44 #ifndef COMMONCPP_TCP_H_
45 #define COMMONCPP_TCP_H_
49 #ifndef COMMONCPP_CONFIG_H_
50 #include <commoncpp/config.h>
53 #ifndef COMMONCPP_STRING_H_
57 #ifndef COMMONCPP_ADDRESS_H_
61 #ifndef COMMONCPP_SOCKET_H_
95 void setSegmentSize(
unsigned mss);
109 virtual bool onAccept(
const IPV4Host &ia, tpport_t port);
114 inline SOCKET getSocket(
void)
120 inline int getSegmentSize(
void)
147 TCPSocket(
const char *name,
unsigned backlog = 5,
unsigned mss = 536);
157 inline IPV4Host getRequest(tpport_t *port = NULL)
const
158 {
return Socket::getIPV4Sender(port);}
168 inline IPV4Host getLocal(tpport_t *port = NULL)
const
169 {
return Socket::getIPV4Local(port);}
176 inline bool isPendingConnection(
timeout_t timeout = TIMEOUT_INF)
177 {
return Socket::isPending(Socket::pendingInput, timeout);}
214 void setSegmentSize(
unsigned mss);
228 virtual bool onAccept(
const IPV6Host &ia, tpport_t port);
233 inline SOCKET getSocket(
void)
236 inline int getSegmentSize(
void)
251 TCPV6Socket(
const IPV6Address &bind, tpport_t port,
unsigned backlog = 5,
unsigned mss = 536);
263 TCPV6Socket(
const char *name,
unsigned backlog = 5,
unsigned mss = 536);
273 inline IPV6Host getRequest(tpport_t *port = NULL)
const
274 {
return Socket::getIPV6Sender(port);}
284 inline IPV6Host getLocal(tpport_t *port = NULL)
const
285 {
return Socket::getIPV6Local(port);}
292 inline bool isPendingConnection(
timeout_t timeout = TIMEOUT_INF)
293 {
return Socket::isPending(Socket::pendingInput, timeout);}
315 class __EXPORT
TCPStream :
protected std::streambuf,
public Socket,
public std::iostream
320 void segmentBuffering(
unsigned mss);
345 void disconnect(
void);
350 int getSegmentSize(
void);
359 void allocate(
size_t size);
365 void endStream(
void);
392 int overflow(
int ch);
402 void connect(
const IPV4Host &host, tpport_t port,
unsigned mss = 536);
404 void connect(
const IPV6Host &host, tpport_t port,
unsigned mss = 536);
414 void connect(
const char *name,
unsigned mss = 536);
423 std::iostream *tcp(
void)
424 {
return ((std::iostream *)
this);};
475 TCPStream(
const char *name, Family family = IPV4,
unsigned mss = 536,
bool throwflag =
false,
timeout_t timer = 0);
506 size_t printf(
const char *format, ...);
515 bool isPending(Pending pend,
timeout_t timeout = TIMEOUT_INF);
524 inline ssize_t peek(
void *buf,
size_t len)
525 {return ::recv(so, (
char *)buf, len, MSG_PEEK);};
532 inline size_t getBufferSize(
void)
const
563 int waitConnection(
timeout_t timeout = TIMEOUT_INF);
585 tpport_t port,
size_t size = 536,
int pri = 0,
size_t stack = 0);
588 tpport_t port,
size_t size = 536,
int pri = 0,
size_t stack = 0);