boost::corosio::io_stream
Platform stream with read/write operations.
Synopsis
Declared in <boost/corosio/io/io_stream.hpp>
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 |
Abstract base for streams that support async reads. |
|
Abstract base for streams that support async writes. |
Types
Name |
Description |
RAII wrapper for I/O object implementation lifetime. |
|
Platform‐specific stream implementation interface. |
|
Service interface for I/O object lifecycle management. |
Member Functions
Name |
Description |
Return the execution context. |
|
Asynchronously read data from the stream. |
|
Asynchronously write data to the stream. |
Protected Types
Name |
Description |
Awaitable for async read operations. |
|
Awaitable for async write operations. |
Protected Member Functions
Name |
Description |
|
Construct stream from a handle. |
|
Move assign from another I/O object. |
|
|
|
|
Protected Static Member Functions
Name |
Description |
Create a handle bound to a service found in the context. |
Derived Classes
Name |
Description |
An asynchronous Unix stream socket for coroutine I/O. |
|
An asynchronous sequential file for coroutine I/O. |
|
An asynchronous TCP socket for coroutine I/O. |
See Also
io_read_stream, io_write_stream, tcp_socket
Created with MrDocs