io
C++ I/O scheduling library with asynchronous socket operations
|
A platform-independent representation of a socket address. More...
#include <socket/socket_address.hpp>
Public Member Functions | |
socket_address ()=default | |
Constructs an empty socket address. | |
socket_address (const socket_address &other)=default | |
Default copy constructor. | |
socket_address (socket_address &&other) noexcept=default | |
Default move constructor. | |
auto | operator= (const socket_address &other) -> socket_address &=default |
Default copy assignment operator. | |
auto | operator= (socket_address &&other) noexcept -> socket_address &=default |
Default move assignment operator. | |
socket_address (socklen_type size) noexcept | |
Constructs a socket address with a specific size. | |
socket_address (const sockaddr_type *addr, socklen_type size) noexcept | |
Constructs a socket_address from a native socket address structure. | |
auto | data () noexcept -> sockaddr_type * |
Returns a mutable pointer to the underlying socket address data. | |
auto | data () const noexcept -> const sockaddr_type * |
Returns a constant pointer to the underlying socket address data. | |
auto | size () noexcept -> socklen_type * |
Returns a mutable pointer to the size of the socket address. | |
auto | size () const noexcept -> const socklen_type * |
Returns a constant pointer to the size of the socket address. | |
auto | operator== (const socket_address &other) const noexcept -> bool |
Compares two socket_address objects for equality. | |
~socket_address ()=default | |
Default destructor. | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<typename SockAddr > | |
auto | make_address (const SockAddr *addr=nullptr) noexcept -> socket_address |
Creates a socket_address object, optionally initialized from a native address. | |
A platform-independent representation of a socket address.
This class provides a wrapper around the native socket address structures, offering a safe and convenient way to manage address information for socket operations. It uses sockaddr_storage_type
to ensure sufficient space for any address family and socklen_type
for the address size, which are platform-specific aliases.
Definition at line 42 of file socket_address.hpp.
|
default |
Constructs an empty socket address.
The internal storage is zero-initialized, and the size is set to the full capacity of the address storage. This prepares the object to be populated by functions that require a buffer for the address, such as accept()
or recvfrom()
.
|
explicitnoexcept |
Constructs a socket address with a specific size.
This constructor initializes the socket address to be ready to hold a socket address of the specified size. The internal storage is zero-initialized, and the size is set to the provided value. This is useful when you know the exact size needed for a particular address family.
size | The size in bytes for the socket address structure. |
Definition at line 23 of file socket_address.cpp.
|
explicitnoexcept |
Constructs a socket_address
from a native socket address structure.
This constructor copies the provided native socket address data into its internal storage, making it suitable for passing to socket functions that require an address, such as connect()
or bind()
.
addr | A pointer to the native socket address (e.g., sockaddr_in ). The data pointed to is copied into the object. |
size | The size of the address structure in bytes. |
Definition at line 27 of file socket_address.cpp.
|
noexcept |
Returns a constant pointer to the underlying socket address data.
This provides read-only access to the address data, suitable for passing to functions like connect()
or bind()
that do not modify the address. The lifetime of the returned pointer is tied to this socket_address
object.
sockaddr_type
data. Definition at line 41 of file socket_address.cpp.
|
noexcept |
Returns a mutable pointer to the underlying socket address data.
This allows the raw address data to be modified by functions like accept()
or getpeername()
that populate a socket address structure provided by the caller. The lifetime of the returned pointer is tied to this socket_address
object.
sockaddr_type
data. Definition at line 36 of file socket_address.cpp.
|
noexcept |
Compares two socket_address
objects for equality.
Two addresses are considered equal if they have the same size and their underlying address data is bit-for-bit identical.
other | The socket_address to compare against. |
true
if the addresses are equal, false
otherwise. Definition at line 52 of file socket_address.cpp.
|
noexcept |
Returns a constant pointer to the size of the socket address.
This provides read-only access to the size, suitable for functions that only need to know the size of the address being passed. The lifetime of the returned pointer is tied to this socket_address
object.
socklen_type
size. Definition at line 48 of file socket_address.cpp.
|
noexcept |
Returns a mutable pointer to the size of the socket address.
This allows the size to be modified by functions like accept()
or getpeername()
that update the size argument to reflect the actual size of the returned address. The lifetime of the returned pointer is tied to this socket_address
object.
socklen_type
size. Definition at line 46 of file socket_address.cpp.
|
related |
Creates a socket_address
object, optionally initialized from a native address.
This function is a helper to construct a socket_address
instance. If addr
is provided, the socket_address
is initialized with the given native address and its size. Otherwise, it creates a socket_address
with an appropriate size for SockAddr
but without initial address data. It performs a compile-time assertion to guarantee that SockAddr
can fit within sockaddr_storage_type
.
SockAddr | The native socket address structure type (e.g., sockaddr_in , sockaddr_in6 ). |
addr | An optional pointer to a native socket address structure to initialize from. If nullptr , an empty socket_address of the appropriate size is created. |
socket_address
object, either initialized from addr
or with the size of SockAddr
. Definition at line 180 of file socket_address.hpp.