AsyncBerkeley
Asynchronous Berkeley sockets. Simple.
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
io::socket::socket_handle Class Reference

A thread-safe, move-only RAII wrapper for a native socket handle. More...

#include <io/socket/socket_handle.hpp>

Public Member Functions

 socket_handle ()=default
 Initializes an invalid socket handle.
 
 socket_handle (const socket_handle &other)=delete
 
auto operator= (const socket_handle &other) -> socket_handle &=delete
 
 socket_handle (socket_handle &&other) noexcept
 Move constructor.
 
auto operator= (socket_handle &&other) noexcept -> socket_handle &
 Move assignment.
 
 socket_handle (native_socket_type handle)
 Constructs from a native socket handle.
 
 socket_handle (int domain, int type, int protocol)
 Constructs a new socket.
 
 operator native_socket_type () const noexcept
 Gets the underlying native socket handle.
 
 operator bool () const noexcept
 Checks if the socket handle is valid.
 
auto operator<=> (const socket_handle &other) const noexcept -> std::strong_ordering
 Compares two socket_handle objects.
 
auto operator== (const socket_handle &other) const noexcept -> bool
 Checks for equality between two socket_handle objects.
 
auto operator<=> (native_socket_type other) const noexcept -> std::strong_ordering
 Compares with a native socket handle.
 
auto operator== (native_socket_type other) const noexcept -> bool
 Checks for equality with a native socket handle.
 
auto set_error (int error) noexcept -> void
 Sets a socket error.
 
auto get_error () const noexcept -> std::error_code
 Gets the last socket error.
 
 ~socket_handle ()
 Closes the managed socket.
 

Friends

auto swap (socket_handle &lhs, socket_handle &rhs) noexcept -> void
 Swaps two socket_handle objects.
 

Detailed Description

A thread-safe, move-only RAII wrapper for a native socket handle.

Ensures unique ownership and automatic closing of a native socket handle.

Constructor & Destructor Documentation

◆ socket_handle() [1/3]

io::socket::socket_handle::socket_handle ( socket_handle &&  other)
noexcept

Move constructor.

Parameters
otherThe socket_handle to move from. other becomes invalid.

◆ socket_handle() [2/3]

io::socket::socket_handle::socket_handle ( native_socket_type  handle)
explicit

Constructs from a native socket handle.

Parameters
handleThe native socket handle to wrap.
Exceptions
std::system_erroron invalid handle.

◆ socket_handle() [3/3]

io::socket::socket_handle::socket_handle ( int  domain,
int  type,
int  protocol 
)
explicit

Constructs a new socket.

Parameters
domainThe communication domain (e.g., AF_INET).
typeThe socket type (e.g., SOCK_STREAM).
protocolThe protocol (e.g., IPPROTO_TCP).
Exceptions
std::system_erroron failure.

Member Function Documentation

◆ operator=()

auto io::socket::socket_handle::operator= ( socket_handle &&  other) -> socket_handle &
noexcept

Move assignment.

Parameters
otherThe socket_handle to move from. other becomes invalid.
Returns
A reference to this socket_handle.

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