Go to the documentation of this file.
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);
151 TCPSocket(
const char *name,
unsigned backlog = 5,
unsigned mss = 536);
162 return Socket::getIPV4Sender(port);
174 return Socket::getIPV4Local(port);
183 return Socket::isPending(Socket::pendingInput, timeout);
221 void setSegmentSize(
unsigned mss);
246 inline int getSegmentSize(
void) {
274 TCPV6Socket(
const char *name,
unsigned backlog = 5,
unsigned mss = 536);
285 return Socket::getIPV6Sender(port);
297 return Socket::getIPV6Local(port);
306 return Socket::isPending(Socket::pendingInput, timeout);
329 class __EXPORT
TCPStream :
protected std::streambuf,
public Socket,
public std::iostream
334 void segmentBuffering(
unsigned mss);
354 TCPStream(Family family = IPV4,
bool throwflag =
true, timeout_t to = 0);
397 int uflow() __OVERRIDE;
406 int overflow(
int ch) __OVERRIDE;
428 void connect(
const char *name,
unsigned mss = 536);
437 std::iostream *
tcp(
void) {
438 return ((std::iostream *)
this);
490 TCPStream(
const char *name, Family family = IPV4,
unsigned mss = 536,
bool throwflag =
false, timeout_t timer = 0);
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);
604 tpport_t port,
size_t size = 536,
int pri = 0,
size_t stack = 0);
607 tpport_t port,
size_t size = 536,
int pri = 0,
size_t stack = 0);
void initial(void)
The initial method is used to esablish a connection when delayed completion is used.
bool isPendingConnection(timeout_t timeout=ucommon::Timer::inf)
Used to wait for pending connection requests.
size_t getBufferSize(void) const
Return the size of the current stream buffering used.
in_port_t tpport_t
Transport Protocol Ports.
TCPV6 sockets are used for stream based connected sessions between two ipv6 sockets.
void connect(const char *name, unsigned mss=536)
Connect a TCP stream to a named destination host and port number, using getaddrinfo interface if avai...
int getSegmentSize(void)
Get protocol segment size.
TCP sockets are used for stream based connected sessions between two sockets.
virtual ~TCPSession()
Make sure destruction happens through a virtual...
int getSegmentSize(void) const
Get the buffer size for servers.
int waitConnection(timeout_t timeout=ucommon::Timer::inf)
Normally called during the thread Initial() method by default, this will wait for the socket connecti...
void disconnect(void)
Disconnect the current session and prepare for a new one.
void reject(void)
Used to reject the next incoming connection request.
virtual bool onAccept(const IPV4Host &ia, tpport_t port)
A method to call in a derived TCPSocket class that is acting as a server when a connection request is...
Network addresses and sockets related classes.
IPV6Host getLocal(tpport_t *port=NULL) const
Used to get local bound address.
Common C++ generic string class.
IPV6Host getRequest(tpport_t *port=NULL) const
Return address and port of next connection request.
bool isPending(Pending pend, timeout_t timeout=ucommon::Timer::inf)
Get the status of pending stream data.
SOCKET getSocket(void) const
Fetch out the socket.
void endStream(void)
Used to terminate the buffer space and cleanup the socket connection.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
int sync(void)
Flushes the stream input and output buffers, writes pending output.
TCPStream(Family family=IPV4, bool throwflag=true, timeout_t to=0)
The constructor required for building other classes or to start an unconnected TCPStream for connect.
SOCKET getSocket(void)
Fetch out the socket.
TCPSocket(const char *name, unsigned backlog=5, unsigned mss=536)
Create a named tcp socket by service and/or interface id.
size_t printf(const char *format,...)
Print content into a socket.
void setTimeout(timeout_t timer)
Set the I/O operation timeout for socket I/O operations.
The TCP session is used to primarily to represent a client connection that can be managed on a sepera...
void allocate(size_t size)
Used to allocate the buffer space needed for iostream operations.
TCPStream(TCPSocket &server, bool throwflag=true, timeout_t timeout=0)
Create a TCP stream by accepting a connection from a bound TCP socket acting as a server.
TCPStream(const char *name, Family family=IPV4, unsigned mss=536, bool throwflag=false, timeout_t timer=0)
Construct a named TCP Socket connected to a remote machine.
std::iostream * tcp(void)
Used in derived classes to refer to the current object via it's iostream.
IPV4Host getRequest(tpport_t *port=NULL) const
Return address and port of next connection request.
TCPV6Socket(const IPV6Address &bind, tpport_t port, unsigned backlog=5, unsigned mss=536)
A TCP "server" is created as a TCP socket that is bound to a hardware address and port number on the ...
TCPSocket(const IPV4Address &bind, tpport_t port, unsigned backlog=5, unsigned mss=536)
A TCP "server" is created as a TCP socket that is bound to a hardware address and port number on the ...
ssize_t peek(void *buf, size_t len)
Examine contents of next waiting packet.
void connect(TCPSocket &server)
Accept a connection from a TCP Server.
The network name and address objects are all derived from a common IPV6Address base class.
TCPStream(const IPV4Host &host, tpport_t port, unsigned mss=536, bool throwflag=true, timeout_t timeout=0)
Create a TCP stream by connecting to a TCP socket (on a remote machine).
IPV4Host getLocal(tpport_t *port=NULL) const
Used to get local bound address.
int underflow()
This streambuf method is used to load the input buffer through the established tcp socket connection.
bool isPendingConnection(timeout_t timeout=ucommon::Timer::inf)
Used to wait for pending connection requests.
virtual ~TCPSocket()
Use base socket handler for ending this socket.
TCPV6Socket(const char *name, unsigned backlog=5, unsigned mss=536)
Create a TCP server for a named host interface and service port.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
TCPSession(const IPV4Host &host, tpport_t port, size_t size=536, int pri=0, size_t stack=0)
Create a TCP socket that will be connected to a remote TCP server and that will execute under it's ow...
virtual ~TCPStream()
Flush and empty all buffers, and then remove the allocated buffers.
The network name and address objects are all derived from a common IPV4Address base class.
TCPSession(TCPSocket &server, int pri=0, size_t stack=0)
Create a TCP socket from a bound TCP server by accepting a pending connection from that server and ex...
TCP streams are used to represent TCP client connections to a server by TCP protocol servers for acce...
virtual bool onAccept(const IPV6Host &ia, tpport_t port)
A method to call in a derived TCPSocket class that is acting as a server when a connection request is...
virtual ~TCPV6Socket()
Use base socket handler for ending this socket.
void reject(void)
Used to reject the next incoming connection request.