|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
A TCP listening socket. More...
Classes | |
| struct | accepted_connection |
Result of accept_with_peer / try_accept_with_peer — a newly accepted connection together with the peer's endpoint. More... | |
| struct | config |
| Listener configuration. More... | |
Public Member Functions | |
| listener (const endpoint &bind_addr) | |
| Creates and listens on a TCP listener at the given address. | |
| listener (const endpoint &bind_addr, const config &cfg) | |
| Creates and listens on a TCP listener with the given configuration. | |
| listener (port_number port) | |
| Creates a TCP listener bound to all local interfaces on the given port. | |
| listener (port_number port, const config &cfg) | |
| Creates a TCP listener bound to all local interfaces on the given port. | |
| stream_socket | accept () |
| Accepts a single incoming connection. | |
| accepted_connection | accept_with_peer () |
| Accepts a single incoming connection and returns the peer's endpoint. | |
| template<typename Rep , typename Period > | |
| stream_socket | accept_for (const std::chrono::duration< Rep, Period > &timeout) |
| Accepts a single connection within the given timeout. | |
| result< stream_socket > | try_accept () |
| Accepts a single incoming connection. | |
| result< accepted_connection > | try_accept_with_peer () |
| Accepts a single incoming connection and returns the peer's endpoint. | |
| template<typename Rep , typename Period > | |
| result< stream_socket > | try_accept_for (const std::chrono::duration< Rep, Period > &timeout) |
| Accepts a single connection within the given timeout. | |
Static Public Member Functions | |
| static result< listener > | make (const endpoint &bind_addr) |
| Creates and listens on a TCP listener at the given address. | |
| static result< listener > | make (const endpoint &bind_addr, const config &cfg) |
| Creates and listens on a TCP listener with the given configuration. | |
| static result< listener > | make (port_number port) |
| Creates a TCP listener bound to all local interfaces on the given port. | |
| static result< listener > | make (port_number port, const config &cfg) |
| Creates a TCP listener bound to all local interfaces on the given port. | |
Static Public Attributes | |
| static constexpr int | default_backlog = 5 |
| Default depth of the pending-connection queue. | |
A TCP listening socket.
A listener binds to a local address, listens, and produces connected stream_socket instances on accept. accept() may be called repeatedly.
Ownership is exclusive: the listener is non-copyable and move-only. A moved-from listener may only be destroyed, move-assigned, or queried via is_open() (→ false) and idf_handle() (→ -1); calling any other method on it is undefined behavior. The destructor closes the listener if open.
Definition at line 50 of file listener.hpp.
Creates and listens on a TCP listener at the given address.
| bind_addr | Local endpoint to bind and listen on. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Creates and listens on a TCP listener with the given configuration.
Address family in cfg is overridden by the family of bind_addr.
| bind_addr | Local endpoint to bind and listen on. |
| cfg | Listener configuration. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
|
explicit |
Creates a TCP listener bound to all local interfaces on the given port.
Picks the most permissive address family available at compile time: when CONFIG_LWIP_IPV6 is enabled, binds to ipv6_addr::any() and (with the default ipv6_only = false) accepts both IPv6 and IPv4-mapped clients; otherwise binds to ipv4_addr::any(). To force a specific family, use the (port, config) overload with cfg.family.
| port | Local port to listen on. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
|
explicit |
Creates a TCP listener bound to all local interfaces on the given port.
The address family in cfg selects between ipv4_addr::any() (default) and ipv6_addr::any().
| port | Local port to listen on. |
| cfg | Listener configuration. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
|
inline |
Accepts a single incoming connection.
Blocks until a client connects.
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 202 of file listener.hpp.
References idfxx::unwrap().
|
inline |
Accepts a single connection within the given timeout.
| timeout | Maximum time to wait. Sub-millisecond resolutions are rounded up. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | if the timeout fires or on other failure. |
Definition at line 225 of file listener.hpp.
References idfxx::timeout, and idfxx::unwrap().
|
inline |
Accepts a single incoming connection and returns the peer's endpoint.
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Definition at line 212 of file listener.hpp.
References idfxx::unwrap().
Creates and listens on a TCP listener at the given address.
| bind_addr | Local endpoint to bind and listen on. |
|
static |
Creates and listens on a TCP listener with the given configuration.
| bind_addr | Local endpoint to bind and listen on. |
| cfg | Listener configuration. |
|
static |
Creates a TCP listener bound to all local interfaces on the given port.
| port | Local port to listen on. |
|
static |
Creates a TCP listener bound to all local interfaces on the given port.
| port | Local port to listen on. |
| cfg | Listener configuration. |
| result< stream_socket > idfxx::net::listener::try_accept | ( | ) |
Accepts a single incoming connection.
|
inline |
Accepts a single connection within the given timeout.
| timeout | Maximum time to wait. Sub-millisecond resolutions are rounded up. |
errc::timed_out. Definition at line 251 of file listener.hpp.
References idfxx::timeout.
| result< accepted_connection > idfxx::net::listener::try_accept_with_peer | ( | ) |
Accepts a single incoming connection and returns the peer's endpoint.
Default depth of the pending-connection queue.
Definition at line 67 of file listener.hpp.