Coordinated binary read source with optional prefetch and cache. More...
#include <StormByte/buffer/io/buffered_reader.hxx>

Classes | |
| class | Parameters |
| Reader knobs. More... | |
Public Member Functions | |
| const StormByte::String::String & | Path () const noexcept |
| Locator stored at construction. | |
| enum Location | Location () const noexcept |
| Where Path points. | |
| virtual | operator bool () const noexcept final |
| Whether the source is prepared to read. | |
| virtual enum State | State () const noexcept final |
| Session state. | |
Lifecycle | |
| BufferedReader (const BufferedReader &)=delete | |
| Copy constructor is deleted. | |
| BufferedReader (BufferedReader &&other) noexcept | |
| Move constructor. | |
| virtual | ~BufferedReader () noexcept |
| Virtual destructor. | |
| BufferedReader & | operator= (const BufferedReader &)=delete |
| Copy assignment is deleted. | |
| BufferedReader & | operator= (BufferedReader &&other) noexcept |
| Move assignment. | |
Session | |
| virtual bool | Open () final |
| Arm the origin. | |
| virtual Result | Close () final |
| Stop prefetch, drop caches, close the origin. | |
| virtual bool | Rewind () final |
| Re-arm an open source: Close then Open. | |
| virtual bool | IsOpen () const noexcept final |
| Whether Open succeeded and Close has not. | |
| virtual bool | IsReadable () const noexcept final |
| Whether reads may be attempted. | |
| virtual bool | EoF () const noexcept final |
| Whether no further bytes can be produced. | |
| virtual StormByte::ByteSize | Available () const noexcept final |
| Cached bytes readable at Tell without touching the origin. | |
Read | |
| virtual Result | Read (StormByte::ByteSize n, FIFO &dest) const final |
Read n bytes into dest, consuming cache / origin. | |
| virtual Result | Read (std::span< std::byte > dest) const final |
Read into dest, consuming cache / origin. | |
| virtual Result | Peek (StormByte::ByteSize n, FIFO &dest) const final |
Copy n bytes into dest without consuming cache. | |
| virtual Result | Peek (std::span< std::byte > dest) const final |
Copy into dest without consuming cache. | |
Position | |
| virtual Result | Seek (std::ptrdiff_t offset, Position mode) const final |
| Move the logical read cursor. | |
| virtual StormByte::ByteSize | Tell () const noexcept final |
| Logical read offset in the stream. | |
| virtual bool | IsSeekable () const noexcept final |
| Whether this instance can reposition the origin. | |
Size | |
| virtual bool | IsSized () const noexcept final |
| Whether the origin length is known. | |
| virtual std::optional< StormByte::ByteSize > | Size () const noexcept final |
| Origin length in bytes when known. | |
Telemetry | |
| const StormByte::Shared< StormByte::Buffer::ReadTelemetry > | Telemetry () const noexcept |
| Shared read counters. | |
Policy | |
| virtual StormByte::ByteSize | ReadAhead () const noexcept |
| Configured prefetch length in bytes. | |
| virtual void | ReadAhead (StormByte::ByteSize bytes) |
| Set prefetch length. | |
| virtual StormByte::ByteSize | MaxMemory () const noexcept |
| Configured cache memory cap in bytes. | |
| virtual void | MaxMemory (StormByte::ByteSize bytes) |
| Set cache memory cap. | |
| virtual std::chrono::milliseconds | MaxWait () const noexcept |
| Configured read wait limit. | |
| virtual void | MaxWait (std::chrono::milliseconds wait) |
| Set read wait limit. | |
Protected Member Functions | |
| STORMBYTE_FORCE_INLINE | BufferedReader (StormByte::String::String path, enum Location location, Parameters parameters={}) |
| Construct an unopened coordinator (State::Unavailable). | |
| BufferedReader (StormByte::String::String path, enum Location location, StormByte::ByteSize read_ahead, StormByte::ByteSize max_memory, std::chrono::milliseconds max_wait) | |
| Construct an unopened coordinator (State::Unavailable). | |
| void | SetState (enum State state) noexcept |
| Publish session state from a leaf hook. | |
| virtual void | Setup () |
| Leaf policy hook. | |
| virtual StormByte::Shared< StormByte::Buffer::ReadTelemetry > | CreateTelemetry () const |
| Allocate the telemetry object this instance will keep. | |
Origin hooks | |
| virtual Result | OriginOpen ()=0 |
| Arm the underlying device and SetState. | |
| virtual Result | OriginClose ()=0 |
| Release the underlying device and SetState Unavailable. | |
| virtual Result | OriginPull (StormByte::ByteSize n, FIFO &dest)=0 |
Read up to n bytes from the device into dest. | |
| virtual bool | OriginCanSeek () const noexcept=0 |
| Whether the device can seek. | |
| virtual Result | OriginSeek (std::ptrdiff_t offset, Position mode)=0 |
| Seek the device. | |
| virtual bool | OriginHasSize () const noexcept=0 |
| Whether the device reports a length. | |
| virtual std::optional< StormByte::ByteSize > | OriginSize () const noexcept=0 |
| Device length in bytes. | |
Friends | |
| class | StormByte::Buffer::Backend::IO::BufferedReader |
Coordinated binary read source with optional prefetch and cache.
Public base for byte origins. Callers take const BufferedReader&. Leaves implement only the Origin* hooks and may override Setup and CreateTelemetry. They do not override Read, Peek, Seek, Open, Close or Rewind.
std::span<std::byte>). No text mode.Open while Idle fails and leaves the state Idle. Close then Open is a valid round-trip.operator bool is true only when the instance is prepared to read: State is Idle and not EoF.
n bytes or origin end. MaxWait of 0ms waits without limit and never returns IO::Status::TryAgain. A positive MaxWait caps the wait; timeout yields IO::Status::TryAgain, destination untouched, state Idle. Origin failure during a pull is IO::Status::Error; the destination is not written; session state becomes State::Fault or State::Unavailable.FIFO overloads: n == 0 serves the current cached span from Tell. Span overloads: dest.size() is the request; an empty span returns IO::Status::Ok and count 0 without consuming or pulling. There is no Read(n, span).
count bytes of dest are written; the remainder of the span is left as-is. Untouched on IO::Status::Failed, IO::Status::Error, IO::Status::TryAgain, or End with count 0.Read advances Tell. Served bytes stay in the map until MaxMemory eviction. Peek does not move Tell.Prefetch is suspended while Tell differs from the device cursor (a "fake seek"). The worker must not pull or OriginSeek in that window: that would either move the device (so a later catch-up is no longer sequential) or commit bytes at the wrong stream offset. Prefetch resumes when Tell meets the device again (the catch-up read is a plain OriginPull, not a seek) or when a hole forces a real OriginSeek.
A jump back into resident pages, then one or many Reads that stay in those pages, never seeks the origin. Reading past that window onto the old device position is still not a seek. Reading past a page whose hole is not the device cursor performs one OriginSeek to that hole.
SeekSavedFull / SeekSavedPartial close on the next Seek or Close. Full: the epoch started on a cache hit and never called OriginSeek. Partial: it did. Small Reads do not decide; the epoch does.
A non-seekable origin rejects Seek without the hook. Seek may block on prefetch cancellation.
StormByte::Shared of StormByte::Buffer::ReadTelemetry. The user cannot reseat the handle. The office updates the same object. The dynamic type is IO::ReadTelemetry unless a leaf overrides CreateTelemetry. Accumulators start at construction and do not reset on Close. MeanRate is the caller rate.m_io. Moved-from is Unavailable.
|
delete |
Copy constructor is deleted.
|
noexcept |
Move constructor.
| other | Instance to take from. Left Unavailable. |
|
virtualnoexcept |
Virtual destructor.
Stops the worker. Does not call Origin*.
Leaves must call Close in their destructor so OriginClose still runs on a live vtable.
|
inlineprotected |
Construct an unopened coordinator (State::Unavailable).
| path | Locator. Stored once. |
| location | Location::Local or Location::Remote. Stored once. |
| parameters | Omitted knobs are 0 / 0 ms. Resolved in the caller. |
|
protected |
Construct an unopened coordinator (State::Unavailable).
| path | Locator. Stored once. |
| location | Location::Local or Location::Remote. Stored once. |
| read_ahead | Initial ReadAhead in bytes. |
| max_memory | Initial MaxMemory in bytes. |
| max_wait | Initial MaxWait. 0ms = unlimited. |
DLL boundary. Children that already resolved knobs call this.
|
finalvirtualnoexcept |
Cached bytes readable at Tell without touching the origin.
Does not call OriginPull or OriginSeek. Does not wait for prefetch. Prefetch already in the map is counted; an in-flight pull is not.
|
finalvirtual |
Stop prefetch, drop caches, close the origin.
Idempotent. Sets session state to State::Unavailable.
|
protectedvirtual |
Allocate the telemetry object this instance will keep.
Called once, after the most-derived constructor, the first time telemetry is needed. A remote leaf returns a further-derived type. Must not return empty.
|
finalvirtualnoexcept |
|
finalvirtualnoexcept |
|
finalvirtualnoexcept |
Whether reads may be attempted.
operator bool.
|
finalvirtualnoexcept |
Whether this instance can reposition the origin.
|
finalvirtualnoexcept |
Whether the origin length is known.
|
noexcept |
Where Path points.
Does not change.
|
virtualnoexcept |
Configured cache memory cap in bytes.
|
virtual |
Set cache memory cap.
Takes effect immediately.
| bytes | Approximate maximum resident cache. 0 drops all spans. |
Cancels prefetch and evicts farthest spans before returning. Waits for the worker; not an origin pull.
|
virtualnoexcept |
Configured read wait limit.
0ms waits forever (never IO::Status::TryAgain).
|
virtual |
Set read wait limit.
Takes effect on the next Read / Peek.
| wait | 0ms = unlimited. Positive = timeout then TryAgain. |
Overridable so a leaf can clamp. Does not cancel an in-flight prefetch. Does not trim the cache.
|
finalvirtual |
Arm the origin.
true if State is State::Idle afterwards.Calls Setup then the backend Open. Not idempotent. A second call while Idle returns false and leaves the session Idle.
|
explicitfinalvirtualnoexcept |
Whether the source is prepared to read.
true if State is State::Idle and not EoF.
|
noexcept |
Move assignment.
| other | Instance to take from. Left Unavailable. |
|
delete |
Copy assignment is deleted.
|
protectedpure virtualnoexcept |
Whether the device can seek.
true if OriginSeek is usable. Implemented in StormByte::Buffer::IO::BufferedLocationReader.
|
protectedpure virtual |
Release the underlying device and SetState Unavailable.
Implemented in StormByte::Buffer::IO::BufferedFileReader.
|
protectedpure virtualnoexcept |
Whether the device reports a length.
true if OriginSize has a value. Implemented in StormByte::Buffer::IO::BufferedLocationReader.
|
protectedpure virtual |
Arm the underlying device and SetState.
Implemented in StormByte::Buffer::IO::BufferedFileReader.
|
protectedpure virtual |
Read up to n bytes from the device into dest.
| n | Maximum bytes to transfer. |
| dest | Implementation FIFO (not the user destination). |
On IO::Status::Error call SetState with State::Fault or State::Unavailable.
Implemented in StormByte::Buffer::IO::BufferedFileReader.
|
protectedpure virtual |
Seek the device.
| offset | Byte offset. |
| mode | Absolute or relative to the device cursor. |
May be slow. Called from a pull when the device cursor is not already at the requested offset.
Implemented in StormByte::Buffer::IO::BufferedFileReader.
|
protectedpure virtualnoexcept |
Device length in bytes.
Implemented in StormByte::Buffer::IO::BufferedFileReader.
|
noexcept |
Locator stored at construction.
Does not change.
A file path, socket://… or http://… . A file leaf's path is always a local filesystem path.
|
finalvirtual |
Copy into dest without consuming cache.
| dest | Caller span. Request size is dest.size(). |
dest.An empty span returns IO::Status::Ok and count 0 without pulling. The first count bytes of dest are written; the tail is left unchanged.
|
finalvirtual |
|
finalvirtual |
Read into dest, consuming cache / origin.
| dest | Caller span. Request size is dest.size(). |
dest.An empty span returns IO::Status::Ok and count 0 without consuming or pulling. The first count bytes of dest are written; the tail is left unchanged.
|
finalvirtual |
|
virtualnoexcept |
Configured prefetch length in bytes.
|
virtual |
Set prefetch length.
Takes effect immediately.
| bytes | Bytes to hold ahead of the cursor after a Read. |
Cancels in-flight prefetch and may trim the cache before returning. Does not pull from the origin. Still waits for the worker.
|
finalvirtual |
|
finalvirtual |
Move the logical read cursor.
| offset | Byte offset. |
| mode | Position::Absolute or Position::Relative. |
Does not call OriginSeek. The device is realigned on a later pull only if that pull's offset is not the current device cursor. Non-seekable origins return Failed without invoking the hook. Negative absolute offsets and relative steps before offset 0 fail. Not currently armed also fails.
|
protectednoexcept |
Publish session state from a leaf hook.
| state | New State. |
Called from OriginOpen, OriginClose and OriginPull. Not for user code.
|
protectedvirtual |
Leaf policy hook.
Called from Open before the origin.
Default does nothing. File uses it for the path-only ctor. The most-derived vtable is live.
Reimplemented in StormByte::Buffer::IO::BufferedLocationReader.
|
finalvirtualnoexcept |
Origin length in bytes when known.
|
finalvirtualnoexcept |
Session state.
|
noexcept |
Shared read counters.
Same instance for the life of this reader.
The user cannot reseat the handle. The office updates the same object. Survivors keep the last values. A leaf may store a wider dynamic type via CreateTelemetry.
|
finalvirtualnoexcept |
Logical read offset in the stream.
|
friend |