boost::corosio::io_stream

Platform stream with read/write operations.

Synopsis

class io_stream
    : public io_read_stream
    , public io_write_stream

Description

Combines io_read_stream and io_write_stream into a single bidirectional stream. The read_some and write_some operations are inherited from the base classes and dispatch through do_read_some / do_write_some, which this class implements by forwarding to the platform implementation.

The implementation hierarchy stays linear (no diamond): io_object::implementation ‐> io_stream::implementation ‐> tcp_socket::implementation ‐> backend impl.

Semantics

Concrete classes wrap direct platform I/O completed by the kernel. Functions taking io_stream& signal "platform implementation required" ‐ use this when you need actual kernel I/O rather than a mock or test double.

For generic stream algorithms that work with test mocks, use template<capy::Stream S> instead of io_stream&.

Thread Safety

Distinct objects: Safe. Shared objects: Unsafe. All calls to a single stream must be made from the same implicit or explicit serialization context.

Example

// Read until buffer full or EOF
capy::task<> read_all( io_stream& stream, std::span<char> buf )
{
    std::size_t total = 0;
    while( total < buf.size() )
    {
        auto [ec, n] = co_await stream.read_some(
            capy::mutable_buffer( buf.data() + total, buf.size() - total ) );
        if( ec == capy::cond::eof )
            break;
        if( ec )
            throw std::system_error( ec );
        total += n;
    }
}

Base Classes

Name

Description

io_read_stream

Abstract base for streams that support async reads.

io_write_stream

Abstract base for streams that support async writes.

Types

Name

Description

handle

RAII wrapper for I/O object implementation lifetime.

implementation

Platform‐specific stream implementation interface.

io_service

Service interface for I/O object lifecycle management.

Member Functions

Name

Description

context

Return the execution context.

read_some

Asynchronously read data from the stream.

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

io_stream [constructor]

Construct stream from a handle.

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.

Derived Classes

Name

Description

local_stream_socket

An asynchronous Unix stream socket for coroutine I/O.

stream_file

An asynchronous sequential file for coroutine I/O.

tcp_socket

An asynchronous TCP socket for coroutine I/O.

See Also

io_read_stream, io_write_stream, tcp_socket

Created with MrDocs