boost::capy::any_buffer_source
Type‐erased wrapper for any BufferSource.
Description
This class provides type erasure for any type satisfying the BufferSource concept, enabling runtime polymorphism for buffer pull operations. It uses cached awaitable storage to achieve zero steady‐state allocation after construction.
The wrapper also satisfies ReadSource. When the wrapped type satisfies only BufferSource, the read operations are synthesized using pull and consume with an extra buffer copy. When the wrapped type satisfies both BufferSource and ReadSource, the native read operations are forwarded directly across the virtual boundary, avoiding the copy.
The wrapper supports two construction modes: ‐ Owning: Pass by value to transfer ownership. The wrapper allocates storage and owns the source. ‐ Reference: Pass a pointer to wrap without ownership. The pointed‐to source must outlive this wrapper.
Within each mode, the vtable is populated at compile time based on whether the wrapped type also satisfies ReadSource: ‐ BufferSource only: read_some and read are synthesized from pull and consume, incurring one buffer copy per operation. ‐ BufferSource + ReadSource: All read operations are forwarded natively through the type‐erased boundary with no extra copy.
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 source
any_buffer_source abs(some_buffer_source{args...});
// Reference - wraps without ownership
some_buffer_source src;
any_buffer_source abs(&src);
const_buffer arr[16];
auto [ec, bufs] = co_await abs.pull(arr);
// ReadSource interface also available
char buf[64];
auto [ec2, n] = co_await abs.read_some(mutable_buffer(buf, 64));
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Move assignment operator. |
Consume bytes from the source. |
|
Check if the wrapper contains a valid source. |
|
Pull buffer data from the source. |
|
Read data into a mutable buffer sequence. |
|
Read some data into a mutable buffer sequence. |
|
Check if the wrapper contains a valid source. |
See Also
any_buffer_sink, BufferSource, ReadSource
Created with MrDocs