dbp::socket Class Reference

Base class for network sockets. More...

#include <socket.h>

Inheritance diagram for dbp::socket:
Inheritance graph
[legend]

List of all members.

Public Types

enum  error { data_not_ready = -1, io_error = -2 }

Public Member Functions

 socket ()
 Constructor.
 socket (const socket &src)
 Constructor.
socketoperator= (const socket &src)
 Copy operator.
virtual ~socket ()
 Destructor.
virtual int handle () const
 Get socket handle.
bool connect (const std::string &address, int port)
 Connection to remote server.
void bind (const socket_address &address)
 Binding to the specified network interfaces.
void listen ()
 Listening for incoming connections.
socket accept ()
 Accept the incoming connection.
virtual int read (int bytes_to_read, char *buffer)
 Read data from the socket.
virtual int write (int bytes_to_write, const char *buffer)
 Write data to the socket.
virtual void shutdown ()
 Shut down the connection.
const std::string & address () const
 Get the socket address.
int port () const
 Get the socket port number.

Protected Attributes

int socket_fd
std::string _address
int _port

Detailed Description

Base class for network sockets.

Detailed class description.


Member Function Documentation

socket dbp::socket::accept (  ) 

Accept the incoming connection.

Accepts the incoming connection. The socket should be in listen mode to do this.

Returns:
a socket to communicate
const std::string& dbp::socket::address (  )  const [inline]

Get the socket address.

Obtains the connected socket ip address.

Returns:
the socket ip address
void dbp::socket::bind ( const socket_address address  ) 

Binding to the specified network interfaces.

Parameters:
address a network address you want bind to
bool dbp::socket::connect ( const std::string &  address,
int  port 
)

Connection to remote server.

Parameters:
address a server address you want connect to
void dbp::socket::listen (  ) 

Listening for incoming connections.

Switchs a socket to a passive state for listening for connections from clients.

int dbp::socket::port (  )  const [inline]

Get the socket port number.

Obtains the connected socket port number.

Returns:
the socket port number
virtual int dbp::socket::read ( int  bytes_to_read,
char *  buffer 
) [virtual]

Read data from the socket.

Reads data from buffer to a socket.

Parameters:
bytes_to_read a size of the buffer (number a bytes to read)
buffer a pointer to data readed
Returns:
number of a bytes readed or -1 on error

Reimplemented in dbp::ssl_socket.

virtual void dbp::socket::shutdown (  )  [virtual]

Shut down the connection.

Closes the connection gracefully.

Reimplemented in dbp::ssl_socket.

virtual int dbp::socket::write ( int  bytes_to_write,
const char *  buffer 
) [virtual]

Write data to the socket.

Writes buffer to a socket.

Parameters:
bytes_to_write a size of a buffer (number a bytes to write)
buffer a pointer to data to write
Returns:
number of a bytes written or -1 on error

Reimplemented in dbp::ssl_socket.


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

 
Support This Project
SourceForge.net Logo