qb
2.0.0.0
C++17 Actor Framework
|
Class implementing a TCP listener for accepting incoming connections. More...
#include <listener.h>
Public Member Functions | |
int | listen (io::endpoint const &ep) noexcept |
Start listening on a specific local endpoint. | |
int | listen (io::uri const &uri) noexcept |
Start listening on an endpoint specified by a URI. | |
int | listen_v4 (uint16_t port, std::string const &host="0.0.0.0") noexcept |
Start listening on a specific IPv4 address and port. | |
int | listen_v6 (uint16_t port, std::string const &host="::") noexcept |
Start listening on a specific IPv6 address and port. | |
int | listen_un (std::string const &path) noexcept |
Start listening on a Unix domain socket. | |
tcp::socket | accept () const noexcept |
Accept a new incoming TCP connection and return it as a new tcp::socket. | |
int | accept (tcp::socket &sock) const noexcept |
Accept a new incoming TCP connection into an existing tcp::socket object. | |
int | disconnect () const noexcept |
Disconnect the listener socket, stopping it from accepting new connections. |
Static Public Member Functions | |
static constexpr bool | is_secure () noexcept |
Indicates that this socket implementation is not secure. |
Class implementing a TCP listener for accepting incoming connections.
This class provides functionality for listening for incoming TCP connections. It inherits protectedly from the base qb::io::socket class and provides methods for binding to a local address, listening for connections, and accepting them. It supports IPv4, IPv6, and Unix Domain Sockets (if enabled).
|
noexcept |
Start listening on a specific local endpoint.
ep | The qb::io::endpoint specifying the local IP address and port to listen on. |
This method first opens a socket with the address family of the endpoint, then binds to the endpoint and starts listening for incoming connections. Default backlog is SOMAXCONN.
|
noexcept |
Start listening on an endpoint specified by a URI.
uri | The qb::io::uri specifying the scheme (e.g., "tcp", "unix"), address, and port. |
Parses the URI to determine the address and port, then calls the appropriate listen_v4, listen_v6, or listen_un method.
|
noexcept |
Start listening on a specific IPv4 address and port.
port | The port number to listen on. |
host | The IPv4 host address string (e.g., "0.0.0.0" for all interfaces, or a specific IP). Defaults to "0.0.0.0". |
|
noexcept |
Start listening on a specific IPv6 address and port.
port | The port number to listen on. |
host | The IPv6 host address string (e.g., "::" for all interfaces, or a specific IP). Defaults to "::". |
|
noexcept |
Start listening on a Unix domain socket.
path | The file system path for the Unix domain socket. |
|
noexcept |
Accept a new incoming TCP connection and return it as a new tcp::socket.
This is a blocking call by default if the listener socket is blocking. For non-blocking accept, the listener socket should be set to non-blocking, and this method would typically be called when select or an event loop indicates readability.
|
noexcept |
Accept a new incoming TCP connection into an existing tcp::socket object.
sock | A reference to a tcp::socket object where the new connection will be placed. If a connection is accepted, sock will wrap the new client socket descriptor. |
Similar to the other accept() method, but uses a pre-existing socket object.
|
noexcept |
Disconnect the listener socket, stopping it from accepting new connections.
This typically calls qb::io::socket::shutdown() and close() on the underlying listener socket.