oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ove::TcpListener Class Reference

RAII wrapper around an oveRTOS TCP listening socket. More...

#include <net.hpp>

Public Member Functions

 TcpListener ()
 Opens a new TCP socket for listening.
 
 ~TcpListener () noexcept
 Closes the listening socket if it is still open.
 
 TcpListener (const TcpListener &)=delete
 
TcpListeneroperator= (const TcpListener &)=delete
 
 TcpListener (TcpListener &&other) noexcept
 Move constructor — transfers ownership of the socket.
 
TcpListeneroperator= (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TcpListener() [1/2]

ove::TcpListener::TcpListener ( )
inline

Opens a new TCP socket for listening.

Asserts at startup if socket creation fails.

◆ TcpListener() [2/2]

ove::TcpListener::TcpListener ( TcpListener &&  other)
inlinenoexcept

Move constructor — transfers ownership of the socket.

Parameters
otherThe source; left in a closed, null state after the move.

Member Function Documentation

◆ operator=()

TcpListener & ove::TcpListener::operator= ( TcpListener &&  other)
inlinenoexcept

Move-assignment operator — transfers ownership of the socket.

Parameters
otherThe source; left in a closed, null state after the move.
Returns
Reference to this object.

◆ bind()

Result< void > ove::TcpListener::bind ( const Address addr)
inlinenoexcept

Binds the socket to a local address.

Parameters
[in]addrLocal 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]backlogMaximum pending connection queue length.
Returns
Empty Result<void> on success; unexpected with the appropriate Error on failure.

◆ accept()

Result< void > ove::TcpListener::accept ( TcpSocket client,
std::chrono::nanoseconds  timeout = wait_forever 
)
inlinenoexcept

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]clientReceives the accepted connection.
[in]timeoutAccept 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: