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::Thread
void detach (void)
 
void exit (void)
 
virtual void final (void)
 
void finalize (void)
 
pthread_t getId (void)
 Get the thread id.
 
virtual void initial (void)
 
bool isRunning (void)
 
bool isThread (void)
 
void join (void)
 
void map (void)
 
virtual void notify (Thread *thread)
 
virtual void run (void)=0
 
void start (void)
 
void sync (void)
 
void terminate (void)
 
 Thread (int pri=0, size_t stack=0)
 
- 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.
 
- Public Member Functions inherited from ost::Socket
struct in_addr getaddress (const IPV4Address &ia)
 
struct in6_addr getaddress (const IPV6Address &ia)
 
Error getErrorNumber (void) const
 Often used by a "catch" to fetch the last error of a thrown socket. More...
 
const char * getErrorString (void) const
 Often used by a "catch" to fetch the user set error string of a thrown socket, but only if EXTENDED error codes are used. More...
 
IPV4Host getIPV4Local (tpport_t *port=((void *) 0)) const
 Get the local address and port number this socket is currently bound to. More...
 
IPV4Host getIPV4Peer (tpport_t *port=((void *) 0)) const
 Get the host address and port of the socket this socket is connected to. More...
 
virtual IPV4Host getIPV4Sender (tpport_t *port=((void *) 0)) const
 May be used to examine the origin of data waiting in the socket receive queue. More...
 
IPV6Host getIPV6Local (tpport_t *port=((void *) 0)) const
 
IPV6Host getIPV6Peer (tpport_t *port=((void *) 0)) const
 
virtual IPV6Host getIPV6Sender (tpport_t *port=((void *) 0)) const
 
IPV4Host getLocal (tpport_t *port=((void *) 0)) const
 
IPV4Host getPeer (tpport_t *port=((void *) 0)) const
 
IPV4Host getSender (tpport_t *port=((void *) 0)) const
 
long getSystemError (void) const
 
const char * getSystemErrorString (void) const
 
bool isActive (void) const
 Test to see if the socket is at least operating or if it is mearly initialized. More...
 
bool isBroadcast (void) const
 Return if broadcast has been enabled for the specified socket. More...
 
bool isConnected (void) const
 Can test to see if this socket is "connected", and hence whether a "catch" can safely call getPeer(). More...
 
virtual bool isPending (Pending pend, timeout_t timeout=ucommon::Timer::inf)
 Get the status of pending operations. More...
 
bool isRouted (void) const
 Return if socket routing is enabled. More...
 
 operator bool () const
 
bool operator! () const
 Operator based testing to see if a socket is currently active.
 
Socket & operator= (const Socket &from)
 Sockets may also be duplicated by the assignment operator.
 
void setCompletion (bool immediate)
 Used to specify blocking mode for the socket. More...
 
Error setKeepAlive (bool enable)
 Set the keep-alive status of this socket and if keep-alive messages will be sent. More...
 
Error setLinger (bool linger)
 Enable lingering sockets on close. More...
 
Error setTypeOfService (Tos service)
 Set packet scheduling on platforms which support ip quality of service conventions. More...
 

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 ucommon::JoinableThread
bool is_active (void)
 Check if running.
 
void join (void)
 Join thread with parent. More...
 
 JoinableThread (size_t size=0)
 Create a joinable thread with a known context stack size. More...
 
virtual void run (void)=0
 Abstract interface for thread context run method.
 
virtual ~JoinableThread ()
 Delete child thread. More...
 
void background (void)
 Start execution of child context as background thread. More...
 
void start (int priority=0)
 Start execution of child context. More...
 
- Protected Member Functions inherited from ucommon::Thread
void map (void)
 Map thread for get method. More...
 
 Thread (size_t stack=0)
 Create a thread object that will have a preset stack size. More...
 
virtual void exit (void)
 Exit the thread context. More...
 
bool isRunning (void)
 
 operator bool ()
 
bool operator! ()
 
void setPriority (void)
 Set thread priority without disrupting scheduling if possible. More...
 
virtual ~Thread ()
 Destroy thread object, thread-specific data, and execution context.
 
- 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...
 
- Protected Member Functions inherited from ost::Socket
Error bufferSize (unsigned size)
 Set the total protocol stack network kernel buffer size for both send and receive together. More...
 
Error connectError (void)
 Used as a common handler for connection failure processing. More...
 
Error drop (const IPV4Multicast &ia)
 Drop membership from a multicast group. More...
 
Error drop (const IPV6Multicast &ia)
 
void endSocket (void)
 Used as the default destructor for ending a socket. More...
 
Error error (Error error, const char *err=((void *) 0), long systemError=0) const
 This service is used to throw all socket errors which usually occur during the socket constructor. More...
 
void error (const char *err) const
 This service is used to throw application defined socket errors where the application specific error code is a string. More...
 
Error join (const IPV4Multicast &ia)
 Join a multicast group. More...
 
Error join (const IPV6Multicast &ia)
 
virtual ssize_t readData (void *buf, size_t len, char separator=0, timeout_t t=0)
 Read in a block of len bytes with specific separator. More...
 
ssize_t readLine (char *buf, size_t len, timeout_t timeout=0)
 Process a logical input line from a socket descriptor directly. More...
 
Error receiveBuffer (unsigned size)
 Set the protocol stack network kernel receive buffer size associated with the socket. More...
 
Error receiveLimit (int limit=1)
 Set thr receive limit.
 
Error receiveTimeout (timeout_t timer)
 Receive timeout for receiving raw network data. More...
 
Error sendBuffer (unsigned size)
 Set the protocol stack network kernel send buffer size associated with the socket. More...
 
Error sendLimit (int limit=2048)
 Set the send limit.
 
Error sendTimeout (timeout_t timer)
 Set the send timeout for sending raw network data. More...
 
Error setBroadcast (bool enable)
 Set the subnet broadcast flag for the socket. More...
 
void setError (bool enable)
 This service is used to turn the error handler on or off for "throwing" exceptions by manipulating the thrown flag. More...
 
Error setLoopbackByFamily (bool enable, Family family=IPV4)
 Set the multicast loopback flag for the socket. More...
 
Error setMulticastByFamily (bool enable, Family family=IPV4)
 Setting multicast binds the multicast interface used for the socket to the interface the socket itself has been implicitly bound to. More...
 
Error setNoDelay (bool enable)
 Enable/disable delaying packets (Nagle algorithm) More...
 
Error setRouting (bool enable)
 Set the socket routing to indicate if outgoing messages should bypass normal routing (set false). More...
 
Error setTimeToLiveByFamily (unsigned char ttl, Family fam=IPV4)
 Set the multicast time to live for a multicast socket. More...
 
 Socket (int domain, int type, int protocol=0)
 An unconnected socket may be created directly on the local machine. More...
 
 Socket (socket_t fd)
 A socket object may be created from a file descriptor when that descriptor was created either through a socket() or accept() call. More...
 
 Socket ()
 Create an inactive socket object for base constructors.
 
 Socket (const Socket &source)
 A socket can also be constructed from an already existing Socket object. More...
 
virtual ssize_t writeData (const void *buf, size_t len, timeout_t t=0)
 Write a block of len bytes to socket. More...
 
struct in_addr getaddress (const IPV4Address &ia)
 
struct in6_addr getaddress (const IPV6Address &ia)
 
Error getErrorNumber (void) const
 Often used by a "catch" to fetch the last error of a thrown socket. More...
 
const char * getErrorString (void) const
 Often used by a "catch" to fetch the user set error string of a thrown socket, but only if EXTENDED error codes are used. More...
 
IPV4Host getIPV4Local (tpport_t *port=((void *) 0)) const
 Get the local address and port number this socket is currently bound to. More...
 
