llmx-rtaco 0.0.1
RTNL-only netlink control-plane library for Linux (C++23).
Loading...
Searching...
No Matches
llmx::rtaco::SocketGuard Class Reference

Thread-safe guard owning a labeled Socket. More...

#include <nl_socket_guard.hxx>

Public Member Functions

 SocketGuard (boost::asio::io_context &io, std::string_view label) noexcept
 Construct a SocketGuard holding a labeled Socket.
 SocketGuard (boost::asio::io_context &io, std::string_view label, uint32_t group_mask) noexcept
 Construct a SocketGuard with a custom netlink group mask.
 SocketGuard (const SocketGuard &)=delete
SocketGuardoperator= (const SocketGuard &)=delete
 SocketGuard (SocketGuard &&)=delete
SocketGuardoperator= (SocketGuard &&)=delete
auto socket () -> Socket &
 Access the underlying Socket instance.
auto ensure_open () -> std::expected< void, std::error_code >
 Ensure the underlying socket is open, opening it if necessary.
void stop ()
 Stop and close the guarded socket.

Private Attributes

Socket socket_
uint32_t group_mask_

Detailed Description

Thread-safe guard owning a labeled Socket.

SocketGuard provides synchronized access to an underlying Socket and ensures the socket is opened on demand. It offers convenience methods to ensure the socket is open or to stop/close it. Thread safety should be achieved via external mutex.

Constructor & Destructor Documentation

◆ SocketGuard() [1/4]

llmx::rtaco::SocketGuard::SocketGuard ( boost::asio::io_context & io,
std::string_view label )
noexcept

Construct a SocketGuard holding a labeled Socket.

◆ SocketGuard() [2/4]

llmx::rtaco::SocketGuard::SocketGuard ( boost::asio::io_context & io,
std::string_view label,
uint32_t group_mask )
noexcept

Construct a SocketGuard with a custom netlink group mask.

◆ SocketGuard() [3/4]

llmx::rtaco::SocketGuard::SocketGuard ( const SocketGuard & )
delete

◆ SocketGuard() [4/4]

llmx::rtaco::SocketGuard::SocketGuard ( SocketGuard && )
delete

Member Function Documentation

◆ ensure_open()

auto llmx::rtaco::SocketGuard::ensure_open ( ) -> std::expected< void, std::error_code >

Ensure the underlying socket is open, opening it if necessary.

Returns
Expected void or an error_code on failure.

◆ operator=() [1/2]

SocketGuard & llmx::rtaco::SocketGuard::operator= ( const SocketGuard & )
delete

◆ operator=() [2/2]

SocketGuard & llmx::rtaco::SocketGuard::operator= ( SocketGuard && )
delete

◆ socket()

auto llmx::rtaco::SocketGuard::socket ( ) -> Socket &

Access the underlying Socket instance.

◆ stop()

void llmx::rtaco::SocketGuard::stop ( )

Stop and close the guarded socket.

Member Data Documentation

◆ group_mask_

uint32_t llmx::rtaco::SocketGuard::group_mask_
private

◆ socket_

Socket llmx::rtaco::SocketGuard::socket_
private

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