boost::capy::any_write_sink
Type‐erased wrapper for any WriteSink.
Description
This class provides type erasure for any type satisfying the WriteSink concept, enabling runtime polymorphism for sink 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 sink. ‐ Reference: Pass a pointer to wrap without ownership. The pointed‐to sink 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.
Thread Safety
Not thread‐safe. Concurrent operations on the same wrapper are undefined behavior.
Example
// Owning - takes ownership of the sink
any_write_sink ws(some_sink{args...});
// Reference - wraps without ownership
some_sink sink;
any_write_sink ws(&sink);
const_buffer buf(data, size);
auto [ec, n] = co_await ws.write(std::span(&buf, 1));
auto [ec2] = co_await ws.write_eof();
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Move assignment operator. |
Check if the wrapper contains a valid sink. |
|
|
|
Signal end of data. |
|
Check if the wrapper contains a valid sink. |
See Also
any_write_stream, WriteSink
Created with MrDocs