sockpp
Modern C++ socket library wrapper
Public Member Functions | List of all members
sockpp::unix_acceptor Class Reference

Class for creating a Unix-domain server. More...

#include <unix_acceptor.h>

Inheritance diagram for sockpp::unix_acceptor:
sockpp::acceptor sockpp::socket

Public Member Functions

 unix_acceptor ()
 Creates an unconnected acceptor.
 
 unix_acceptor (const unix_address &addr, int queSize=DFLT_QUE_SIZE)
 Creates a acceptor and starts it listening on the specified address. More...
 
unix_address address () const
 Gets the local address to which we are bound. More...
 
bool open (const unix_address &addr, int queSize=DFLT_QUE_SIZE)
 Opens the acceptor socket and binds it to the specified address. More...
 
unix_socket accept ()
 Accepts an incoming UNIX connection and gets the address of the client. More...
 
- Public Member Functions inherited from sockpp::acceptor
 acceptor ()
 Creates an unconnected acceptor.
 
 acceptor (socket_t handle)
 Creates an acceptor from an existing OS socket handle and claims ownership of the handle. More...
 
 acceptor (const sock_address &addr, int queSize=DFLT_QUE_SIZE)
 Creates an acceptor socket and starts it listening to the specified address. More...
 
 acceptor (acceptor &&acc)
 Move constructor. More...
 
acceptoroperator= (acceptor &&rhs)
 Move assignment. More...
 
bool listen (int queSize=DFLT_QUE_SIZE)
 Sets the socket listening on the address to which it is bound. More...
 
bool open (const sock_address &addr, int queSize=DFLT_QUE_SIZE, bool reuseSock=true)
 Opens the acceptor socket, binds it to the specified address, and starts listening. More...
 
stream_socket accept (sock_address *clientAddr=nullptr)
 Accepts an incoming TCP connection and gets the address of the client. More...
 
- Public Member Functions inherited from sockpp::socket
 socket ()
 Creates an unconnected (invalid) socket.
 
 socket (socket_t h)
 Creates a socket from an existing OS socket handle. More...
 
 socket (socket &&sock) noexcept
 Move constructor. More...
 
virtual ~socket ()
 Destructor closes the socket.
 
bool is_open () const
 Determines if the socket is open (valid). More...
 
bool operator! () const
 Determines if the socket is closed or in an error state. More...
 
 operator bool () const
 Determines if the socket is open and in an error-free state. More...
 
socket_t handle () const
 Get the underlying OS socket handle. More...
 
virtual sa_family_t family () const
 Gets the network family of the address to which the socket is bound. More...
 
socket clone () const
 Creates a new socket that refers to this one. More...
 
void clear (int val=0)
 Clears the error flag for the object. More...
 
socket_t release ()
 Releases ownership of the underlying socket object. More...
 
void reset (socket_t h=INVALID_SOCKET)
 Replaces the underlying managed socket object. More...
 
socketoperator= (socket &&sock) noexcept
 Move assignment. More...
 
bool bind (const sock_address &addr)
 Binds the socket to the specified address. More...
 
sock_address_any address () const
 Gets the local address to which the socket is bound. More...
 
sock_address_any peer_address () const
 Gets the address of the remote peer, if this socket is connected. More...
 
bool get_option (int level, int optname, void *optval, socklen_t *optlen) const
 Gets the value of a socket option. More...
 
template<typename T >
bool get_option (int level, int optname, T *val) const
 Gets the value of a socket option. More...
 
bool set_option (int level, int optname, const void *optval, socklen_t optlen)
 Sets the value of a socket option. More...
 
template<typename T >
bool set_option (int level, int optname, const T &val)
 Sets the value of a socket option. More...
 
bool set_non_blocking (bool on=true)
 Places the socket into or out of non-blocking mode. More...
 
int last_error () const
 Gets the code for the last errror. More...
 
std::string last_error_str () const
 Gets a string describing the last errror. More...
 
bool shutdown (int how=SHUT_RDWR)
 Shuts down all or part of the full-duplex connection. More...
 
bool close ()
 Closes the socket. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from sockpp::acceptor
static acceptor create (int domain)
 Creates an unbound acceptor socket with an open OS socket handle. More...
 
- Static Public Member Functions inherited from sockpp::socket
static void initialize ()
 Initializes the socket (sockpp) library. More...
 
static void destroy ()
 Shuts down the socket library. More...
 
static socket create (int domain, int type, int protocol=0)
 Creates a socket with the specified communications characterics. More...
 
static std::tuple< socket, socketpair (int domain, int type, int protocol=0)
 Creates a pair of connected sockets. More...
 
static std::string error_str (int errNum)
 Gets a string describing the specified error. More...
 
- Protected Member Functions inherited from sockpp::socket
bool close_on_err ()
 Closes the socket without checking for errors or updating the last error. More...
 
void set_last_error ()
 Cache the last system error code into this object. More...
 
template<typename T >
check_ret (T ret) const
 Checks the value and if less than zero, sets last error. More...
 
template<typename T >
bool check_ret_bool (T ret) const
 Checks the value and if less than zero, sets last error. More...
 
socket_t check_socket (socket_t ret) const
 Checks the value and if it is not a valid socket, sets last error. More...
 
bool check_socket_bool (socket_t ret) const
 Checks the value and if it is INVALID_SOCKET, sets last error. More...
 
- Static Protected Member Functions inherited from sockpp::acceptor
static socket_t create_handle (int domain)
 Creates an underlying acceptor socket. More...
 
- Static Protected Member Functions inherited from sockpp::socket
static int get_last_error ()
 OS-specific means to retrieve the last error from an operation. More...
 
- Static Protected Attributes inherited from sockpp::acceptor
static const int DFLT_QUE_SIZE = 4
 The default listener queue size. More...
 

Detailed Description

Class for creating a Unix-domain server.

Objects of this class bind and listen on Unix-domain ports for connections. Normally, a server thread creates one of these and blocks on the call to accept incoming connections. The call to accept creates and returns a unix_stream_socket which can then be used for the actual communications.

Constructor & Destructor Documentation

◆ unix_acceptor()

sockpp::unix_acceptor::unix_acceptor ( const unix_address 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 listen.
queSizeThe listener queue size.

Member Function Documentation

◆ accept()

unix_socket sockpp::unix_acceptor::accept ( )
inline

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

Returns
A unix_socket to the client.

◆ address()

unix_address sockpp::unix_acceptor::address ( ) const
inline

Gets the local address to which we are bound.

Returns
The local address to which we are bound.

◆ open()

bool sockpp::unix_acceptor::open ( const unix_address addr,
int  queSize = DFLT_QUE_SIZE 
)
inline

Opens the acceptor socket and binds it to the specified address.

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

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