sockets::TCPSocket Class Reference

TCP socket class. More...

#include <tcpsocket.h>

Inheritance diagram for sockets::TCPSocket:

sockets::TCPClient sockets::IPSocket sockets::Socket List of all members.

Public Member Functions

 TCPSocket (Buffer *rbuf=0, Buffer *wbuf=0)
 Constructor.
 TCPSocket (TCPSocket const &tcps)
 Copy constructor.
TCPSocketoperator= (TCPSocket const &right)
 Assignment operator.
virtual bool connect ()
 Connects the socket.
virtual bool connect_next (bool *last=0)
 Connects to the next peer.
virtual bool set_remote (char const *address, char const *port, char const **error=0)
 Same as IPSocket::set_remote(), but resets the next connection to 0 if needed.
virtual bool set_remote (char const *address, unsigned short port, char const **error=0)
 Same as IPSocket::set_remote(), numeric port version.
virtual bool add_remote (char const *address, char const *port, char const **error=0)
 Adds remote address and port.
virtual char const * raddress () const
 Overrides IPSocket::raddress().
virtual unsigned short rport () const
 Overrides IPSocket::rport().

Protected Member Functions

virtual bool connect (IPInfo const *ipi)
 Connects to the given peer.
IPInfo const * next () const
 Returns the next peer to try to connect to.

Detailed Description

This class adds connection abilities to the TCPClient class.


Constructor & Destructor Documentation

sockets::TCPSocket::TCPSocket ( Buffer rbuf = 0,
Buffer wbuf = 0 
) [inline, explicit]

Constructor.

Parameters:
[in] rbuf If non-zero, points to the read buffer of the socket.
[in] wbuf If non-zero, points to the write buffer of the socket.
See also:
TCPClient::rbuf(), TCPClient::wbuf()


Member Function Documentation

virtual bool sockets::TCPSocket::connect (  )  [virtual]

Connects the socket to the remote address and port that have been specified through the set_remote() function.

This function creates the socket file descriptor if it is not created already, and calls the watch() function to monitor it. The ssCreated and ssMonitored status flags are thus guaranteed to be set if this function succeeds.

The socket may not be actually fully connected when this function succeeds; if it is, tne ssConnected and ssWritable status flags are set, the on_connect() function is called, the on_write() function is then called if the ssWritable flag is still set, else the ssConnecting flag is set. In both cases, the watch() function is called to monitor the socket so that incoming events are caught.

Returns:
true if successful, false otherwise. In the latter case, errno is set appropriately, unless you didn't call set_remote() or watch() fails.

virtual bool sockets::TCPSocket::connect_next ( bool *  last = 0  )  [virtual]

Connects to the next peer. The list of peers is specified through the add_remote() function.

This function creates the socket file descriptor if it is not created already, and calls the watch() function to monitor it. The ssCreated and ssMonitored status flags are thus guaranteed to be set if this function succeeds.

The socket may not be actually fully connected when this function succeeds; if it is, tne ssConnected and ssWritable status flags are set, the on_connect() function is called, the on_write() function is then called if the ssWritable flag is still set, else the ssConnecting flag is set. In both cases, the watch() function is called to monitor the socket so that incoming events are caught.

Parameters:
[out] last If non-zero, this is set to true if the peer is the last in the list, false otherwise.
Returns:
true if successful, false otherwise. In the latter case, errno is set appropriately, unless you didn't call set_remote() or watch() fails.

virtual bool sockets::TCPSocket::add_remote ( char const *  address,
char const *  port,
char const **  error = 0 
) [virtual]

Adds remote address and port to the existing list of peers that this socket can be connected to. It can't be changed once the ssListening, ssConnecting or ssConnected status flags are set on the socket.

This function calls the set_remote() function if the ssRemoteInfo status flag is not set. Else it adds the new peers to the TOP of the list.

Parameters:
[in] address An address to connect to, either as a hostname that will be resolved or an IP address expressed as a character string.
[in] port A port to connect to, either as a service listed in /etc/services or a port number expressed as a character string.
[out] error (optional) Points to a character wtring describing the error that happened if the function fails.
Returns:
true if successful, false otherwise.


The documentation for this class was generated from the following file:
Generated on Wed Aug 15 00:37:23 2007 for Epona API by  doxygen 1.5.2