RAII wrapper around an oveRTOS TCP listening socket.
More...
#include <net.hpp>
|
| | TcpListener () |
| | Opens a new TCP socket for listening.
|
| |
|
| ~TcpListener () noexcept |
| | Closes the listening socket if it is still open.
|
| |
|
| TcpListener (const TcpListener &)=delete |
| |
|
TcpListener & | operator= (const TcpListener &)=delete |
| |
| | TcpListener (TcpListener &&other) noexcept |
| | Move constructor — transfers ownership of the socket.
|
| |
| TcpListener & | operator= (TcpListener &&other) noexcept |
| | Move-assignment operator — transfers ownership of the socket.
|
| |
| Result< void > | bind (const Address &addr) noexcept |
| | Binds the socket to a local address.
|
| |
| Result< void > | listen (int backlog=4) noexcept |
| | Marks the socket as listening for incoming connections.
|
| |
| Result< void > | accept (TcpSocket &client, std::chrono::nanoseconds timeout=wait_forever) noexcept |
| | Accepts an incoming connection.
|
| |
| void | close () |
| | Closes the listening socket.
|
| |
| bool | is_open () const |
| | Returns true if the listening socket is open.
|
| |
| ove_socket_t | handle () const |
| | Returns the raw oveRTOS socket handle.
|
| |
RAII wrapper around an oveRTOS TCP listening socket.
Opens a stream socket on construction, then bind() + listen() to begin accepting connections. accept() returns a TcpSocket that owns the accepted connection.
- Note
- Non-copyable. Move-only when heap allocation is enabled.
◆ TcpListener() [1/2]
| ove::TcpListener::TcpListener |
( |
| ) |
|
|
inline |
Opens a new TCP socket for listening.
Asserts at startup if socket creation fails.
◆ TcpListener() [2/2]
Move constructor — transfers ownership of the socket.
- Parameters
-
| other | The source; left in a closed, null state after the move. |
◆ operator=()
Move-assignment operator — transfers ownership of the socket.
- Parameters
-
| other | The source; left in a closed, null state after the move. |
- Returns
- Reference to this object.
◆ bind()
Binds the socket to a local address.
- Parameters
-
| [in] | addr | Local address to bind. |
- Returns
- Empty
Result<void> on success; unexpected with the appropriate Error on failure (Error::NetAddrInUse, …).
◆ listen()
| Result< void > ove::TcpListener::listen |
( |
int |
backlog = 4 | ) |
|
|
inlinenoexcept |
Marks the socket as listening for incoming connections.
- Parameters
-
| [in] | backlog | Maximum pending connection queue length. |
- Returns
- Empty
Result<void> on success; unexpected with the appropriate Error on failure.
◆ accept()
Accepts an incoming connection.
The accepted socket is written into client by reference (rather than returned via Result<TcpSocket>) because TcpSocket is non-movable in CONFIG_OVE_ZERO_HEAP mode — returning one by value would not compile there. On success client owns the accepted connection; on failure it is left in a closed state.
- Parameters
-
| [out] | client | Receives the accepted connection. |
| [in] | timeout | Accept timeout (any std::chrono::duration unit; defaults to wait_forever). |
- Returns
- Empty
Result<void> on success; unexpected Error on failure (typically Error::Timeout or Error::NetClosed).
◆ close()
| void ove::TcpListener::close |
( |
| ) |
|
|
inline |
Closes the listening socket.
Idempotent. Safe to call on an already-closed listener — the call is silently a no-op in that case. The destructor calls this as part of cleanup, so explicit close() is only needed when you want to release the listening socket before the TcpListener goes out of scope.
Effect on pending I/O. A thread blocked on accept against this listener will unblock with a backend-specific error code — typically OVE_ERR_NET_CLOSED. Already-accepted TcpSocket instances are independent file descriptors and are not affected; they continue to operate normally until closed individually.
Thread-safety. Not safe to call concurrently with another close() on the same listener, nor concurrently with accept on a thread that does not expect the listener to disappear. Coordinate teardown via the usual signal-then-close pattern.
◆ is_open()
| bool ove::TcpListener::is_open |
( |
| ) |
const |
|
inline |
Returns true if the listening socket is open.
- Returns
- Socket open state.
◆ handle()
| ove_socket_t ove::TcpListener::handle |
( |
| ) |
const |
|
inline |
Returns the raw oveRTOS socket handle.
- Returns
- The opaque
ove_socket_t handle.
The documentation for this class was generated from the following file: