25 #include <cppmyth_config.h> 31 #define SOCKET_HOSTNAME_MAXSIZE 256 32 #define SOCKET_RCVBUF_MINSIZE 16384 33 #define SOCKET_READ_TIMEOUT_SEC 10 34 #define SOCKET_READ_TIMEOUT_USEC 0 35 #define SOCKET_READ_ATTEMPT 3 36 #define SOCKET_BUFFER_SIZE 1472 37 #define SOCKET_CONNECTION_REQUESTS 5 54 m_timeout.tv_sec = SOCKET_READ_TIMEOUT_SEC;
55 m_timeout.tv_usec = SOCKET_READ_TIMEOUT_USEC;
58 virtual bool SendData(
const char* buf,
size_t size) = 0;
59 virtual size_t ReceiveData(
void* buf,
size_t n) = 0;
60 void SetTimeout(timeval timeout) { m_timeout = timeout; }
63 struct timeval m_timeout;
92 virtual bool Connect(
const char *server,
unsigned port,
int rcvbuf);
100 virtual bool SendData(
const char* buf,
size_t size);
108 virtual size_t ReceiveData(
void* buf,
size_t n);
113 virtual void Disconnect();
118 virtual bool IsValid()
const;
126 int Listen(timeval *timeout);
136 std::string GetHostAddrInfo();
141 static const char* GetMyHostName();
144 net_socket_t m_socket;
175 bool Create(SOCKET_AF_t af);
180 bool IsValid()
const;
187 bool Bind(
unsigned port);
194 bool ListenConnection(
int queueSize = SOCKET_CONNECTION_REQUESTS);
201 bool AcceptConnection(
TcpSocket& socket);
215 net_socket_t m_socket;
217 unsigned m_requestQueueSize;
242 bool SendData(
const char* buf,
size_t size);
250 size_t ReceiveData(
void* buf,
size_t n);
255 bool IsValid()
const;
264 bool Open(SOCKET_AF_t af,
const char* target,
unsigned port);
272 bool Open(SOCKET_AF_t af,
bool broadcast =
false);
280 bool SetAddress(
const char* target,
unsigned port);
288 bool SetMulticastTTL(
int multicastTTL);
293 std::string GetRemoteAddrInfo()
const;
303 net_socket_t m_socket;
331 bool Create(SOCKET_AF_t af);
336 bool IsValid()
const;
343 bool Bind(
unsigned port);
351 bool SetMulticastTTL(
int multicastTTL);
359 bool SetMulticastMembership(
const char *group,
bool join);
365 size_t AwaitIncoming(timeval timeout);
366 size_t AwaitIncoming();
372 std::string GetRemoteAddrInfo()
const;
380 size_t ReadData(
void* buf,
size_t n);
390 net_socket_t m_socket;
396 struct timeval m_timeout;
400 UdpServerSocket& operator=(
const UdpServerSocket&);
408 , m_bound(boundSocket) { }
410 bool SendData(
const char* buf,
size_t size) { (void)buf; (void)size;
return false; };
412 size_t ReceiveData(
void* buf,
size_t n)
415 if (m_bound.IsValid())
417 if ((r = m_bound.ReadData(buf, n)) > 0)
419 if (m_bound.AwaitIncoming(m_timeout) > 0)
420 return m_bound.ReadData(buf, n);
net_socket_t GetHandle() const
void SetReadAttempt(int n)
net_socket_t GetHandle() const
net_socket_t GetHandle() const
net_socket_t GetHandle() const