Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
sockpp::acceptor_tmpl< STREAM_SOCK, ADDR > Class Template Reference

#include <acceptor.h>

Inheritance diagram for sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >:
sockpp::acceptor sockpp::socket

Public Types

using stream_sock_t = STREAM_SOCK
 
using addr_t = ADDR
 

Public Member Functions

 acceptor_tmpl ()
 
 acceptor_tmpl (const addr_t &addr, int queSize=DFLT_QUE_SIZE)
 
 acceptor_tmpl (in_port_t port, int queSize=DFLT_QUE_SIZE)
 
 acceptor_tmpl (acceptor_tmpl &&acc)
 
acceptor_tmploperator= (acceptor_tmpl &&rhs)
 
addr_t address () const
 
bool bind (const addr_t &addr)
 
bool open (const addr_t &addr, int queSize=DFLT_QUE_SIZE)
 
bool open (in_port_t port, int queSize=DFLT_QUE_SIZE)
 
stream_sock_t accept (addr_t *clientAddr=nullptr)
 
- Public Member Functions inherited from sockpp::acceptor
 acceptor ()
 
 acceptor (socket_t handle)
 
 acceptor (const sock_address &addr, int queSize=DFLT_QUE_SIZE)
 
 acceptor (acceptor &&acc)
 
acceptoroperator= (acceptor &&rhs)
 
bool listen (int queSize=DFLT_QUE_SIZE)
 
bool open (const sock_address &addr, int queSize=DFLT_QUE_SIZE, bool reuseSock=true)
 
stream_socket accept (sock_address *clientAddr=nullptr)
 
- Public Member Functions inherited from sockpp::socket
 socket ()
 
 socket (socket_t h)
 
 socket (socket &&sock) noexcept
 
virtual ~socket ()
 
bool is_open () const
 
bool operator! () const
 
 operator bool () const
 
socket_t handle () const
 
virtual sa_family_t family () const
 
socket clone () const
 
void clear (int val=0)
 
socket_t release ()
 
void reset (socket_t h=INVALID_SOCKET)
 
socketoperator= (socket &&sock) noexcept
 
bool bind (const sock_address &addr)
 
sock_address_any address () const
 
sock_address_any peer_address () const
 
bool get_option (int level, int optname, void *optval, socklen_t *optlen) const
 
template<typename T >
bool get_option (int level, int optname, T *val) const
 
bool set_option (int level, int optname, const void *optval, socklen_t optlen)
 
template<typename T >
bool set_option (int level, int optname, const T &val)
 
bool set_non_blocking (bool on=true)
 
int last_error () const
 
std::string last_error_str () const
 
bool shutdown (int how=SHUT_RDWR)
 
bool close ()
 

Static Public Member Functions

static acceptor_tmpl create ()
 
- Static Public Member Functions inherited from sockpp::acceptor
static acceptor create (int domain)
 
- Static Public Member Functions inherited from sockpp::socket
static void initialize ()
 
static void destroy ()
 
static socket create (int domain, int type, int protocol=0)
 
static std::tuple< socket, socketpair (int domain, int type, int protocol=0)
 
static std::string error_str (int errNum)
 

Additional Inherited Members

- Protected Member Functions inherited from sockpp::socket
bool close_on_err ()
 
void set_last_error ()
 
template<typename T >
check_ret (T ret) const
 
template<typename T >
bool check_ret_bool (T ret) const
 
socket_t check_socket (socket_t ret) const
 
bool check_socket_bool (socket_t ret) const
 
- Static Protected Member Functions inherited from sockpp::acceptor
static socket_t create_handle (int domain)
 
- Static Protected Member Functions inherited from sockpp::socket
static int get_last_error ()
 
- Static Protected Attributes inherited from sockpp::acceptor
static const int DFLT_QUE_SIZE = 4
 

Detailed Description

template<typename STREAM_SOCK, typename ADDR = typename STREAM_SOCK::addr_t>
class sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >

Base template class for streaming servers of specific address families. This is a base for creating socket acceptor classes for an individual family. In most cases, all that is needed is a type definition specifying which addresses type should be used to receive incoming connections, like: using tcp_acceptor = acceptor_tmpl<tcp_socket>;

Member Typedef Documentation

◆ addr_t

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
using sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::addr_t = ADDR

The type of address for the acceptor and streams.

◆ stream_sock_t

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
using sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::stream_sock_t = STREAM_SOCK

The type of streaming socket from the acceptor.

Constructor & Destructor Documentation

◆ acceptor_tmpl() [1/4]

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::acceptor_tmpl ( )
inline

Creates an unconnected acceptor.

◆ acceptor_tmpl() [2/4]

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::acceptor_tmpl ( const addr_t & addr,
int queSize = DFLT_QUE_SIZE )
inline

Creates a acceptor and starts it listening on the specified address.

Parameters
addrThe TCP address on which to read_message.
queSizeThe listener queue size.

◆ acceptor_tmpl() [3/4]

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::acceptor_tmpl ( in_port_t port,
int queSize = DFLT_QUE_SIZE )
inline

Creates a acceptor and starts it listening on the specified port. The acceptor binds to the specified port for any address on the local host.

Parameters
portThe TCP port on which to read_message.
queSizeThe listener queue size.

◆ acceptor_tmpl() [4/4]

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::acceptor_tmpl ( acceptor_tmpl< STREAM_SOCK, ADDR > && acc)
inline

Move constructor. Creates an acceptor by moving the other acceptor to this one.

Parameters
accAnother acceptor

Member Function Documentation

◆ accept()

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
stream_sock_t sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::accept ( addr_t * clientAddr = nullptr)
inline

Accepts an incoming connection and gets the address of the client.

Parameters
clientAddrPointer to the variable that will get the address of a client when it connects.
Returns
A tcp_socket to the remote client.

◆ address()

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
addr_t sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::address ( ) const
inline

Gets the local address to which we are bound.

Returns
The local address to which we are bound.

◆ bind()

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
bool sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::bind ( const addr_t & addr)
inline

Binds the socket to the specified address.

Parameters
addrThe address to which we get bound.
Returns
true on _success, false on error

◆ create()

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
static acceptor_tmpl sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::create ( )
inlinestatic

Creates an unbound acceptor socket with an open OS socket handle. An application would need to manually bind and read_message to this acceptor to get incoming connections.

Returns
An open, but unbound acceptor socket.

◆ open() [1/2]

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
bool sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::open ( const addr_t & addr,
int queSize = DFLT_QUE_SIZE )
inline

Opens the acceptor socket, binds it to the specified address, and starts listening.

Parameters
addrThe address to which this server should be bound.
queSizeThe listener queue size.
Returns
true on _success, false on error

◆ open() [2/2]

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
bool sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::open ( in_port_t port,
int queSize = DFLT_QUE_SIZE )
inline

Opens the acceptor socket, binds the socket to all adapters and starts it listening.

Parameters
portThe TCP port on which to read_message.
queSizeThe listener queue size.
Returns
true on _success, false on error

◆ operator=()

template<typename STREAM_SOCK , typename ADDR = typename STREAM_SOCK::addr_t>
acceptor_tmpl & sockpp::acceptor_tmpl< STREAM_SOCK, ADDR >::operator= ( acceptor_tmpl< STREAM_SOCK, ADDR > && rhs)
inline

Move assignment.

Parameters
rhsThe other socket to move into this one.
Returns
A reference to this object.

The documentation for this class was generated from the following file: