#include <socket_acceptor.hpp>
Inherits matador::socket_base< P >.
Public Types | |
typedef socket_base< P > | base |
typedef socket_stream< P > | stream_type |
typedef base::protocol_type | protocol_type |
typedef base::peer_type | peer_type |
Public Types inherited from matador::socket_base< P > | |
typedef P | protocol_type |
typedef P::peer | peer_type |
Public Member Functions | |
socket_acceptor ()=default | |
socket_acceptor (peer_type &peer) | |
socket_acceptor (const char *hostname, unsigned short port) | |
int | bind (const char *hostname, unsigned short port) |
int | bind (peer_type &peer) |
int | listen (int backlog) |
void * | get_in_addr (struct sockaddr *sa) |
unsigned short | get_port (struct sockaddr *sa) |
std::string | get_remote_address (struct sockaddr_storage &remote_addr) |
int | accept (stream_type &stream) |
int | accept (stream_type &stream, peer_type &endpoint) |
int | reuse_address (bool reuse) |
bool | reuse_address () const |
Public Member Functions inherited from matador::socket_base< P > | |
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) |
The socket acceptor class provides the base functionality of the socket base class plus acceptor specific functions like listen, bind or accept
P | Socket protocol type |
typedef socket_base<P> matador::socket_acceptor< P >::base |
Shortcut to base socket type
typedef base::peer_type matador::socket_acceptor< P >::peer_type |
Shortcut to peer type
typedef base::protocol_type matador::socket_acceptor< P >::protocol_type |
Shortcut to protocol type
typedef socket_stream<P> matador::socket_acceptor< P >::stream_type |
Shortcut to socket stream type
|
default |
Default constructor
|
explicit |
Constructs a socket acceptor for the given peer
peer | Peer to construct an acceptor from |
matador::socket_acceptor< P >::socket_acceptor | ( | const char * | hostname, |
unsigned short | port | ||
) |
Constructs an acceptor for given hostname and port
hostname | Hostname of the accepting endpoint |
port | Portnumber of the accepting endpoint |
int matador::socket_acceptor< P >::accept | ( | stream_type & | stream | ) |
Accept a connection and assign the socket descriptor to the given socket stream.
Once the descriptor is assigned to the stream it can be used to read and write data to it.
stream | Stream to use after connection was accepted |
int matador::socket_acceptor< P >::accept | ( | stream_type & | stream, |
peer_type & | endpoint | ||
) |
Accept a connection and assign the socket descriptor to the given socket stream.
Once the descriptor is assigned to the stream it can be used to read and write data to it.
The given peer endpoint is filled with the address information of the remote endpoint.
stream | Stream to use after connection was accepted |
endpoint | Will be filled with the remote endpoint information |
int matador::socket_acceptor< P >::bind | ( | const char * | hostname, |
unsigned short | port | ||
) |
Creates a listening socket and binds the given hostname and port to it
Returns zero (0) on success and -1 on error with errno set
hostname | Hostname to bind |
port | Portnumber to bind |
int matador::socket_acceptor< P >::bind | ( | peer_type & | peer | ) |
Creates a listening socket and binds the given peer endpoint to it
Returns zero (0) on success and -1 on error with errno set
peer | Binds the given peer endpoint to the socket |
void * matador::socket_acceptor< P >::get_in_addr | ( | struct sockaddr * | sa | ) |
Returns a pointer to the underlying concrete internet address of the given socket address structure
sa | Socket address |
unsigned short matador::socket_acceptor< P >::get_port | ( | struct sockaddr * | sa | ) |
Returns the port number of the given socket address structure
sa | Socket address |
std::string matador::socket_acceptor< P >::get_remote_address | ( | struct sockaddr_storage & | remote_addr | ) |
Get the remote address and port as string representation.
remote_addr | Remote socket address structure |
int matador::socket_acceptor< P >::listen | ( | int | backlog | ) |
Start listening to the bound endpoint using the internally created socket.
Returns zero (0) on success and -1 on error with errno set
backlog | Number of backlog |
bool matador::socket_acceptor< P >::reuse_address | ( | ) | const |
Returns true if the flag is set otherwise false is returned.
int matador::socket_acceptor< P >::reuse_address | ( | bool | reuse | ) |
Sets or clears the reuse address flag. If the given value is true the flag is set otherwise the flag is cleared.
reuse | Indicates if the reuse address flag should be set |