boost::corosio::native_udp_socket

An asynchronous UDP socket with devirtualized I/O operations.

Synopsis

template<auto Backend>
class native_udp_socket
    : public udp_socket

Description

This class template inherits from udp_socket and shadows the async operations (send_to, recv_from, connect, send, recv) with versions that call the backend implementation directly, allowing the compiler to inline through the entire call chain.

Non‐async operations (open, close, cancel, bind, socket options) remain unchanged and dispatch through the compiled library.

A native_udp_socket IS‐A udp_socket and can be passed to any function expecting udp_socket&, in which case virtual dispatch is used transparently.

Thread Safety

Same as udp_socket.

Example

#include <boost/corosio/native/native_udp_socket.hpp>

native_io_context<epoll> ctx;
native_udp_socket<epoll> s(ctx);
s.open();
s.bind(endpoint(ipv4_address::any(), 9000));
char buf[1024];
endpoint sender;
auto [ec, n] = co_await s.recv_from(
    capy::mutable_buffer(buf, sizeof(buf)), sender);

Base Classes

Name

Description

udp_socket

An asynchronous UDP socket for coroutine I/O.

Types

Name

Description

connect_awaitable

Represent the awaitable returned by connect.

handle

RAII wrapper for I/O object implementation lifetime.

implementation

Define backend hooks for UDP socket operations.

io_service

Service interface for I/O object lifecycle management.

recv_awaitable

Represent the awaitable returned by recv.

recv_from_awaitable

Represent the awaitable returned by recv_from.

send_awaitable

Represent the awaitable returned by send.

send_to_awaitable

Represent the awaitable returned by send_to.

wait_awaitable

Represent the awaitable returned by wait.

Member Functions

Name

Description

native_udp_socket [constructor] [deleted]

Constructors

operator= [deleted]

Assignment operators

bind

Bind the socket to a local endpoint.

cancel

Cancel any pending asynchronous operations.

close

Close the socket.

connect

Asynchronously connect to set the default peer.

context

Return the execution context.

get_option

Get a socket option.

is_open

Check if the socket is open.

local_endpoint

Get the local endpoint of the socket.

native_handle

Get the native socket handle.

open

Open the socket.

recv

Receive a datagram from the connected peer.

recv_from

Receive a datagram and capture the sender's endpoint.

remote_endpoint

Get the remote endpoint of the socket.

send

Send a datagram to the connected peer.

send_to

Send a datagram to the specified destination.

set_option

Set a socket option.

wait

Asynchronously wait for the socket to be ready.

Protected Member Functions

Name

Description

operator= [deleted]

Move assign from another I/O object.

Protected Static Member Functions

Name

Description

create_handle

Create a handle bound to a service found in the context.

Protected Data Members

Name

Description

h_

The platform I/O handle owned by this object.

Template Parameters

Name

Description

Backend

A backend tag value (e.g., epoll) whose type provides the concrete implementation types.

See Also

udp_socket, epoll_t

Created with MrDocs