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