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_ 91 class __EXPORT TCPSocket :
protected Socket
95 void setSegmentSize(
unsigned mss);
97 __DELETE_COPY(TCPSocket);
111 virtual bool onAccept(
const IPV4Host &ia, tpport_t port);
116 inline SOCKET getSocket(
void)
const {
123 inline int getSegmentSize(
void)
const {
139 TCPSocket(
const IPV4Address &bind, tpport_t port,
unsigned backlog = 5,
unsigned mss = 536);
151 TCPSocket(
const char *name,
unsigned backlog = 5,
unsigned mss = 536);
161 inline IPV4Host getRequest(tpport_t *port = NULL)
const {
162 return Socket::getIPV4Sender(port);
173 inline IPV4Host getLocal(tpport_t *port = NULL)
const {
174 return Socket::getIPV4Local(port);
182 inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF) {
183 return Socket::isPending(Socket::pendingInput, timeout);
189 virtual ~TCPSocket();
217 class __EXPORT TCPV6Socket :
protected Socket
221 void setSegmentSize(
unsigned mss);
223 __DELETE_COPY(TCPV6Socket);
237 virtual bool onAccept(
const IPV6Host &ia, tpport_t port);
242 inline SOCKET getSocket(
void) {
246 inline int getSegmentSize(
void) {
262 TCPV6Socket(
const IPV6Address &bind, tpport_t port,
unsigned backlog = 5,
unsigned mss = 536);
274 TCPV6Socket(
const char *name,
unsigned backlog = 5,
unsigned mss = 536);
284 inline IPV6Host getRequest(tpport_t *port = NULL)
const {
285 return Socket::getIPV6Sender(port);
296 inline IPV6Host getLocal(tpport_t *port = NULL)
const {
297 return Socket::getIPV6Local(port);
305 inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF) {
306 return Socket::isPending(Socket::pendingInput, timeout);
312 virtual ~TCPV6Socket();
329 class __EXPORT TCPStream :
protected std::streambuf,
public Socket,
public std::iostream
334 void segmentBuffering(
unsigned mss);
336 friend TCPStream& crlf(TCPStream&);
337 friend TCPStream& lfcr(TCPStream&);
340 TCPStream(
const TCPStream &source);
354 TCPStream(Family family = IPV4,
bool throwflag =
true, timeout_t to = 0);
359 void disconnect(
void);
364 int getSegmentSize(
void);
373 void allocate(
size_t size);
379 void endStream(
void);
387 int underflow() __OVERRIDE;
397 int uflow() __OVERRIDE;
406 int overflow(
int ch) __OVERRIDE;
416 void connect(const IPV4Host &host, tpport_t port,
unsigned mss = 536);
418 void connect(
const IPV6Host &host, tpport_t port,
unsigned mss = 536);
428 void connect(
const char *name,
unsigned mss = 536);
437 std::iostream *tcp(
void) {
438 return ((std::iostream *)
this);
451 TCPStream(TCPSocket &server,
bool throwflag =
true, timeout_t timeout = 0);
453 TCPStream(TCPV6Socket &server,
bool throwflag =
true, timeout_t timeout = 0);
461 void connect(TCPSocket &server);
463 void connect(TCPV6Socket &server);
476 TCPStream(
const IPV4Host &host, tpport_t port,
unsigned mss = 536,
bool throwflag =
true, timeout_t timeout = 0);
478 TCPStream(
const IPV6Host &host, tpport_t port,
unsigned mss = 536,
bool throwflag =
true, timeout_t timeout = 0);
490 TCPStream(
const char *name, Family family = IPV4,
unsigned mss = 536,
bool throwflag =
false, timeout_t timer = 0);
497 inline void setTimeout(timeout_t timer) {
506 virtual ~TCPStream();
522 size_t printf(
const char *format, ...);
531 bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF) __OVERRIDE;
540 inline ssize_t peek(
void *buf,
size_t len) {
541 return ::recv(so, (
char *)buf, (socksize_t)len, MSG_PEEK);
549 inline size_t getBufferSize(
void)
const {
564 class __EXPORT TCPSession :
public Thread,
public TCPStream
567 TCPSession(
const TCPSession &rhs);
582 int waitConnection(timeout_t timeout = TIMEOUT_INF);
590 void initial(
void) __OVERRIDE;
603 TCPSession(
const IPV4Host &host,
604 tpport_t port,
size_t size = 536,
int pri = 0,
size_t stack = 0);
606 TCPSession(
const IPV6Host &host,
607 tpport_t port,
size_t size = 536,
int pri = 0,
size_t stack = 0);
619 TCPSession(TCPSocket &server,
int pri = 0,
size_t stack = 0);
621 TCPSession(TCPV6Socket &server,
int pri = 0,
size_t stack = 0);
627 virtual ~TCPSession();
Network addresses and sockets related classes.
Common C++ generic string class.