#include <socket.hpp>
Inherited by matador::socket_acceptor< tcp >, matador::socket_stream< tcp >, matador::socket_acceptor< P >, and matador::socket_stream< P >.
Public Types | |
| typedef P | protocol_type |
| typedef P::peer | peer_type |
Public Member Functions | |
| socket_base (const protocol_type &protocol) | |
| socket_base (const peer_type &peer) | |
| socket_type | open (const protocol_type &protocol) |
| void | close () |
| bool | is_open () const |
| socket_type | release () |
| bool | connect (const typename protocol_type::peer &p) |
| void | non_blocking (bool nb) |
| bool | non_blocking () const |
| void | cloexec (bool nb) |
| bool | cloexec () const |
| bool | options (int name, bool value) |
| socket_type | id () const |
| void | assign (socket_type sock) |
Base class for several kind of socket classes (acceptor, stream) representing a socket. The protocol is selected via the template parameter (/sa tcp and udp classes)
| P | Protocol type |
| typedef P::peer matador::socket_base< P >::peer_type |
Shortcut to the peer type
| typedef P matador::socket_base< P >::protocol_type |
Shortcut to the protocol type
|
explicit |
Creates a socket for a specific given protocol
| protocol | Initial protocol |
|
explicit |
Creates a socket with the given peer
| peer | Peer used to initialize the socket |
| void matador::socket_base< P >::assign | ( | socket_type | sock | ) |
Assigns the given socket fd to this socket. If the socket is already opened an exception is thrown.
| sock | The socket fd to assign |
| bool matador::socket_base< P >::cloexec | ( | ) | const |
Returns true if close on exec option is set
| void matador::socket_base< P >::cloexec | ( | bool | nb | ) |
Set or unset the cose on exec flag for the socket
| nb | Flag to set or unset cloexec option |
| void matador::socket_base< P >::close | ( | ) |
Closes the open socket
| bool matador::socket_base< P >::connect | ( | const typename protocol_type::peer & | p | ) |
Connect to the given peer. If the connection could be established true is returned, otherwise false is returned and errno is set.
| p | Peer to execute to |
| socket_type matador::socket_base< P >::id | ( | ) | const |
Returns the underlying socket fd
| bool matador::socket_base< P >::is_open | ( | ) | const |
Returns true if the socket is open (created)
| bool matador::socket_base< P >::non_blocking | ( | ) | const |
Returns true if the socket is non blocking otherwise returns false
| void matador::socket_base< P >::non_blocking | ( | bool | nb | ) |
Sets the socket either blocking (false) or non blocking (true).
| nb | True sets the socket non blocking false blocking |
| socket_type matador::socket_base< P >::open | ( | const protocol_type & | protocol | ) |
Opens a socket. On success a positive socket id (fd) is returned. In case of error -1 is returned and errno is set.
| protocol | Protocol for which a socket is created |
| bool matador::socket_base< P >::options | ( | int | name, |
| bool | value | ||
| ) |
Sets a socket option represented by name. If option was successfully set true is returned. Otherwise false and errno ist set.
| name | Option name |
| value | Flag to set or unset the option |
| socket_type matador::socket_base< P >::release | ( | ) |
Releases the socket fd and sets the internal socket to zero (0).
After the socket is released the user is in charge to take of the socket