IPV4Host getIPV4Peer (tpport_t *port=((void *) 0)) const
 Get the host address and port of the socket this socket is connected to. More...
 
virtual IPV4Host getIPV4Sender (tpport_t *port=((void *) 0)) const
 May be used to examine the origin of data waiting in the socket receive queue. More...
 
IPV6Host getIPV6Local (tpport_t *port=((void *) 0)) const
 
IPV6Host getIPV6Peer (tpport_t *port=((void *) 0)) const
 
virtual IPV6Host getIPV6Sender (tpport_t *port=((void *) 0)) const
 
IPV4Host getLocal (tpport_t *port=((void *) 0)) const
 
IPV4Host getPeer (tpport_t *port=((void *) 0)) const
 
IPV4Host getSender (tpport_t *port=((void *) 0)) const
 
long getSystemError (void) const
 
const char * getSystemErrorString (void) const
 
bool isActive (void) const
 Test to see if the socket is at least operating or if it is mearly initialized. More...
 
bool isBroadcast (void) const
 Return if broadcast has been enabled for the specified socket. More...
 
bool isConnected (void) const
 Can test to see if this socket is "connected", and hence whether a "catch" can safely call getPeer(). More...
 
virtual bool isPending (Pending pend, timeout_t timeout=ucommon::Timer::inf)
 Get the status of pending operations. More...
 
bool isRouted (void) const
 Return if socket routing is enabled. More...
 
 operator bool () const
 
bool operator! () const
 Operator based testing to see if a socket is currently active.
 
Socket & operator= (const Socket &from)
 Sockets may also be duplicated by the assignment operator.
 
void setCompletion (bool immediate)
 Used to specify blocking mode for the socket. More...
 
Error setKeepAlive (bool enable)
 Set the keep-alive status of this socket and if keep-alive messages will be sent. More...
 
Error setLinger (bool linger)
 Enable lingering sockets on close. More...
 
Error setTypeOfService (Tos service)
 Set packet scheduling on platforms which support ip quality of service conventions. More...
 
- Protected Member Functions inherited from ucommon::Socket
int blocking (bool enable)
 Set socket blocking I/O mode. More...
 
int broadcast (bool enable)
 Set socket for unicast mode broadcasts. More...
 
void cancel (void)
 Cancel pending i/o by shutting down the socket.
 
bool ccid (uint8_t id)
 Set ccid of dccp socket. More...
 
bool connected (void) const
 Test if socket is connected. More...
 
int connectto (struct addrinfo *list)
 Connect our socket to a remote host from an address list. More...
 
int disconnect (void)
 Disconnect a connected socket. More...
 
int drop (const struct addrinfo *list)
 Drop socket from multicast group. More...
 
int err (void) const
 Get error code.
 
int getError (void)
 Get socket error code. More...
 
bool is_pending (unsigned value) const
 See the number of bytes in the receive queue. More...
 
int join (const struct addrinfo *list)
 Join socket to multicast group. More...
 
int keepalive (bool enable)
 Set socket for keepalive packets. More...
 
int loopback (bool enable)
 Set loopback to read multicast packets we broadcast. More...
 
int multicast (unsigned ttl=1)
 Set multicast mode and multicast broadcast range. More...
 
int nodelay (void) const
 Set nodelay option for tcp socket. More...
 
 operator bool ()
 Test if socket is valid. More...
 
 operator socket_t () const
 Get the socket descriptor by casting. More...
 
bool operator! () const
 Test if socket is invalid. More...
 
socket_t operator* () const
 Get the socket descriptor by pointer reference. More...
 
Socketoperator= (socket_t socket)
 Assign socket from a socket descriptor. More...
 
size_t peek (void *data, size_t number) const
 Peek at data waiting in the socket receive buffer. More...
 
unsigned pending (void) const
 Get the number of bytes of data in the socket receive buffer. More...
 
