#include <tcpsocket.h>
Public Member Functions | |
TCPSocket (Buffer *rbuf=0, Buffer *wbuf=0) | |
Constructor. | |
TCPSocket (TCPSocket const &tcps) | |
Copy constructor. | |
TCPSocket & | operator= (TCPSocket const &right) |
Assignment operator. | |
virtual bool | connect () |
Connects the socket. | |
virtual bool | connect_next () |
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(). | |
virtual bool | is_last () const |
Determines whether the last connect_next() targeted the last peer in the list. | |
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. |
Constructor.
[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. |
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.
virtual bool sockets::TCPSocket::connect_next | ( | ) | [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.
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.
[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. |