boost::corosio::io_stream

Platform stream with read/write operations.

Synopsis

class io_stream
    : public io_object

Description

This base class provides the fundamental async read and write operations for kernel‐level stream I/O. Derived classes wrap OS‐specific stream implementations (sockets, pipes, etc.) and satisfy capy::ReadStream and capy::WriteStream concepts.

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::buffer( buf.data() + total, buf.size() - total ) );
        if( ec == capy::cond::eof )
            break;
        if( ec.failed() )
            capy::detail::throw_system_error( ec );
        total += n;
    }
}

Base Classes

Name Description

io_object

Base class for platform I/O objects.

Types

Name

Description

handle

RAII wrapper for I/O object implementation lifetime.

implementation

Forward declaration for platform‐specific implementation.

io_object_impl

Base interface for platform I/O implementations.

io_service

Service interface for I/O object lifecycle management.

io_stream_impl

Platform‐specific stream implementation interface.

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 bound to the given execution context.

Protected Data Members

Name

ctx_

impl_

Derived Classes

Name Description

tcp_socket

An asynchronous TCP socket for coroutine I/O.

See Also

capy::Stream, capy::ReadStream, capy::WriteStream, tcp_socket

Created with MrDocs