boost::capy::any_write_stream
Type‐erased wrapper for any WriteStream.
Description
This class provides type erasure for any type satisfying the WriteStream concept, enabling runtime polymorphism for write 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
Operations complete immediately without suspending when the buffer sequence is empty, or when the underlying stream's awaitable reports readiness via await_ready.
Thread Safety
Not thread‐safe. Concurrent operations on the same wrapper are undefined behavior.
Example
// Owning - takes ownership of the stream
any_write_stream stream(socket{ioc});
// Reference - wraps without ownership
socket sock(ioc);
any_write_stream stream(&sock);
const_buffer buf(data, size);
auto [ec, n] = co_await stream.write_some(std::span(&buf, 1));
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Move assignment operator. |
Check if the wrapper contains a valid stream. |
|
Initiate an asynchronous write operation. |
|
Check if the wrapper contains a valid stream. |
See Also
any_read_stream, any_stream, WriteStream
Created with MrDocs