sockets::IPSocket Class Reference

Base class for all IP sockets. More...

#include <ipsocket.h>

Inheritance diagram for sockets::IPSocket:

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

Public Member Functions

 IPSocket (int type=0, int protocol=0)
 Constructor.
 IPSocket (IPSocket const &ips)
 Copy constructor.
virtual IPSocketoperator= (IPSocket const &right)
 Assignment operator.
 ~IPSocket ()
 Destructor.
virtual bool assign (int fd, uint32_t status)
 Assigns a socket file descriptor.
virtual bool bind ()
 Binds the socket.
virtual bool set_local (char const *address, char const *port, char const **error=0)
 Sets local address and port.
virtual bool set_local (char const *address, unsigned short port, char const **error=0)
 Same as the other set_local(), but port is an integer.
virtual bool set_remote (char const *address, char const *port, char const **error=0)
 Sets remote address and port.
virtual bool set_remote (char const *address, unsigned short port, char const **error=0)
 Same as the other set_remote(), but port is an integer.
virtual char const * laddress () const
 Returns the local address.
virtual unsigned short lport () const
 Returns the local port.
virtual char const * raddress () const
 Returns the remote address.
virtual unsigned short rport () const
 Returns the remote port.

Protected Member Functions

virtual bool create ()
 Overrides Socket::create() to set the socket as non-blocking.
bool resolve (char const *address, char const *port, char const **error, IPInfo **ipi)
 Resolves an address and port.
IPInfolocal ()
 Returns the local information.
IPInfo const * local () const
 Returns the local information.
IPInforemote ()
 Returns the remote information.
IPInfo const * remote () const
 Returns the remote information.
unsigned short port (IPInfo const *ipi) const
 Returns the port out of an IPInfo object.

Classes

class  IPInfo
 IP information class. More...

Detailed Description

This is the base class for all IP sockets. It must not be instantiated directly; rather, use a derived class or create your own.

This class provides support to set up and retrieve information about the local and remote end of a connection, as well as a function to bind the socket to a specific address and/or port.

Both IPv4 and IPv6 are supported.


Constructor & Destructor Documentation

sockets::IPSocket::IPSocket int  type = 0,
int  protocol = 0
[inline, explicit]
 

Constructor.

Parameters:
[in] type The socket type (one of the SOCK_... constants defined in the system header files). May be set to 0 if you want to set it later.
[in] protocol The socket protocol that needs to be used. This is seldom used, as there is generally only one protocol for a given family/type combination; use the value 0 to use the default protocol.


Member Function Documentation

virtual bool sockets::IPSocket::assign int  fd,
uint32_t  status
[virtual]
 

Assigns a socket file descriptor to the socket object, that is then used by the object for all operations on the socket.

This function overrides Socket::assign() to set the socket as non-blocking.

Parameters:
[in] fd The socket file descriptor to assign.
[in] status The status flags that are added to the socket. If the ssMonitored flag is among them, the watch() function is automatically called.
Returns:
true if successful, false otherwise. errno is set accordingly in the latter case.

Reimplemented from sockets::Socket.

Reimplemented in sockets::TCPClient.

virtual bool sockets::IPSocket::bind  )  [virtual]
 

Binds the socket to the local address and port that have been specified through the set_local() function.

This function creates the socket file descriptor if it is not created already. The ssCreated and ssBound flags are guaranteed to be set if this function succeeds.

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

virtual char const* sockets::IPSocket::laddress  )  const [virtual]
 

Returns the local address. This is either the address set through the set_local() function if it was used, or the one the socket is actually bound to if the ssCreated status flag is set and ssLocalInfo is not.

Returns:
The local address, or 0 if it is unavailable.

virtual unsigned short sockets::IPSocket::lport  )  const [virtual]
 

Returns the local port. This is the port set through the set_local() function if it was used, or the one the socket is actually bound to if the ssCreated status flag is set and ssLocalInfo is not.

Returns:
The local port, or 0 if it is unavailable.

virtual char const* sockets::IPSocket::raddress  )  const [virtual]
 

Returns the remote address. This is the address set through the set_remote() function.

Returns:
The remote address, or 0 if it is unavailable.

Reimplemented in sockets::TCPSocket.

bool sockets::IPSocket::resolve char const *  address,
char const *  port,
char const **  error,
IPInfo **  ipi
[protected]
 

Resolves an address and port.

Parameters:
[in] address The address to resolve. It may either be an IP address or a hostname.
[in] port The port to resolve. It may either be a numeric port or a service name.
[out] error A pointer to a character string receiving an error message when the function returns false. May be NULL.
[in] ipi On input, points to either a NULL pointer or a pointer to an IPInfo object that will be the next object in the resolved list. On output, points to either the original pointer or to the first new object of the resolved list.
Returns:
true if successful, false otherwise.

virtual unsigned short sockets::IPSocket::rport  )  const [virtual]
 

Returns the remote port. This is the port set through the set_remote() function.

Returns:
The remote port, or 0 if it is unavailable.

Reimplemented in sockets::TCPSocket.

virtual bool sockets::IPSocket::set_local char const *  address,
char const *  port,
char const **  error = 0
[virtual]
 

Sets local address and port. It can't be changed once the ssBound, ssListening, ssConnecting or ssConnected status flags are set on the socket.

This function determines the socket protocol family if the ssRemoteInfo and ssCreated status flags are not set on the socket.

Parameters:
[in] address The address to bind to, either as a hostname that will be resolved or an IP address expressed as a character string.
[in] port The port to bind 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.

virtual bool sockets::IPSocket::set_remote char const *  address,
char const *  port,
char const **  error = 0
[virtual]
 

Sets remote address and port. It can't be changed once the ssListening, ssConnecting or ssConnected status flags are set on the socket.

This function determines the socket protocol family if the ssLocalInfo and ssCreated status flags are not set on the socket.

Parameters:
[in] address The address to connect to, either as a hostname that will be resolved or an IP address expressed as a character string.
[in] port The 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.

Reimplemented in sockets::TCPSocket.


The documentation for this class was generated from the following file:
Generated on Sun May 20 21:32:22 2007 for Epona API by  doxygen 1.4.6