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

RAII wrapper for a Boost.Asio netlink socket. More...

#include <nl_socket.hxx>

Public Types

using socket_t = Protocol::socket
using endpoint_t = Protocol::endpoint
using native_t = typename socket_t::native_handle_type

Public Member Functions

 Socket (boost::asio::io_context &io, std::string_view label) noexcept
 Construct a netlink Socket with an io_context and label.
 ~Socket () noexcept
 Destroy the Socket object and ensure underlying socket is closed.
 Socket (const Socket &)=delete
Socketoperator= (const Socket &)=delete
 Socket (Socket &&) noexcept=default
Socketoperator= (Socket &&) noexcept=default
auto is_open () const noexcept -> bool
 Check whether the socket is currently open.
auto close () -> std::expected< void, std::error_code >
 Close the underlying socket.
auto cancel () -> std::expected< void, std::error_code >
 Cancel any asynchronous operations on the socket.
auto open (int proto, uint32_t groups) -> std::expected< void, std::error_code >
 Open and configure the netlink socket.
template<typename Option>
void set_option (const Option &option, boost::system::error_code &ec)
template<typename Endpoint>
void bind (const Endpoint &endpoint, boost::system::error_code &ec)
template<typename Endpoint>
void connect (const Endpoint &endpoint, boost::system::error_code &ec)
template<typename MutableBufferSequence, typename CompletionToken>
auto async_receive (const MutableBufferSequence &buffers, CompletionToken &&token) -> decltype(std::declval< socket_t >().async_receive(buffers, std::forward< CompletionToken >(token)))
template<typename MutableBufferSequence>
auto receive (const MutableBufferSequence &buffers, boost::system::error_code &ec) -> size_t
template<typename ConstBufferSequence, typename CompletionToken>
auto async_send (const ConstBufferSequence &buffers, CompletionToken &&token) -> decltype(std::declval< socket_t >() .async_send(buffers, std::forward< CompletionToken >(token)))
template<typename ConstBufferSequence>
auto send (const ConstBufferSequence &buffers, boost::system::error_code &ec) -> size_t
auto native_handle () -> native_t
 Get the native socket handle.

Private Types

using ext_ack_option
using strict_chk_option
using recv_buf_option
using no_enobufs_option

Private Attributes

socket_t socket_
std::string label_

Detailed Description

RAII wrapper for a Boost.Asio netlink socket.

Encapsulates socket creation, option configuration, bind, and teardown for Netlink protocol sockets used by rtaco.

Member Typedef Documentation

◆ endpoint_t

◆ ext_ack_option

Initial value:
boost::asio::detail::socket_option::integer<SOL_NETLINK, NETLINK_EXT_ACK>

◆ native_t

using llmx::rtaco::Socket::native_t = typename socket_t::native_handle_type

◆ no_enobufs_option

Initial value:
boost::asio::detail::socket_option::integer<SOL_NETLINK, NETLINK_NO_ENOBUFS>

◆ recv_buf_option

Initial value:
boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVBUF>

◆ socket_t

◆ strict_chk_option

Initial value:
boost::asio::detail::socket_option::integer<SOL_NETLINK,
NETLINK_GET_STRICT_CHK>

Constructor & Destructor Documentation

◆ Socket() [1/3]

llmx::rtaco::Socket::Socket ( boost::asio::io_context & io,
std::string_view label )
explicitnoexcept

Construct a netlink Socket with an io_context and label.

◆ ~Socket()

llmx::rtaco::Socket::~Socket ( )
noexcept

Destroy the Socket object and ensure underlying socket is closed.

◆ Socket() [2/3]

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

◆ Socket() [3/3]

llmx::rtaco::Socket::Socket ( Socket && )
defaultnoexcept

Member Function Documentation

◆ async_receive()

template<typename MutableBufferSequence, typename CompletionToken>
auto llmx::rtaco::Socket::async_receive ( const MutableBufferSequence & buffers,
CompletionToken && token ) -> decltype(std::declval< socket_t >().async_receive(buffers, std::forward< CompletionToken >(token)))
inline

◆ async_send()

template<typename ConstBufferSequence, typename CompletionToken>
auto llmx::rtaco::Socket::async_send ( const ConstBufferSequence & buffers,
CompletionToken && token ) -> decltype(std::declval< socket_t >() .async_send(buffers, std::forward< CompletionToken >(token)))
inline

◆ bind()

template<typename Endpoint>
void llmx::rtaco::Socket::bind ( const Endpoint & endpoint,
boost::system::error_code & ec )
inline

◆ cancel()

auto llmx::rtaco::Socket::cancel ( ) -> std::expected< void, std::error_code >

Cancel any asynchronous operations on the socket.

Returns
std::expected<void, std::error_code> Empty on success or contains the encountered error on failure.

◆ close()

auto llmx::rtaco::Socket::close ( ) -> std::expected< void, std::error_code >

Close the underlying socket.

Returns
std::expected<void, std::error_code> Empty on success or contains the encountered error on failure.

◆ connect()

template<typename Endpoint>
void llmx::rtaco::Socket::connect ( const Endpoint & endpoint,
boost::system::error_code & ec )
inline

◆ is_open()

auto llmx::rtaco::Socket::is_open ( ) const -> bool
noexcept

Check whether the socket is currently open.

Returns
true if the underlying Boost.Asio socket is open.

◆ native_handle()

auto llmx::rtaco::Socket::native_handle ( ) -> native_t

Get the native socket handle.

Returns
native_t The underlying native socket handle (file descriptor).

◆ open()

auto llmx::rtaco::Socket::open ( int proto,
uint32_t groups ) -> std::expected< void, std::error_code >

Open and configure the netlink socket.

Opens the socket for the given netlink protocol and subscribes to the provided multicast groups. Configures recommended socket options and binds the socket.

Exceptions
std::runtime_erroron fatal failures when opening or binding fails.
Returns
std::expected<void, std::error_code> Empty on success or contains the encountered error from socket option configuration.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Socket & llmx::rtaco::Socket::operator= ( Socket && )
defaultnoexcept

◆ receive()

template<typename MutableBufferSequence>
auto llmx::rtaco::Socket::receive ( const MutableBufferSequence & buffers,
boost::system::error_code & ec ) -> size_t
inline

◆ send()

template<typename ConstBufferSequence>
auto llmx::rtaco::Socket::send ( const ConstBufferSequence & buffers,
boost::system::error_code & ec ) -> size_t
inline

◆ set_option()

template<typename Option>
void llmx::rtaco::Socket::set_option ( const Option & option,
boost::system::error_code & ec )
inline

Member Data Documentation

◆ label_

std::string llmx::rtaco::Socket::label_
private

◆ socket_

socket_t llmx::rtaco::Socket::socket_
private

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