size_t printf (const char *format,...)
 Print formatted string to socket. More...
 
int priority (int scheduling)
 Set packet priority, 0 to 6 unless privileged. More...
 
size_t readfrom (void *data, size_t number, struct sockaddr_storage *address=((void *) 0))
 Read data from the socket receive buffer. More...
 
size_t readline (char *data, size_t size)
 Read a newline of text data from the socket and save in NULL terminated string. More...
 
size_t readline (String &buffer)
 Read a string of input from the socket and strip trailing newline. More...
 
int recvsize (unsigned size)
 Set the size of the socket receive buffer. More...
 
void release (void)
 Shutdown and close the socket.
 
unsigned segsize (unsigned size)
 Set segment size and get mtu of a socket. More...
 
int sendsize (unsigned size)
 Set the size of the socket send buffer. More...
 
int sendwait (unsigned size)
 Set the size to wait before sending. More...
 
void shutdown (void)
 Shutdown the socket communication channel.
 
 Socket ()
 Create a socket object for use.
 
 Socket (const Socket &existing)
 Create socket as duped handle of existing socket. More...
 
 Socket (socket_t socket)
 Create socket from existing socket descriptor. More...
 
 Socket (struct addrinfo *address)
 Create and connect a socket to an address from an address list. More...
 
 Socket (int family, int type, int protocol=0)
 Create an unbound socket of a specific type. More...
 
 Socket (const char *address, const char *port, int family=0, int type=0, int protocol=0)
 Create a bound socket. More...
 
int tos (int type)
 Set the type of service field of outgoing packets. More...
 
int ttl (unsigned char time)
 Set the time to live before packets expire. More...
 
int type (void)
 Get the type of a socket. More...
 
bool wait (timeout_t timeout=0) const
 Test for pending input data. More...
 
int wait (timeout_t timeout=Timer::inf)
 Socket i/o timer setting. More...
 
bool waitSending (timeout_t timeout=0) const
 Test for output data sent. More...
 
size_t writes (const char *string)
 Write a null terminated string to the socket. More...
 
size_t writeto (const void *data, size_t number, const struct sockaddr *address=((void *) 0))
 Write data to the socket send buffer. More...
 
virtual ~Socket ()
 Shutdown, close, and destroy socket.
 

Additional Inherited Members

- Public Types inherited from ost::Thread
enum  Throw { throwNothing, throwObject, throwException }
 How to raise error.
 
typedef enum ost::Thread::Throw Throw
 How to raise error.
 
- Public Types inherited from ost::Socket
typedef enum Error Error
 
enum  Error {
  errSuccess = 0, errCreateFailed, errCopyFailed, errInput,
  errInputInterrupt, errResourceFailure, errOutput, errOutputInterrupt,
  errNotConnected, errConnectRefused, errConnectRejected, errConnectTimeout,
  errConnectFailed, errConnectInvalid, errConnectBusy, errConnectNoRoute,
  errBindingFailed, errBroadcastDenied, errRoutingDenied, errKeepaliveDenied,
  errServiceDenied, errServiceUnavailable, errMulticastDisabled, errTimeout,
  errNoDelay, errExtended, errLookupFail, errSearchErr,
  errInvalidValue
}
 
typedef enum Family Family
 
enum  Family { IPV6 = 1, IPV4 = 2 }
 
typedef enum Pending Pending
 
enum  Pending { pendingInput, pendingOutput, pendingError }
 
typedef enum State State
 
enum  State {
  INITIAL, AVAILABLE, BOUND, CONNECTED,
  CONNECTING, STREAM
}
 
typedef enum Tos Tos
 
enum  Tos {
  tosLowDelay = 0, tosThroughput, tosReliability, tosMinCost,
  tosInvalid
}
 
- Static Public Member Functions inherited from ost::Thread
static Thread * get (void)
 
static Throw getException (void)
 Get exception mode of the current thread. More...
 
static void setException (Throw mode)
 Set exception mode of the current thread. More...
 
static void sleep (timeout_t msec=ucommon::Timer::inf)
 
static void yield (void)
 
- Static Public Member Functions inherited from ost::Socket
static bool check (Family fam)
 See if a specific protocol family is available in the current runtime environment. More...
 
- Protected Types inherited from ucommon::Thread
enum  
 
- Protected Types inherited from ost::Socket
typedef enum Error Error
 
enum  Error {
  errSuccess = 0, errCreateFailed, errCopyFailed, errInput,
  errInputInterrupt, errResourceFailure, errOutput, errOutputInterrupt,
  errNotConnected, errConnectRefused, errConnectRejected, errConnectTimeout,
  errConnectFailed, errConnectInvalid, errConnectBusy, errConnectNoRoute,
  errBindingFailed, errBroadcastDenied, errRoutingDenied, errKeepaliveDenied,
  errServiceDenied, errServiceUnavailable, errMulticastDisabled, errTimeout,
  errNoDelay, errExtended, errLookupFail, errSearchErr,
  errInvalidValue
}
 
typedef enum Family Family
 
enum  Family { IPV6 = 1, IPV4 = 2 }
 
typedef enum Pending Pending
 
enum  Pending { pendingInput, pendingOutput, pendingError }
 
typedef enum State State
 
enum  State {
  INITIAL, AVAILABLE, BOUND, CONNECTED,
  CONNECTING, STREAM
}
 
typedef enum Tos Tos
 
enum  Tos {
  tosLowDelay = 0, tosThroughput, tosReliability, tosMinCost,
  tosInvalid
}
 
- Static Protected Member Functions inherited from ucommon::Thread
static void concurrency (int level)
 Set concurrency level of process. More...
 
static bool equal (pthread_t thread1, pthread_t thread2)
 Determine if two thread identifiers refer to the same thread. More...
 
static Threadget (void)
 Get mapped thread object. More...
 
static void init (void)
 Used to initialize threading library. More...
 
static void policy (int polid)
 Used to specify scheduling policy for threads above priority "0". More...
 
static pthread_t self (void)
 Get current thread id. More...
 
static void sleep (timeout_t timeout)
 Sleep current thread for a specified time period. More...
 
static void yield (void)
 Yield execution context of the current thread. More...
 
- Static Protected Member Functions inherited from ost::Socket
static socket_t dupSocket (socket_t s, Socket::State state)
 
static bool check (Family fam)
 See if a specific protocol family is available in the current runtime environment. More...
 
- Static Protected Member Functions inherited from ucommon::Socket
static socket_t acceptfrom (socket_t socket, struct sockaddr_storage *address=((void *) 0))
 Accept a socket connection from a remote host. More...
 
static int bindto (socket_t socket, const char *address, const char *service, int protocol=0)
 Bind the socket descriptor to a known interface and service port. More...
 
static int bindto (socket_t socket, const struct sockaddr *address)
 Bind the socket descriptor to a known interface. More...
 
static int blocking (socket_t socket, bool enable)
 Set socket blocking I/O mode of socket descriptor. More...
 
static int broadcast (socket_t socket, bool enable)
 Set socket for unicast mode broadcasts on socket descriptor. More...
 
static void cancel (socket_t socket)
 Cancel pending i/o by shutting down the socket. More...
 
static bool ccid (socket_t socket, uint8_t id)
 Set congestion control id. More...
 
static int connectto (socket_t socket, struct addrinfo *list)
 Connect socket descriptor to a remote host from an address list. More...
 
static unsigned copy (struct sockaddr *target, const struct sockaddr *origin)
 Copy a socket address. More...
 
static socket_t create (int family, int type, int protocol)
 Create a socket object unbound. More...
 
static socket_t create (const struct addrinfo *address, int type, int protocol)
 Create a connected socket. More...
 
static socket_t create (const char *iface, const char *service, int family=0, int type=0, int protocol=0)
 Create a bound socket for a service. More...
 
