boost::corosio::native_tcp_socket

An asynchronous TCP socket with devirtualized I/O operations.

Synopsis

template<auto Backend>
class native_tcp_socket
    : public tcp_socket

Description

This class template inherits from tcp_socket and shadows the async operations (read_some, write_some, connect) with versions that call the backend implementation directly, allowing the compiler to inline through the entire call chain.

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

A native_tcp_socket IS‐A tcp_socket and can be passed to any function expecting tcp_socket& or io_stream&, in which case virtual dispatch is used transparently.

Thread Safety

Same as tcp_socket.

Example

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

native_io_context<epoll> ctx;
native_tcp_socket<epoll> s(ctx);
s.open();
auto [ec] = co_await s.connect(ep);
auto [ec2, n] = co_await s.read_some(buf);

Base Classes

Name Description

tcp_socket

An asynchronous TCP socket for coroutine I/O.

Types

Name

Description

connect_awaitable

handle

RAII wrapper for I/O object implementation lifetime.

implementation

io_service

Service interface for I/O object lifecycle management.

linger_options

Options for SO_LINGER socket option.

Enums

Name

Description

shutdown_type

Different ways a socket may be shutdown.

Member Functions

Name

Description

native_tcp_socket [constructor] [deleted]

Constructors

operator= [deleted]

Assignment operators

cancel

Cancel any pending asynchronous operations.

close

Close the socket.

connect

Asynchronously connect to a remote endpoint.

context

Return the execution context.

is_open

Check if the socket is open.

keep_alive

Get the current SO_KEEPALIVE setting.

linger

Get the current SO_LINGER setting.

local_endpoint

Get the local endpoint of the socket.

native_handle

Get the native socket handle.

no_delay

Get the current TCP_NODELAY setting.

open

Open the socket.

read_some

Asynchronously read data from the socket.

receive_buffer_size

Get the receive buffer size (SO_RCVBUF).

remote_endpoint

Get the remote endpoint of the socket.

send_buffer_size

Get the send buffer size (SO_SNDBUF).

set_keep_alive

Enable or disable SO_KEEPALIVE.

set_linger

Set the SO_LINGER option.

set_no_delay

Enable or disable TCP_NODELAY (disable Nagle's algorithm).

set_receive_buffer_size

Set the receive buffer size (SO_RCVBUF).

set_send_buffer_size

Set the send buffer size (SO_SNDBUF).

shutdown

Disable sends or receives on the socket.

write_some

Asynchronously write data to the socket.

Protected Types

Name

Description

read_some_awaitable

Awaitable for async read operations.

write_some_awaitable

Awaitable for async write operations.

Protected Member Functions

Name

Description

operator= [deleted]

Move assign from another I/O object.

do_read_some [virtual]

do_read_some overloads

do_write_some [virtual]

do_write_some overloads

Protected Static Member Functions

Name

Description

create_handle

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

Protected Data Members

Name

h_

Template Parameters

Name Description

Backend

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

See Also

tcp_socket, epoll_t, iocp_t

Created with MrDocs