io
C++ I/O scheduling library with asynchronous socket operations
|
A thread-safe container for socket messages used in advanced I/O operations. More...
#include <socket/socket_message.hpp>
Public Member Functions | |
socket_message () | |
Default constructor. | |
socket_message (const socket_message &other)=delete | |
Deleted copy constructor. | |
auto | operator= (const socket_message &other) -> socket_message &=delete |
Deleted copy assignment operator. | |
socket_message (socket_message &&other) noexcept | |
Move constructor. | |
auto | operator= (socket_message &&other) noexcept -> socket_message & |
Move assignment operator. | |
auto | get () const -> message_data |
Gets the underlying message_data struct. | |
auto | operator= (message_data data) -> socket_message & |
Assign message_data to socket_message. | |
auto | address () const -> socket_address |
Gets the socket address. | |
auto | set_address (socket_address address) -> socket_message & |
Sets the socket address. | |
auto | exchange_address (socket_address address) -> socket_address |
Exchanges the socket address. | |
auto | buffers () const -> scatter_gather_buffer |
Gets the data buffers. | |
auto | set_buffers (scatter_gather_buffer buffers) -> socket_message & |
Sets the data buffers. | |
auto | exchange_buffers (scatter_gather_buffer buffers) -> scatter_gather_buffer |
Exchanges the data buffers. | |
auto | push_back (socket_buffer_type buffer) -> socket_message & |
Adds a new data buffer to the end of the buffer collection. | |
template<typename... Args> | |
auto | emplace_back (Args &&...args) -> socket_message & |
Constructs a new buffer in-place at the end of the buffer collection. | |
auto | control () const -> ancillary_buffer |
Gets the ancillary data. | |
auto | set_control (ancillary_buffer control) -> socket_message & |
Sets the ancillary data. | |
auto | exchange_control (ancillary_buffer control) -> ancillary_buffer |
Exchanges the ancillary data. | |
auto | flags () const -> int |
Gets the message flags. | |
auto | set_flags (int flags) -> socket_message & |
Sets the message flags. | |
auto | exchange_flags (int flags) -> int |
Exchanges the message flags. | |
~socket_message ()=default | |
Default destructor. | |
Friends | |
auto | swap (socket_message &lhs, socket_message &rhs) noexcept -> void |
Swaps the contents of two socket_message instances. | |
A thread-safe container for socket messages used in advanced I/O operations.
The socket_message
class provides a thread-safe wrapper around the socket message data, supporting scatter-gather I/O operations with ancillary data and control information. This class is designed for use with the sendmsg()
and recvmsg()
system calls, which require complex message structures.
Key features:
socket_message
instance are thread-safe due to internal mutex protection. Multiple threads can safely access different socket_message
instances concurrently. Concurrent access to the same instance is serialized.Definition at line 110 of file socket_message.hpp.
io::socket::socket_message::socket_message | ( | ) |
Default constructor.
Creates an empty socket message with initialized internal data.
Definition at line 20 of file socket_message.cpp.
|
delete |
Deleted copy constructor.
Copying is disallowed to enforce move-only semantics and prevent resource ownership issues.
|
noexcept |
Move constructor.
Transfers ownership of the socket message data from another instance, leaving the source instance in a valid but unspecified state.
other | The socket_message to move from. |
Definition at line 22 of file socket_message.cpp.
|
default |
Default destructor.
Cleans up internal resources. The unique_ptr
ensures that the message_data
structure is properly deallocated.
auto io::socket::socket_message::address | ( | ) | const -> socket_address |
Gets the socket address.
Definition at line 55 of file socket_message.cpp.
auto io::socket::socket_message::buffers | ( | ) | const -> scatter_gather_buffer |
Gets the data buffers.
These buffers are used for vectored I/O operations that can read or write multiple non-contiguous memory regions in a single system call.
Definition at line 74 of file socket_message.cpp.
auto io::socket::socket_message::control | ( | ) | const -> ancillary_buffer |
Gets the ancillary data.
This data contains control information that can be passed alongside the main message data, such as file descriptors, credentials, or other metadata.
Definition at line 100 of file socket_message.cpp.
|
inline |
Constructs a new buffer in-place at the end of the buffer collection.
This method constructs a new socket_buffer_type
object directly in the buffer collection using the provided arguments, avoiding unnecessary copies or moves. This is more efficient than push_back
when the buffer can be constructed from the arguments directly.
Args | The types of arguments to forward to the buffer constructor. |
args | The arguments to forward to construct the new buffer. |
socket_message
for method chaining.Definition at line 265 of file socket_message.hpp.
auto io::socket::socket_message::exchange_address | ( | socket_address | address | ) | -> socket_address |
Exchanges the socket address.
address | The socket address to set. |
Definition at line 66 of file socket_message.cpp.
auto io::socket::socket_message::exchange_buffers | ( | scatter_gather_buffer | buffers | ) | -> scatter_gather_buffer |
Exchanges the data buffers.
The provided buffers are moved into the message, transferring ownership. The previous buffers are returned to the caller.
buffers | The buffer collection to set (will be moved). |
Definition at line 86 of file socket_message.cpp.
auto io::socket::socket_message::exchange_control | ( | ancillary_buffer | control | ) | -> ancillary_buffer |
Exchanges the ancillary data.
The provided control data is moved into the message, transferring ownership. The previous control data is returned to the caller.
control | The ancillary data to set (will be moved). |
Definition at line 111 of file socket_message.cpp.
auto io::socket::socket_message::exchange_flags | ( | int | flags | ) | -> int |
Exchanges the message flags.
The provided flags are set in the message, replacing the current flags. The previous flags are returned to the caller.
flags | The message flags to set. |
Definition at line 130 of file socket_message.cpp.
auto io::socket::socket_message::flags | ( | ) | const -> int |
Gets the message flags.
These flags control the behavior of socket operations and correspond to the flags parameter used with the sendmsg()
and recvmsg()
system calls.
Definition at line 119 of file socket_message.cpp.
auto io::socket::socket_message::get | ( | ) | const -> message_data |
Gets the underlying message_data
struct.
Definition at line 43 of file socket_message.cpp.
|
delete |
Deleted copy assignment operator.
Copying is disallowed to enforce move-only semantics and prevent resource ownership issues.
auto io::socket::socket_message::operator= | ( | message_data | data | ) | -> socket_message & |
Assign message_data
to socket_message.
Definition at line 49 of file socket_message.cpp.
|
noexcept |
Move assignment operator.
Transfers ownership of the socket message data from another instance, leaving the source instance in a valid but unspecified state.
other | The socket_message to move from. |
Definition at line 27 of file socket_message.cpp.
auto io::socket::socket_message::push_back | ( | socket_buffer_type | buffer | ) | -> socket_message & |
Adds a new data buffer to the end of the buffer collection.
This method appends the provided buffer to the end of the scatter-gather buffer collection. The operation is thread-safe and the buffer is copied into the collection.
buffer | The buffer to add to the collection. |
socket_message
for method chaining.Definition at line 94 of file socket_message.cpp.
auto io::socket::socket_message::set_address | ( | socket_address | address | ) | -> socket_message & |
Sets the socket address.
address | The socket address to set. |
socket_message
for method chaining. Definition at line 60 of file socket_message.cpp.
auto io::socket::socket_message::set_buffers | ( | scatter_gather_buffer | buffers | ) | -> socket_message & |
Sets the data buffers.
The provided buffers are moved into the message, transferring ownership.
buffers | The buffer collection to set (will be moved). |
socket_message
for method chaining. Definition at line 79 of file socket_message.cpp.
auto io::socket::socket_message::set_control | ( | ancillary_buffer | control | ) | -> socket_message & |
Sets the ancillary data.
The provided data is moved into the message, transferring ownership.
control | The ancillary data to set (will be moved). |
socket_message
for method chaining. Definition at line 105 of file socket_message.cpp.
auto io::socket::socket_message::set_flags | ( | int | flags | ) | -> socket_message & |
Sets the message flags.
These flags control the behavior of socket operations and correspond to the flags parameter used with the sendmsg()
and recvmsg()
system calls (e.g., MSG_DONTWAIT
, MSG_PEEK
, MSG_TRUNC
).
flags | The message flags to set. |
socket_message
for method chaining. Definition at line 124 of file socket_message.cpp.
|
friend |
Swaps the contents of two socket_message
instances.
This function atomically swaps the contents of two socket_message
instances using a dual-mutex lock to prevent deadlocks.
lhs | The first socket_message instance. |
rhs | The second socket_message instance. |
std::scoped_lock
to prevent deadlocks when locking multiple mutexes. Definition at line 33 of file socket_message.cpp.