boost::corosio::local_stream_socket

An asynchronous Unix stream socket for coroutine I/O.

Synopsis

class local_stream_socket
    : public io_stream

Description

This class provides asynchronous Unix domain stream socket operations that return awaitable types. Each operation participates in the affine awaitable protocol, ensuring coroutines resume on the correct executor.

The socket must be opened before performing I/O operations. Operations support cancellation through std::stop_token via the affine protocol, or explicitly through the cancel() member function.

Thread Safety

Distinct objects: Safe. Shared objects: Unsafe. A socket must not have concurrent operations of the same type (e.g., two simultaneous reads). One read and one write may be in flight simultaneously.

Semantics

Wraps the platform Unix domain socket stack. Operations dispatch to OS socket APIs via the io_context backend (epoll, kqueue, select, or IOCP). Satisfies capy::Stream.

Example

io_context ioc;
local_stream_socket s(ioc);
s.open();

auto [ec] = co_await s.connect(local_endpoint("/tmp/my.sock"));
if (ec)
    co_return;

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

Base Classes

Name

Description

io_stream

Platform stream with read/write operations.

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 local stream socket operations.

io_service

Service interface for I/O object lifecycle management.

wait_awaitable

Represent the awaitable returned by wait.

Type Aliases

Name

Description

endpoint_type

The endpoint type used by this socket.

shutdown_type

Member Functions

Name

Description

local_stream_socket [constructor] [deleted]

Constructors

~local_stream_socket [destructor] [virtual]

Destructor.

operator= [deleted]

Move assignment operator.

assign

Assign an existing file descriptor to this socket.

available

Query the number of bytes available for reading.

cancel

Cancel any pending asynchronous operations.

close

Close the socket.

connect

Initiate an asynchronous connect operation.

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 stream.

release

Release ownership of the native socket handle.

remote_endpoint

Get the remote endpoint of the socket.

set_option

Set a socket option.

shutdown

shutdown overloads

wait

Wait for the socket to become ready in a given direction.

write_some

Asynchronously write data to the stream.

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

local_stream_socket [constructor]

Constructors

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

Description

h_

The platform I/O handle owned by this object.

Friends

Name

Description

boost::corosio::local_stream_acceptor

An asynchronous Unix domain stream acceptor for coroutine I/O.

Non-Member Functions

Name

Description

connect_pair

Synchronously connect two AF_UNIX stream sockets as a connected pair.

Derived Classes

Name

Description

native_local_stream_socket

An asynchronous Unix stream socket with devirtualized I/O operations.

Created with MrDocs