static socket_t create (const Socket::address &address)
 Create a connected socket for a service. More...
 
static int disconnect (socket_t socket)
 Disconnect a connected socket descriptor. More...
 
static int drop (socket_t socket, const struct addrinfo *list)
 Drop socket descriptor from multicast group. More...
 
static bool eq_from (const struct sockaddr_storage *address1, const struct sockaddr_storage *address2)
 Compare socket addresses. More...
 
static bool eq_host (const struct sockaddr *address1, const struct sockaddr *address2)
 Compare socket host addresses. More...
 
static bool eq_inet (const struct sockaddr_internet *address1, const struct sockaddr_internet *address2)
 Compare socket addresses. More...
 
static bool eq_subnet (const struct sockaddr *address1, const struct sockaddr *address2)
 See if both addresses are in the same subnet. More...
 
static bool equal (const struct sockaddr *address1, const struct sockaddr *address2)
 Compare socket addresses. More...
 
static int error (socket_t socket)
 Get socket error code of socket descriptor. More...
 
static int error (void)
 Return error code of last socket operation,. More...
 
static int family (socket_t socket)
 Get the address family of the socket descriptor. More...
 
static int family (const struct sockaddr_storage &address)
 Get the address family of a socket address object. More...
 
static int family (const struct sockaddr_internet &address)
 Get the address family of an internet socket address object. More...
 
static struct addrinfohinting (socket_t socket, struct addrinfo *hint)
 Create an address info lookup hint based on the family and type properties of a socket descriptor. More...
 
static char * hostname (const struct sockaddr *address, char *buffer, size_t size)
 Lookup and return the host name associated with a socket address. More...
 
static void init (void)
 Initialize socket subsystem.
 
static void init (const char *program)
 Initialize with program name. More...
 
static bool is_null (const char *string)
 Simple function to validate that a given IP address string is a "zero" address. More...
 
static bool is_numeric (const char *string)
 Simple function to validate that a given IP address string is a numeric address. More...
 
static int join (socket_t socket, const struct addrinfo *list)
 Join socket descriptor to multicast group. More...
 
static int keepalive (socket_t socket, bool enable)
 Set socket for keepalive packets for socket descriptor. More...
 
static unsigned keyhost (const struct sockaddr *address, unsigned size)
 Convert a socket host address into a hash map index. More...
 
static unsigned keyindex (const struct sockaddr *address, unsigned size)
 Convert a socket address and service into a hash map index. More...
 
static socklen_t len (const struct sockaddr *address)
 Get the size of a socket address. More...
 
static int listento (socket_t socket, const struct sockaddr *address, int backlog=5)
 Bind the socket descriptor to a known interface listen on service port. More...
 
static int local (socket_t socket, struct sockaddr_storage *address)
 Get local address to which the socket is bound. More...
 
static int loopback (socket_t socket, bool enable)
 Set loopback to read multicast packets socket descriptor broadcasts. More...
 
static int multicast (socket_t socket, unsigned ttl=1)
 Set multicast mode and multicast broadcast range for socket descriptor. More...
 
static int nodelay (socket_t socket)
 Set tcp nodelay option on socket descriptor. More...
 
static unsigned pending (socket_t socket)
 Get the number of bytes pending in the receive buffer of a socket descriptor. More...
 
static ssize_t printf (socket_t socket, const char *format,...)
 Print formatted string to socket. More...
 
static int priority (socket_t socket, int scheduling)
 Set packet priority of socket descriptor. More...
 
static struct addrinfoquery (const char *host, const char *service, int type=SOCK_STREAM, int protocol=0)
 Get an address list directly. More...
 
static socklen_t query (socket_t socket, struct sockaddr_storage *address, const char *hostname, const char *service)
 Lookup a host name and service address based on the addressing family and socket type of a socket descriptor. More...
 
