matador::socket_acceptor< P > Class Template Reference

#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)
 

Detailed Description

template<class P>
class matador::socket_acceptor< P >

The socket acceptor class provides the base functionality of the socket base class plus acceptor specific functions like listen, bind or accept

Template Parameters
PSocket protocol type

Member Typedef Documentation

◆ base

template<class P >
typedef socket_base<P> matador::socket_acceptor< P >::base

Shortcut to base socket type

◆ peer_type

template<class P >
typedef base::peer_type matador::socket_acceptor< P >::peer_type

Shortcut to peer type

◆ protocol_type

template<class P >
typedef base::protocol_type matador::socket_acceptor< P >::protocol_type

Shortcut to protocol type

◆ stream_type

template<class P >
typedef socket_stream<P> matador::socket_acceptor< P >::stream_type

Shortcut to socket stream type

Constructor & Destructor Documentation

◆ socket_acceptor() [1/3]

template<class P >
matador::socket_acceptor< P >::socket_acceptor ( )
default

Default constructor

◆ socket_acceptor() [2/3]

template<class P >
matador::socket_acceptor< P >::socket_acceptor ( peer_type peer)
explicit

Constructs a socket acceptor for the given peer

Parameters
peerPeer to construct an acceptor from

◆ socket_acceptor() [3/3]

template<class P >
matador::socket_acceptor< P >::socket_acceptor ( const char *  hostname,
unsigned short  port 
)

Constructs an acceptor for given hostname and port

Parameters
hostnameHostname of the accepting endpoint
portPortnumber of the accepting endpoint

Member Function Documentation

◆ accept() [1/2]

template<class P >
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.

Parameters
streamStream to use after connection was accepted
Returns
The fd of the new connection

◆ accept() [2/2]

template<class P >
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.

Parameters
streamStream to use after connection was accepted
endpointWill be filled with the remote endpoint information
Returns
The fd of the new connection

◆ bind() [1/2]

template<class P >
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

Parameters
hostnameHostname to bind
portPortnumber to bind
Returns
Returns zero (0) on success.

◆ bind() [2/2]

template<class P >
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

Parameters
peerBinds the given peer endpoint to the socket
Returns
Returns zero (0) on success.

◆ get_in_addr()

template<class P >
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

Parameters
saSocket address
Returns
Pointer to the internet address

◆ get_port()

template<class P >
unsigned short matador::socket_acceptor< P >::get_port ( struct sockaddr *  sa)

Returns the port number of the given socket address structure

Parameters
saSocket address
Returns
The port number

◆ get_remote_address()

template<class P >
std::string matador::socket_acceptor< P >::get_remote_address ( struct sockaddr_storage &  remote_addr)

Get the remote address and port as string representation.

Parameters
remote_addrRemote socket address structure
Returns
String representation of the remote address

◆ listen()

template<class P >
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

Parameters
backlogNumber of backlog
Returns
Returns zero (0) on success.

◆ reuse_address() [1/2]

template<class P >
bool matador::socket_acceptor< P >::reuse_address ( ) const

Returns true if the flag is set otherwise false is returned.

Returns
True if flag is set

◆ reuse_address() [2/2]

template<class P >
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.

Parameters
reuseIndicates if the reuse address flag should be set
Returns
0 if setting was successful, -1 on error

The documentation for this class was generated from the following file:
  • matador/net/socket_acceptor.hpp