Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

eqn_cruncher::socket Class Reference

This class is a thin wrapper around the standard UNIX socket interface. More...

#include <socket.hpp>

List of all members.

Public Types

typedef std::pair< sockaddr_in,
int > 
accept_t

Public Methods

int get_sockid ()
 Get the file descriptor of the socket.

 socket ()
 Default constructs a socket.

 socket (const int _sockid)
 Constructs a socket from an existing file descriptor.

std::string get_remote_name ()
void reuse_sock_addr ()
 Frees the port number associated with the current socket, so that on exit, the port can be re-used immediately.

void bind (unsigned short int _pno)
 Binds a socket to a port.

void connect (unsigned short int _pno, std::string const &host_name)
 Connects the socket to some remote host specified in the second parameter.

void listen (int max_queued=10)
 Makes the socket listen for connections.

accept_t accept ()
 Accepts new connections if the listen() function succeeded.

int send (const char *buff, int buff_len)
 This function sends data to the entity on the other side of the socket.

int send (std::string const &data)
 This function sends a string to the entity on the other side of the socket.

int sendto (const char *buff, int len, std::string const &host_name)
 This function sends data to the entity on the other side of the socket. It works on unconnected sockets.

int sendto (std::string const &msg, std::string const &host_name)
 This function sends a string to the entity on the other side of the socket. It works on unconnected sockets.

int receive (void *buff, int buff_size)
 A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data.

int receive_from (void *buff, int buff_size)
 A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data. This function works on unconected sockets.

void close ()
 Closes the socket for reading as well as writing.


Static Public Methods

sockaddr_in get_socket_info (unsigned short int port_no)
 Get the socket information.

hostent * host_by_name (std::string const &host_name)
 Returns the host info given the host name as a string.

std::string str_ip (unsigned int uint_ip)
 Returns the IP address as a string given the IP address in host byte order.


Detailed Description

This class is a thin wrapper around the standard UNIX socket interface.


Member Typedef Documentation

typedef std::pair<sockaddr_in, int> eqn_cruncher::socket::accept_t
 

This is the type returned by the accept function. It contains: 1. The socket information such as the the IP address, etc... of the connector. 2. The file descriptor of the socket.


Constructor & Destructor Documentation

eqn_cruncher::socket::socket   [inline]
 

Default constructs a socket.

This basically creates a new socket, and assigned the new file descriptor of the socket to the internal member sock_id.

eqn_cruncher::socket::socket const int    _sockid [inline, explicit]
 

Constructs a socket from an existing file descriptor.

Checks internally in debug mode if the file descriptor is not an invalid value.

Parameters:
_sockid  The file descriptor of the socket already opened.


Member Function Documentation

accept_t eqn_cruncher::socket::accept   [inline]
 

Accepts new connections if the listen() function succeeded.

void eqn_cruncher::socket::bind unsigned short int    _pno [inline]
 

Binds a socket to a port.

Parameters:
_pno  The port number to bind the socket to.

void eqn_cruncher::socket::close   [inline]
 

Closes the socket for reading as well as writing.

void eqn_cruncher::socket::connect unsigned short int    _pno,
std::string const &    host_name
[inline]
 

Connects the socket to some remote host specified in the second parameter.

Parameters:
_pno  The port number to use while trying to connect and on connecting.
host_name  The host name specified as a string. This function perfroms a DNS lookup internally to find the IP address given the host name. This host name can also be a string containing the IP address in host byte order.

std::string eqn_cruncher::socket::get_remote_name   [inline]
 

sockaddr_in eqn_cruncher::socket::get_socket_info unsigned short int    port_no [inline, static]
 

Get the socket information.

Parameters:
port_no  The port number to be associated with the socket information.
Returns:
The socket information in the form of an object of type sockaddr_in.

int eqn_cruncher::socket::get_sockid   [inline]
 

Get the file descriptor of the socket.

Returns:
The file descriptor of the socket.

hostent* eqn_cruncher::socket::host_by_name std::string const &    host_name [inline, static]
 

Returns the host info given the host name as a string.

Parameters:
host_name  A string specifying the host name.
Returns:
A pointer to a hostent structure.

void eqn_cruncher::socket::listen int    max_queued = 10 [inline]
 

Makes the socket listen for connections.

Parameters:
max_queued  The maximum number of queued up requests that the internal buffer should be able to hold while listening for new conenctions.

int eqn_cruncher::socket::receive void *    buff,
int    buff_size
[inline]
 

A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data.

Parameters:
buff  A buffer to place the read data.
buff_size  The size of the buffer buff.
Returns:
The number of bytes actually read.

int eqn_cruncher::socket::receive_from void *    buff,
int    buff_size
[inline]
 

A blocking function which reads data off the socket. It waits until the person at the other side has written something onto the socket, and reads off that written data. This function works on unconected sockets.

Parameters:
buff  A buffer to place the read data.
buff_size  The size of the buffer buff.
Returns:
The number of bytes actually read.

void eqn_cruncher::socket::reuse_sock_addr   [inline]
 

Frees the port number associated with the current socket, so that on exit, the port can be re-used immediately.

int eqn_cruncher::socket::send std::string const &    data [inline]
 

This function sends a string to the entity on the other side of the socket.

Parameters:
data  The string to be sent.
Returns:
The number of bytes actually sent.

int eqn_cruncher::socket::send const char *    buff,
int    buff_len
[inline]
 

This function sends data to the entity on the other side of the socket.

Parameters:
buff  A buffer containing the data to be sent.
buff_len  The size of the actual data to be sent in the buffer.
Returns:
The number of bytes actually sent.

int eqn_cruncher::socket::sendto std::string const &    msg,
std::string const &    host_name
[inline]
 

This function sends a string to the entity on the other side of the socket. It works on unconnected sockets.

Parameters:
msg  The string to be sent.
host_name  The host name specified as a string. This function perfroms a DNS lookup internally to find the IP address given the host name. This host name can also be a string containing the IP address in host byte order.
Returns:
The number of bytes actually sent.

int eqn_cruncher::socket::sendto const char *    buff,
int    len,
std::string const &    host_name
[inline]
 

This function sends data to the entity on the other side of the socket. It works on unconnected sockets.

Parameters:
buff  A buffer containing the data to be sent.
len  The size of the actual data to be sent in the buffer.
host_name  The host name specified as a string. This function perfroms a DNS lookup internally to find the IP address given the host name. This host name can also be a string containing the IP address in host byte order.
Returns:
The number of bytes actually sent.

std::string eqn_cruncher::socket::str_ip unsigned int    uint_ip [inline, static]
 

Returns the IP address as a string given the IP address in host byte order.

Parameters:
uint_ip  The IP address in host byte order.
Returns:
The IP address as a string.


The documentation for this class was generated from the following file:
Generated on Mon Oct 11 13:09:26 2004 for Equation Cruncher by doxygen1.2.18