|
| | Bridge (const ExternalReader &in, const ExternalWriter &out, std::size_t chunk_size=4096) noexcept |
| | Construct a Bridge with both read and write handlers (copying handlers).
|
| |
| | Bridge (ExternalReader &&in, ExternalWriter &&out, std::size_t chunk_size=4096) noexcept |
| | Construct a Bridge with both read and write handlers (moving handlers).
|
| |
| std::size_t | ChunkSize () const noexcept |
| | Gets the configured chunk size for passthrough operations.
|
| |
| bool | Flush () const noexcept |
| | Flushes any pending bytes in the internal buffer to the write handler.
|
| |
| bool | Passthrough (std::size_t bytes) const noexcept |
| | Passthrough bytes from read handler to write handler (const overload).
|
| |
| bool | Passthrough (std::size_t bytes) noexcept |
| | Passthrough bytes from read handler to write handler (non-const overload).
|
| |
| std::size_t | PendingBytes () const noexcept |
| | Gets the number of pending bytes in the internal buffer.
|
| |
|
The Bridge is non-copyable but movable. The destructor attempts to flush any pending bytes by calling Flush().
|
|
| Bridge (const Bridge &other)=delete |
| | Copy constructor (deleted) — Bridge is non-copyable.
|
| |
|
| Bridge (Bridge &&other) noexcept=default |
| | Move constructor (defaulted) — transfers handlers.
|
| |
|
| ~Bridge () noexcept |
| | Destructor — attempts to flush pending bytes.
|
| |
|
Bridge & | operator= (const Bridge &other)=delete |
| | Copy assignment (deleted).
|
| |
|
Bridge & | operator= (Bridge &&other) noexcept=default |
| | Move assignment (defaulted).
|
| |
Pass-through adapter that forwards bytes from an ExternalReader to an ExternalWriter in chunks.
The Bridge connects an ExternalReader (source) and an ExternalWriter (sink). It reads data from the reader and forwards it to the writer in fixed-size chunks specified by chunk_size. The class keeps a small internal SharedFIFO buffer (m_buffer) that accumulates data between calls.
Key behaviour and guarantees:
- Reads are requested from the configured
ExternalReader (const or non-const overload is selected depending on whether the Bridge instance itself is const). The const overload is expected to perform non-destructive/peek-style reads while the non-const overload may destructively consume data from the reader.
- When enough bytes are available (>=
chunk_size) the bridge forwards whole chunks to the ExternalWriter via ExternalWriter::Write().
- If
chunk_size is zero then chunking is disabled: the bridge will attempt to forward all bytes read from the ExternalReader to the ExternalWriter immediately (no accumulation into fixed-size chunks). In this mode the internal buffer is not used for normal accumulation of leftovers; callers should still handle writer failures appropriately.
- To avoid losing data on writer failure the implementation copies the head (the bytes given to the writer) and only moves the remaining tail into the internal buffer. This preserves the original data in case the writer rejects the chunk.
- After passthrough operations the internal buffer will contain at most
chunk_size - 1 bytes (the leftover tail). Flush() will write any remaining bytes in a single call.
- The destructor calls
Flush() to attempt sending pending bytes.
Thread-safety and constness:
- The
Bridge is NOT thread-safe and is intended for single-thread usage only. It must not be shared concurrently across threads without external synchronization. The class does not provide internal locking or other synchronization primitives.
- The internal
mutable buffer permits logically-const operations to update internal state (for example, const passthrough overloads may internally accumulate data). This facility is provided solely for convenience in single-threaded scenarios and does not imply safety for concurrent use.
- The
ExternalReader and ExternalWriter objects are stored behind std::shared_ptr; callers remain responsible for ensuring those handlers are not concurrently accessed in an unsafe manner.