AsyncBerkeley
Asynchronous Berkeley sockets. Simple.
Loading...
Searching...
No Matches
Functions
Sockets

Functions for I/O Operations. More...

Functions

auto io::accept (auto &&socket, std::span< std::byte > address={}) -> decltype(auto)
 Accepts an incoming connection on a listening socket.
 
auto io::bind (auto &&socket, std::span< const std::byte > address) -> decltype(auto)
 Binds a socket to a local address.
 
auto io::connect (auto &&socket, std::span< const std::byte > address) -> decltype(auto)
 Connects a socket to a remote address.
 
auto io::fcntl (auto &&socket, int cmd, auto &&...args) -> decltype(auto)
 Performs a file control operation on a socket.
 
auto io::getpeername (auto &&socket, std::span< std::byte > address) -> decltype(auto)
 Gets the peer address of a connected socket.
 
auto io::getsockopt (auto &&socket, int level, int optname, std::span< std::byte > option) -> decltype(auto)
 Gets a socket option.
 
auto io::getsockname (auto &&socket, std::span< std::byte > address) -> decltype(auto)
 Gets the local address of a socket.
 
auto io::listen (auto &&socket, int backlog) -> decltype(auto)
 Sets a socket to listen for incoming connections.
 
auto io::recvmsg (auto &&socket, auto &&msg, int flags) -> decltype(auto)
 Receives a message from a socket.
 
auto io::sendmsg (auto &&socket, auto &&msg, int flags) -> decltype(auto)
 Sends a message on a socket.
 
auto io::setsockopt (auto &&socket, int level, int optname, std::span< const std::byte > option) -> decltype(auto)
 Sets a socket option.
 
auto io::shutdown (auto &&socket, int how) -> decltype(auto)
 Shuts down all or part of a connection on a socket.
 

Detailed Description

Functions for I/O Operations.

These functions are the main interface for performing socket operations. They dispatch to different implementations based on the arguments provided, allowing for both synchronous and asynchronous use.

Function Documentation

◆ accept()

auto io::accept ( auto &&  socket,
std::span< std::byte >  address = {} 
) -> decltype(auto)
inline

Accepts an incoming connection on a listening socket.

Parameters
socketA socket-like object.
addressA span to be populated with the peer's address.
Returns
A (socket, address) pair for synchronous operations, or a stdexec::sender for asynchronous operations.

◆ bind()

auto io::bind ( auto &&  socket,
std::span< const std::byte >  address 
) -> decltype(auto)
inline

Binds a socket to a local address.

Parameters
socketA socket-like object.
addressThe local address to bind to.
Returns
0 on success, -1 on error.

◆ connect()

auto io::connect ( auto &&  socket,
std::span< const std::byte >  address 
) -> decltype(auto)
inline

Connects a socket to a remote address.

Parameters
socketA socket-like object.
addressThe remote address to connect to.
Returns
0 on success, -1 on error for synchronous operations. A stdexec::sender for asynchronous operations.

◆ fcntl()

auto io::fcntl ( auto &&  socket,
int  cmd,
auto &&...  args 
) -> decltype(auto)
inline

Performs a file control operation on a socket.

Parameters
socketA socket-like object.
cmdThe command to perform.
argsOptional arguments for the command.
Returns
The result of the underlying fcntl call.

◆ getpeername()

auto io::getpeername ( auto &&  socket,
std::span< std::byte >  address 
) -> decltype(auto)
inline

Gets the peer address of a connected socket.

Parameters
socketA socket-like object.
addressA span to be populated with the peer's address.
Returns
A span containing the peer's address.

◆ getsockname()

auto io::getsockname ( auto &&  socket,
std::span< std::byte >  address 
) -> decltype(auto)
inline

Gets the local address of a socket.

Parameters
socketA socket-like object.
addressA span to be populated with the local address.
Returns
A span containing the local socket address.

◆ getsockopt()

auto io::getsockopt ( auto &&  socket,
int  level,
int  optname,
std::span< std::byte >  option 
) -> decltype(auto)
inline

Gets a socket option.

Parameters
socketA socket-like object.
levelThe protocol level of the option.
optnameThe option name.
optionA span to be populated with the option value.
Returns
A (result, option) pair, where result is the return code of the underlying getsockopt call.

◆ listen()

auto io::listen ( auto &&  socket,
int  backlog 
) -> decltype(auto)
inline

Sets a socket to listen for incoming connections.

Parameters
socketA socket-like object.
backlogThe maximum length of the pending connections queue.
Returns
The result of the underlying listen call.

◆ recvmsg()

auto io::recvmsg ( auto &&  socket,
auto &&  msg,
int  flags 
) -> decltype(auto)
inline

Receives a message from a socket.

Parameters
socketA socket-like object.
msgA message object to receive data into.
flagsFlags to control the receive operation.
Returns
The number of bytes received for synchronous operations. A stdexec::sender for asynchronous operations.

◆ sendmsg()

auto io::sendmsg ( auto &&  socket,
auto &&  msg,
int  flags 
) -> decltype(auto)
inline

Sends a message on a socket.

Parameters
socketA socket-like object.
msgThe message object to send.
flagsFlags to control the send operation.
Returns
The number of bytes sent for synchronous operations. A stdexec::sender for asynchronous operations.

◆ setsockopt()

auto io::setsockopt ( auto &&  socket,
int  level,
int  optname,
std::span< const std::byte >  option 
) -> decltype(auto)
inline

Sets a socket option.

Parameters
socketA socket-like object.
levelThe protocol level of the option.
optnameThe option name.
optionA span containing the option value.
Returns
The result of the underlying setsockopt call.

◆ shutdown()

auto io::shutdown ( auto &&  socket,
int  how 
) -> decltype(auto)
inline

Shuts down all or part of a connection on a socket.

Parameters
socketA socket-like object.
howA flag specifying which parts of the connection to shut down.
Returns
The result of the underlying shutdown call.