sends::socket_api Class Reference

Socket API. More...

#include <socket_api.hh>

Inheritance diagram for sends::socket_api:

sends::raw_socket sends::ssl_bio

List of all members.

Public Types

enum  sock_err { serr_OK = 0, serr_failure, serr_retry, serr_internal }

Public Member Functions

 socket_api (void)
 Constructor.
virtual ~socket_api (void)
 Destructor.
virtual socket_apiaccept (void)=0
 Accept a connection request.
virtual sock_err bind (const std::string &addr)=0
 Bind socket to a local address.
virtual sock_err close (void)=0
 Close the socket.
virtual sock_err connect (const std::string &s)=0
 connect to specied peer.
sock_err error (void) const
 get error code.
virtual long gets (char *buf, long len, char term='\n')
 Read a terminated data string.
virtual sock_err handshake (void)
 Handhake with connecting peer socket.
virtual sock_err listen (const std::string &port, int lq)=0
 Listen for connection requests.
const char * peer_name (void) const
virtual long read (char *buf, long len)
 Read data.
virtual long read_available (char *buf, long len)=0
 Read available data.
void set_error (sock_err err)
 Set the error code.
sock_err set_error (void)
 Set the error code from system codes.
void set_verbose (int verb)
 Set the verbosity.
virtual int socket_id (void) const =0
 Get the socket id.
int verbose (void) const
 Set the verbosity.
virtual long write (const char *buf, long len)=0
 Write data.
virtual int wait_data (double nsec)
 Wait for data.

Static Public Member Functions

static sock_err parse_addr (const std::string &addr, unsigned int &node, unsigned short &port)
 Parse an IP address.

Protected Attributes

sock_err mError
 Status of most recent method.
int mVerbose
 Error print-out verbosity level.
std::string mPeer
 Peer name.


Detailed Description

Socket API.

The socket API defines the basic functions needed for manipulating a socket.

Author:
J. Zweizig
Version:
1.0; modified April 24, 2008

Member Enumeration Documentation

Enumerated socket errors.


Constructor & Destructor Documentation

sends::socket_api::socket_api ( void   ) 

Constructor.

Construct a socket.

virtual sends::socket_api::~socket_api ( void   )  [virtual]

Destructor.

Close the socket ans destry the local data.


Member Function Documentation

virtual socket_api* sends::socket_api::accept ( void   )  [pure virtual]

Accept a connection request.

Accept creates a new socket connected to the first external socket requesting a connection.

Returns:
Pointer to a new socket connected to requestor.

Implemented in sends::raw_socket, and sends::ssl_bio.

virtual sock_err sends::socket_api::bind ( const std::string &  addr  )  [pure virtual]

Bind socket to a local address.

Bind the socket to a local address. If the IP address is zero the socket will be bound to all local networks. If the port number is zero or omitted, the next available port is allocated.

Parameters:
addr Local addres to which the socet is to be bound.
Returns:
Socket error code.

Implemented in sends::raw_socket, and sends::ssl_bio.

virtual sock_err sends::socket_api::close ( void   )  [pure virtual]

Close the socket.

Abstract method to close the socket. This method will depend strongly on the implementation.

Implemented in sends::raw_socket, and sends::ssl_bio.

virtual sock_err sends::socket_api::connect ( const std::string &  s  )  [pure virtual]

connect to specied peer.

Connect to the specified address.

Parameters:
s Peer socket address
Returns:
Socket error code.

Implemented in sends::raw_socket, and sends::ssl_bio.

socket_api::sock_err sends::socket_api::error ( void   )  const [inline]

get error code.

Get the error result from the most recent socket operation.

Returns:
Error code as enumerated in socket_err.

References mError.

virtual long sends::socket_api::gets ( char *  buf,
long  len,
char  term = '\n' 
) [virtual]

Read a terminated data string.

Read the specified number of bytes into the buffer or until a termination character is found.

Parameters:
buf Pointer to buffer to receive data.
len Maximum length of data to be read (in bytes).
term termination character
Returns:
Number of data bytes read or -1 on error

virtual sock_err sends::socket_api::handshake ( void   )  [virtual]

Handhake with connecting peer socket.

Perform connection handshakes. This method may be trivial in cases where no encryption or authorization takes place.

Returns:
Socket status codes.

Reimplemented in sends::ssl_bio.

virtual sock_err sends::socket_api::listen ( const std::string &  port,
int  lq 
) [pure virtual]

Listen for connection requests.

Listen to the specified port address, Queue the specified number of connection requests pending acceptance.

Parameters:
port Local port name to listen to.
lq Length of connection request queue
Returns:
Socket error code.

Implemented in sends::raw_socket, and sends::ssl_bio.

static sock_err sends::socket_api::parse_addr ( const std::string &  addr,
unsigned int &  node,
unsigned short &  port 
) [static]

Parse an IP address.

Parse a port address into an ip address and a port number. The input syntax is "address:port".

Parameters:
addr Address string.
node IP address
port Port number
Returns:
Socket error code.

const char * sends::socket_api::peer_name ( void   )  const [inline]

Peer name.

References mPeer.

virtual long sends::socket_api::read ( char *  buf,
long  len 
) [virtual]

Read data.

Read exactly the specified number of bytes into the buffer.

Parameters:
buf Pointer to buffer to receive data.
len Maximum length of data to be read (in bytes).
Returns:
Number of data bytes read or -1 on error

virtual long sends::socket_api::read_available ( char *  buf,
long  len 
) [pure virtual]

Read available data.

Read up to the specified number of bytes from the socket into the buffer.

Parameters:
buf Pointer to buffer to receive data.
len Maximum length of data to be read (in bytes).
Returns:
Number of data bytes read.

Implemented in sends::raw_socket, and sends::ssl_bio.

void sends::socket_api::set_error ( sock_err  err  ) 

Set the error code.

set the error code.

Parameters:
err Error code.

sock_err sends::socket_api::set_error ( void   ) 

Set the error code from system codes.

Set the socket error code based on an educated guess from errno.

void sends::socket_api::set_verbose ( int  verb  ) 

Set the verbosity.

Set the verbosity level. The default level (1) prints messages for each failure.

Parameters:
verb Verbosity level.

virtual int sends::socket_api::socket_id ( void   )  const [pure virtual]

Get the socket id.

Get a socket id number. In general this will be the system fd for the socket.

Returns:
Socket id for use in select.

Implemented in sends::raw_socket, and sends::ssl_bio.

int sends::socket_api::verbose ( void   )  const [inline]

Set the verbosity.

Set the verbosity level. The default level (1) prints messages for each failure.

Returns:
Verbosity level.

References mVerbose.

virtual long sends::socket_api::write ( const char *  buf,
long  len 
) [pure virtual]

Write data.

Write the specified number of bytes into the buffer.

Parameters:
buf Pointer to data to be written
len Length of data to be written (in bytes).
Returns:
Number of data bytes written or -1 on error.

Implemented in sends::raw_socket, and sends::ssl_bio.

virtual int sends::socket_api::wait_data ( double  nsec  )  [virtual]

Wait for data.

Wait at most the specified number of seconds for data to arrive for reading.

Parameters:
nsec Maximum number of seconds to wait for data
Returns:
Integer with the following values:
  • -1 Systerm error occurred (e.g. EINTR)
  • 0 Request timed out.
  • 1 data available on port.

Reimplemented in sends::raw_socket.


The documentation for this class was generated from the following file:

Generated on Tue Jun 10 12:18:12 2008 for SENDS by  doxygen 1.5.5