boost::corosio::native_tcp_socket

Connects, reads, and writes over TCP, calling the backend directly.

Synopsis

template<auto Backend>
class native_tcp_socket
    : public tcp_socket

Description

This class template inherits from tcp_socket. It shadows the async operations (read_some, write_some, connect) with versions that call the backend implementation directly. The compiler can then 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 that case, virtual dispatch is used transparently.

Thread Safety

Same as tcp_socket.

Example

capy::task<>
connect_and_read()
{
    corosio::native_io_context<corosio::epoll> ctx;
    corosio::native_tcp_socket<corosio::epoll> s(ctx);
    auto [ec] = co_await s.connect(
        corosio::endpoint(corosio::ipv4_address::loopback(), 8080));
    if (ec)
        co_return;

    char buf[1024];
    auto [ec2, n] =
        co_await s.read_some(capy::mutable_buffer(buf, sizeof(buf)));
    if (ec2)
        co_return;
}

Base Classes

Name

Description

tcp_socket

Connects, reads, and writes over TCP, from a coroutine.

Types

Name

Description

connect_awaitable

Represent the awaitable returned by connect.

handle

Owns a platform‐specific I/O implementation and destroys it when the handle goes out of scope.

implementation

Define backend hooks for TCP socket operations.

io_service

Constructs, closes, and destroys platform implementations on behalf of an I/O object. Platform backends implement this interface.

wait_awaitable

Represent the awaitable returned by wait.

Type Aliases

Name

Description

endpoint_type

The endpoint type used by this socket.

shutdown_type

The shutdown direction type used by this socket.

Member Functions

Name

Description

native_tcp_socket [constructor]

Constructors

operator=

Assignment operators

assign

Assign an existing native socket to this object.

bind

Bind the socket to a local endpoint.

cancel

Cancel any pending asynchronous operations.

close

Close the socket.

connect

Asynchronously connect to a remote endpoint.

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.

read_some

Asynchronously read data from the socket.

release

Release ownership of the native socket handle.

remote_endpoint

Get the remote endpoint of the socket.

set_option

Set a socket option.

shutdown

Disable sends or receives on the socket.

wait

Asynchronously wait for the socket to be ready.

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=

Assignment operators

do_read_some [virtual]

Dispatch read through implementation vtable.

do_write_some [virtual]

Dispatch write through implementation vtable.

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, iocp) whose type provides the concrete implementation types.

See Also

tcp_socket, epoll_t, iocp_t

Created with MrDocs