Net++
A class-based C++ encapsulation over the POSIX Sockets API
Loading...
Searching...
No Matches
tcp::Acceptor Class Reference

Accepts connections and assigns a dedicated TCPConnection object. More...

#include <tcp.hpp>

Public Member Functions

 Acceptor (std::string port, int32_t domain)
 Constructor for the Acceptor object.
 
 ~Acceptor ()
 Destructor of the Acceptor object.
 
 Acceptor (Acceptor &&other) noexcept
 Copy constructor for the Acceptor object.
 
Acceptoroperator= (Acceptor &&other) noexcept
 Copy operator for the Acceptor object.
 
void bind () const
 Binds the socket handle to the host machine's address.
 
void listen () const
 Starts listening on the socket for incoming connections.
 
Connection::connection_ptr accept () const
 Accepts incoming connections synchronously.
 

Detailed Description

Accepts connections and assigns a dedicated TCPConnection object.

Encapsulates a listening socket

Constructor & Destructor Documentation

◆ Acceptor() [1/2]

tcp::Acceptor::Acceptor ( std::string  port,
int32_t  domain 
)

Constructor for the Acceptor object.

Creates a TCP connection with the capability to listen and accept connections on the given port.

Parameters
portThe port in string format

◆ ~Acceptor()

tcp::Acceptor::~Acceptor ( )

Destructor of the Acceptor object.

Closes the underlying socket handle.

◆ Acceptor() [2/2]

tcp::Acceptor::Acceptor ( Acceptor &&  other)
noexcept

Copy constructor for the Acceptor object.

Moves the underlying socket handle and port from the source object and invalidates the source object

Member Function Documentation

◆ accept()

Connection::connection_ptr tcp::Acceptor::accept ( ) const

Accepts incoming connections synchronously.

Makes a call to the POSIX accept and creates a shared pointer to a tcp::Connection object with the resulting file descriptor

Returns
A shared pointer to a tcp::Connection object whose socket handle is the file descriptor obtained from POSIX accept

◆ bind()

void tcp::Acceptor::bind ( ) const

Binds the socket handle to the host machine's address.

Handles getaddrinfo() in passive mode and makes a call to the POSIX bind. See "$ man 2 bind"

◆ listen()

void tcp::Acceptor::listen ( ) const

Starts listening on the socket for incoming connections.

◆ operator=()

Acceptor & tcp::Acceptor::operator= ( Acceptor &&  other)
noexcept

Copy operator for the Acceptor object.

Closes any open sockets, moves the socket handle and port from the source object, and invalidates the source object


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