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);
virtual ~TCPV6Socket()
Use base socket handler for ending this socket.
int getSegmentSize(void) const
Get the buffer size for servers.
virtual ~TCPSocket()
Use base socket handler for ending this socket.
The network name and address objects are all derived from a common IPV6Address base class.
virtual ~TCPStream()
Flush and empty all buffers, and then remove the allocated buffers.
TCPV6 sockets are used for stream based connected sessions between two ipv6 sockets.
Network addresses and sockets related classes.
ssize_t peek(void *buf, size_t len)
Examine contents of next waiting packet.
int waitConnection(timeout_t timeout=ucommon::Timer::inf)
Normally called during the thread Initial() method by default, this will wait for the socket connecti...
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...
TCPSocket(const char *name, unsigned backlog=5, unsigned mss=536)
Create a named tcp socket by service and/or interface id.
void endStream(void)
Used to terminate the buffer space and cleanup the socket connection.
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).
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.
void setTimeout(timeout_t timer)
Set the I/O operation timeout for socket I/O operations.
The network name and address objects are all derived from a common IPV4Address base class.
void allocate(size_t size)
Used to allocate the buffer space needed for iostream operations.
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.
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...
Common C++ generic string class.
IPV6Host 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 ...
The TCP session is used to primarily to represent a client connection that can be managed on a sepera...
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 ...
TCP sockets are used for stream based connected sessions between two sockets.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
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.
IPV6Host getLocal(tpport_t *port=NULL) const
Used to get local bound address.
void connect(TCPSocket &server)
Accept a connection from a TCP Server.
int getSegmentSize(void)
Get protocol segment size.
TCP streams are used to represent TCP client connections to a server by TCP protocol servers for acce...
in_port_t tpport_t
Transport Protocol Ports.
void disconnect(void)
Disconnect the current session and prepare for a new one.
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...
SOCKET getSocket(void) const
Fetch out the socket.
void reject(void)
Used to reject the next incoming connection request.
TCPV6Socket(const char *name, unsigned backlog=5, unsigned mss=536)
Create a TCP server for a named host interface and service port.
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...
void initial(void)
The initial method is used to esablish a connection when delayed completion is used.
virtual ~TCPSession()
Make sure destruction happens through a virtual...
bool isPendingConnection(timeout_t timeout=ucommon::Timer::inf)
Used to wait for pending connection requests.
SOCKET getSocket(void)
Fetch out the socket.
bool isPendingConnection(timeout_t timeout=ucommon::Timer::inf)
Used to wait for pending connection requests.
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...
void reject(void)
Used to reject the next incoming connection request.
size_t printf(const char *format,...)
Print content into a socket.
size_t getBufferSize(void) const
Return the size of the current stream buffering used.
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.
std::iostream * tcp(void)
Used in derived classes to refer to the current object via it's iostream.
int sync(void)
Flushes the stream input and output buffers, writes pending output.
bool isPending(Pending pend, timeout_t timeout=ucommon::Timer::inf)
Get the status of pending stream data.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
IPV4Host getRequest(tpport_t *port=NULL) const
Return address and port of next connection request.