UCommon
Public Member Functions | Protected Member Functions
ost::TCPSession Class Reference

The TCP session is used to primarily to represent a client connection that can be managed on a seperate thread. More...

#include <tcp.h>

Inheritance diagram for ost::TCPSession:
Inheritance graph
[legend]
Collaboration diagram for ost::TCPSession:
Collaboration graph
[legend]

Public Member Functions

 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 own thread. More...
 
 TCPSession (const IPV6Host &host, tpport_t port, size_t size=536, int pri=0, size_t stack=0)
 
 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 execute a thread for the accepted connection. More...
 
 TCPSession (TCPV6Socket &server, int pri=0, size_t stack=0)
 
virtual ~TCPSession ()
 Make sure destruction happens through a virtual...
 
- Public Member Functions inherited from ost::TCPStream
void connect (TCPSocket &server)
 Accept a connection from a TCP Server. More...
 
void connect (TCPV6Socket &server)
 
void disconnect (void)
 Disconnect the current session and prepare for a new one.
 
size_t getBufferSize (void) const
 Return the size of the current stream buffering used. More...
 
int getSegmentSize (void)
 Get protocol segment size.
 
bool isPending (Pending pend, timeout_t timeout=ucommon::Timer::inf)
 Get the status of pending stream data. More...
 
ssize_t peek (void *buf, size_t len)
 Examine contents of next waiting packet. More...
 
size_t printf (const char *format,...)
 Print content into a socket. More...
 
void setTimeout (timeout_t timer)
 Set the I/O operation timeout for socket I/O operations. More...
 
int sync (void)
 Flushes the stream input and output buffers, writes pending output. More...
 
 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. More...
 
 TCPStream (TCPV6Socket &server, bool throwflag=true, timeout_t timeout=0)
 
 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). More...
 
 TCPStream (const IPV6Host &host, tpport_t port, unsigned mss=536, bool throwflag=true, timeout_t timeout=0)
 
 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. More...
 
virtual ~TCPStream ()
 Flush and empty all buffers, and then remove the allocated buffers.
 

Protected Member Functions

void initial (void)
 The initial method is used to esablish a connection when delayed completion is used. More...
 
int waitConnection (timeout_t timeout=ucommon::Timer::inf)
 Normally called during the thread Initial() method by default, this will wait for the socket connection to complete when connecting to a remote socket. More...
 
- Protected Member Functions inherited from ost::TCPStream
void allocate (size_t size)
 Used to allocate the buffer space needed for iostream operations. More...
 
void connect (const IPV4Host &host, tpport_t port, unsigned mss=536)
 Create a TCP stream by connecting to a TCP socket (on a remote machine). More...
 
void connect (const IPV6Host &host, tpport_t port, unsigned mss=536)
 
void connect (const char *name, unsigned mss=536)
 Connect a TCP stream to a named destination host and port number, using getaddrinfo interface if available. More...
 
void endStream (void)
 Used to terminate the buffer space and cleanup the socket connection. More...
 
int overflow (int ch)
 This streambuf method is used to write the output buffer through the established tcp connection. More...
 
std::iostream * tcp (void)
 Used in derived classes to refer to the current object via it's iostream. More...
 
int uflow ()
 This streambuf method is used for doing unbuffered reads through the establish tcp socket connection when in interactive mode. More...
 
int underflow ()
 This streambuf method is used to load the input buffer through the established tcp socket connection. More...
 

Additional Inherited Members

- Protected Attributes inherited from ost::TCPStream
size_t bufsize
 
Family family
 
char * gbuf
 
char * pbuf
 
timeout_t timeout
 

Detailed Description

The TCP session is used to primarily to represent a client connection that can be managed on a seperate thread.

The TCP session also supports a non-blocking connection scheme which prevents blocking during the constructor and moving the process of completing a connection into the thread that executes for the session.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m Threaded streamable socket with non-blocking constructor.

Definition at line 564 of file tcp.h.

Constructor & Destructor Documentation

◆ TCPSession() [1/2]

ost::TCPSession::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 own thread.

Parameters
hostinternet address of remote TCP server.
portnumber of remote server.
sizeof streaming buffer.
priexecution priority relative to parent.
stackallocation needed on some platforms.

◆ TCPSession() [2/2]

ost::TCPSession::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 execute a thread for the accepted connection.

Parameters
servertcp socket to accept a connection from.
priexecution priority relative to parent.
stackallocation needed on some platforms.

Member Function Documentation

◆ initial()

void ost::TCPSession::initial ( void  )
protected

The initial method is used to esablish a connection when delayed completion is used.

This assures the constructor terminates without having to wait for a connection request to complete.

◆ waitConnection()

int ost::TCPSession::waitConnection ( timeout_t  timeout = ucommon::Timer::inf)
protected

Normally called during the thread Initial() method by default, this will wait for the socket connection to complete when connecting to a remote socket.

One might wish to use setCompletion() to change the socket back to blocking I/O calls after the connection completes. To implement the session one must create a derived class which implements run().

Returns
0 if successful, -1 if timed out.
Parameters
timeoutto wait for completion in milliseconds.

The documentation for this class was generated from the following file: