ucommon
|
TCP streams are used to represent TCP client connections to a server by TCP protocol servers for accepting client connections. More...
#include <tcp.h>
Public Member Functions | |
void | connect (TCPSocket &server) |
Accept a connection from a TCP Server. | |
void | connect (TCPV6Socket &server) |
void | disconnect (void) |
Disconnect the current session and prepare for a new one. | |
size_t | getBufferSize (void) |
Return the size of the current stream buffering used. | |
int | getSegmentSize (void) |
Get protocol segment size. | |
bool | isPending (Pending pend, timeout_t timeout=ucommon::Timer::inf) |
Get the status of pending stream data. | |
ssize_t | peek (void *buf, size_t len) |
Examine contents of next waiting packet. | |
size_t | printf (char *format,...) |
Print content into a socket. | |
void | setTimeout (timeout_t timer) |
Set the I/O operation timeout for socket I/O operations. | |
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. | |
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 (TCPV6Socket &server, bool throwflag=true, timeout_t timeout=0) | |
TCPStream (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 (IPV6Host &host, tpport_t port, unsigned mss=536, bool throwflag=true, timeout_t timeout=0) | |
TCPStream (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 | ~TCPStream () |
Flush and empty all buffers, and then remove the allocated buffers. | |
Protected Member Functions | |
void | allocate (size_t size) |
Used to allocate the buffer space needed for iostream operations. | |
void | connect (IPV4Host &host, tpport_t port, unsigned mss=536) |
Create a TCP stream by connecting to a TCP socket (on a remote machine). | |
void | connect (IPV6Host &host, tpport_t port, unsigned mss=536) |
void | connect (char *name, unsigned mss=536) |
Connect a TCP stream to a named destination host and port number, using getaddrinfo interface if available. | |
void | endStream (void) |
Used to terminate the buffer space and cleanup the socket connection. | |
int | overflow (int ch) |
This streambuf method is used to write the output buffer through the established tcp connection. | |
std::iostream * | tcp (void) |
Used in derived classes to refer to the current object via it's iostream. | |
int | uflow () |
This streambuf method is used for doing unbuffered reads through the establish tcp socket connection when in interactive mode. | |
int | underflow () |
This streambuf method is used to load the input buffer through the established tcp socket connection. | |
Protected Attributes | |
size_t | bufsize |
Family | family |
char * | gbuf |
char * | pbuf |
timeout_t | timeout |
Friends | |
TCPStream & | crlf (TCPStream &) |
TCPStream & | lfcr (TCPStream &) |
TCP streams are used to represent TCP client connections to a server by TCP protocol servers for accepting client connections.
The TCP stream is a C++ "stream" class, and can accept streaming of data to and from other C++ objects using the << and >> operators.
TCPStream itself can be formed either by connecting to a bound network address of a TCP server, or can be created when "accepting" a network connection from a TCP server.
Create a TCP stream by accepting a connection from a bound TCP socket acting as a server.
This performs an "accept" call.
server | socket listening |
throwflag | flag to throw errors. |
timeout | for all operations. |
ost::TCPStream::TCPStream | ( | 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).
host | address of remote TCP server. |
port | number to connect. |
mss | maximum segment size of streaming buffers. |
throwflag | flag to throw errors. |
timeout | for all operations. |
ost::TCPStream::TCPStream | ( | 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.
name | of remote service. |
family | of protocol. |
mss | maximum segment size of streaming buffers. |
throwflag | flag to throw errors. |
timer | for timeout for all operations. |
void ost::TCPStream::allocate | ( | size_t | size | ) | [protected] |
Used to allocate the buffer space needed for iostream operations.
This function is called by the constructor.
size | of stream buffers from constructor. |
void ost::TCPStream::connect | ( | IPV4Host & | host, |
tpport_t | port, | ||
unsigned | mss = 536 |
||
) | [protected] |
Create a TCP stream by connecting to a TCP socket (on a remote machine).
host | address of remote TCP server. |
port | number to connect. |
mss | maximum segment size of streaming buffers. |
void ost::TCPStream::connect | ( | char * | name, |
unsigned | mss = 536 |
||
) | [protected] |
Connect a TCP stream to a named destination host and port number, using getaddrinfo interface if available.
name | of host and service to connect |
mss | maximum segment size of stream buffer |
void ost::TCPStream::connect | ( | TCPSocket & | server | ) |
Accept a connection from a TCP Server.
server | socket listening |
void ost::TCPStream::endStream | ( | void | ) | [protected] |
Used to terminate the buffer space and cleanup the socket connection.
This fucntion is called by the destructor.
size_t ost::TCPStream::getBufferSize | ( | void | ) | [inline] |
bool ost::TCPStream::isPending | ( | Pending | pend, |
timeout_t | timeout = ucommon::Timer::inf |
||
) |
Get the status of pending stream data.
This can be used to examine if input or output is waiting, or if an error or disconnect has occured on the stream. If a read buffer contains data then input is ready and if write buffer contains data it is first flushed and then checked.
int ost::TCPStream::overflow | ( | int | ch | ) | [protected] |
This streambuf method is used to write the output buffer through the established tcp connection.
ch | char to push through. |
ssize_t ost::TCPStream::peek | ( | void * | buf, |
size_t | len | ||
) | [inline] |
Examine contents of next waiting packet.
buf | pointer to packet buffer for contents. |
len | of packet buffer. |
Reimplemented from ucommon::Socket.
size_t ost::TCPStream::printf | ( | char * | format, |
... | |||
) |
Print content into a socket.
format | string |
Reimplemented from ucommon::Socket.
void ost::TCPStream::setTimeout | ( | timeout_t | timer | ) | [inline] |
int ost::TCPStream::sync | ( | void | ) |
Flushes the stream input and output buffers, writes pending output.
std::iostream* ost::TCPStream::tcp | ( | void | ) | [inline, protected] |
int ost::TCPStream::uflow | ( | ) | [protected] |
This streambuf method is used for doing unbuffered reads through the establish tcp socket connection when in interactive mode.
Also this method will handle proper use of buffers if not in interative mode.
int ost::TCPStream::underflow | ( | ) | [protected] |
This streambuf method is used to load the input buffer through the established tcp socket connection.