boost::capy::any_read_stream
Type‐erased wrapper for any ReadStream.
Description
This class provides type erasure for any type satisfying the ReadStream concept, enabling runtime polymorphism for read operations. It uses cached awaitable storage to achieve zero steady‐state allocation after construction.
The wrapper supports two construction modes: ‐ Owning: Pass by value to transfer ownership. The wrapper allocates storage and owns the stream. ‐ Reference: Pass a pointer to wrap without ownership. The pointed‐to stream must outlive this wrapper.
Awaitable Preallocation
The constructor preallocates storage for the type‐erased awaitable. This reserves all virtual address space at server startup so memory usage can be measured up front, rather than allocating piecemeal as traffic arrives.
Immediate Completion
When the underlying stream's awaitable reports ready immediately (e.g. buffered data already available), the wrapper skips coroutine suspension entirely and returns the result inline.
Thread Safety
Not thread‐safe. Concurrent operations on the same wrapper are undefined behavior.
Example
// Owning - takes ownership of the stream
any_read_stream stream(socket{ioc});
// Reference - wraps without ownership
socket sock(ioc);
any_read_stream stream(&sock);
mutable_buffer buf(data, size);
auto [ec, n] = co_await stream.read_some(buf);
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Move assignment operator. |
Check if the wrapper contains a valid stream. |
|
Initiate an asynchronous read operation. |
|
Check if the wrapper contains a valid stream. |
See Also
any_write_stream, any_stream, ReadStream
Created with MrDocs