static char * query (const struct sockaddr *address, char *buffer, socklen_t size)
 Get the hostname of a socket address. More...
 
static void query (int family)
 Set default socket family preference for query options when the socket type is otherwise not specified. More...
 
static ssize_t readline (socket_t socket, char *data, size_t size, timeout_t timeout=Timer::inf)
 Read a newline of text data from the socket and save in NULL terminated string. More...
 
static ssize_t recvfrom (socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_storage *address=((void *) 0))
 Get data waiting in receive queue. More...
 
static ssize_t recvinet (socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_internet *address=((void *) 0))
 Get internet data waiting in receive queue. More...
 
static int recvsize (socket_t socket, unsigned size)
 Set the receive size of a socket descriptor. More...
 
static void release (struct addrinfo *list)
 Release an address list directly. More...
 
static void release (socket_t socket)
 Release (close) a socket. More...
 
static int remote (socket_t socket, struct sockaddr_storage *address)
 Get remote address to which the socket is connected. More...
 
static ssize_t replyto (socket_t socket, const void *buffer, size_t size, int flags, const struct sockaddr_storage *address)
 Send reply on socket. More...
 
static unsigned segsize (socket_t socket, unsigned size=0)
 Set segment size and get MTU. More...
 
static ssize_t sendinet (socket_t socket, const void *buffer, size_t size, int flags, const struct sockaddr_internet *address)
 Send to internet socket. More...
 
static int sendsize (socket_t socket, unsigned size)
 Set the send size of a socket descriptor. More...
 
static ssize_t sendto (socket_t socket, const void *buffer, size_t size, int flags=0, const struct sockaddr *address=((void *) 0))
 Send data on socket. More...
 
static int sendwait (socket_t socket, unsigned size)
 Set the size to wait before sending. More...
 
static short service (const struct sockaddr *address)
 Get the service port of a socket. More...
 
static short service (const struct sockaddr_internet *address)
 Get the service port of an inet socket. More...
 
static unsigned store (struct sockaddr_storage *storage, const struct sockaddr *address)
 Store an address into an address object. More...
 
static unsigned store (struct sockaddr_internet *storage, const struct sockaddr *address)
 Store an address into an internet address object. More...
 
static int tos (socket_t socket, int type)
 Set type of service of socket descriptor. More...
 
static int ttl (socket_t socket, unsigned char time)
 Set the time to live for the socket descriptor. More...
 
static int type (socket_t socket)
 Get the type of a socket. More...
 
static void v4mapping (bool enable)
 Set the default socket behavior for v6-v4 mapping. More...
 
static int via (struct sockaddr *address, const struct sockaddr *destination)
 Get the socket address of the interface needed to reach a destination address. More...
 
static bool wait (socket_t socket, timeout_t timeout=0)
 Test for pending input data. More...
 
- Protected Attributes inherited from ucommon::JoinableThread
volatile bool joining
 
volatile bool running
 
- Protected Attributes inherited from ucommon::Thread
void * cancellor
 
int priority
 
enum ucommon::Thread:: { ... }  reserved
 
size_t stack
 
pthread_t tid
 
- Protected Attributes inherited from ost::TCPStream
size_t bufsize
 
Family family
 
char * gbuf
 
char * pbuf
 
timeout_t timeout
 
- Protected Attributes inherited from ost::Socket
struct {
   bool   broadcast: 1
 
   bool   completion: 1
 
   bool   keepalive: 1
 
   bool   linger: 1
 
   bool   loopback: 1
 
   bool   multicast: 1
 
   bool   route: 1
 
   bool   thrown: 1
 
   unsigned   ttl: 8
 
flags
 
State volatile state
 
- Protected Attributes inherited from ucommon::Socket
int ioerr
 
timeout_t iowait
 
socket_t so
 
- Static Protected Attributes inherited from ost::Socket
static Mutex mutex
 

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 546 of file tcp.h.

Constructor & Destructor Documentation

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.
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

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.

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: