Base class for network sockets. More...
#include <socket.h>

Public Types | |
| enum | error { data_not_ready = -1, io_error = -2 } |
Public Member Functions | |
| socket () | |
| Constructor. | |
| socket (const socket &src) | |
| Constructor. | |
| socket & | operator= (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 |
Base class for network sockets.
Detailed class description.
| socket dbp::socket::accept | ( | ) |
Accept the incoming connection.
Accepts the incoming connection. The socket should be in listen mode to do this.
| const std::string& dbp::socket::address | ( | ) | const [inline] |
Get the socket address.
Obtains the connected socket ip address.
| void dbp::socket::bind | ( | const socket_address & | address | ) |
Binding to the specified network interfaces.
| address | a network address you want bind to |
| bool dbp::socket::connect | ( | const std::string & | address, | |
| int | port | |||
| ) |
Connection to remote server.
| 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.
| virtual int dbp::socket::read | ( | int | bytes_to_read, | |
| char * | buffer | |||
| ) | [virtual] |
Read data from the socket.
Reads data from buffer to a socket.
| bytes_to_read | a size of the buffer (number a bytes to read) | |
| buffer | a pointer to data readed |
Reimplemented in dbp::ssl_socket.
| virtual void dbp::socket::shutdown | ( | ) | [virtual] |
| virtual int dbp::socket::write | ( | int | bytes_to_write, | |
| const char * | buffer | |||
| ) | [virtual] |
Write data to the socket.
Writes buffer to a socket.
| bytes_to_write | a size of a buffer (number a bytes to write) | |
| buffer | a pointer to data to write |
Reimplemented in dbp::ssl_socket.