matador::socket_base< P > Class Template Reference

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

Detailed Description

template<class P>
class matador::socket_base< P >

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)

Template Parameters
PProtocol type

Member Typedef Documentation

◆ peer_type

template<class P >
typedef P::peer matador::socket_base< P >::peer_type

Shortcut to the peer type

◆ protocol_type

template<class P >
typedef P matador::socket_base< P >::protocol_type

Shortcut to the protocol type

Constructor & Destructor Documentation

◆ socket_base() [1/2]

template<class P >
matador::socket_base< P >::socket_base ( const protocol_type protocol)
explicit

Creates a socket for a specific given protocol

Parameters
protocolInitial protocol

◆ socket_base() [2/2]

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

Creates a socket with the given peer

Parameters
peerPeer used to initialize the socket

Member Function Documentation

◆ assign()

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

Parameters
sockThe socket fd to assign

◆ cloexec() [1/2]

template<class P >
bool matador::socket_base< P >::cloexec ( ) const

Returns true if close on exec option is set

Returns
True on set cloexec option

◆ cloexec() [2/2]

template<class P >
void matador::socket_base< P >::cloexec ( bool  nb)

Set or unset the cose on exec flag for the socket

Parameters
nbFlag to set or unset cloexec option

◆ close()

template<class P >
void matador::socket_base< P >::close ( )

Closes the open socket

◆ connect()

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

Parameters
pPeer to execute to
Returns
True on successful connection

◆ id()

template<class P >
socket_type matador::socket_base< P >::id ( ) const

Returns the underlying socket fd

Returns
Underlying socket fd

◆ is_open()

template<class P >
bool matador::socket_base< P >::is_open ( ) const

Returns true if the socket is open (created)

Returns
True on open socket

◆ non_blocking() [1/2]

template<class P >
bool matador::socket_base< P >::non_blocking ( ) const

Returns true if the socket is non blocking otherwise returns false

Returns
True if socket is non blocking

◆ non_blocking() [2/2]

template<class P >
void matador::socket_base< P >::non_blocking ( bool  nb)

Sets the socket either blocking (false) or non blocking (true).

Parameters
nbTrue sets the socket non blocking false blocking

◆ open()

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

Parameters
protocolProtocol for which a socket is created
Returns
The socket fd or -1 on error

◆ options()

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

Parameters
nameOption name
valueFlag to set or unset the option
Returns
True on success

◆ release()

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

Returns
The released socket fd

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