Version 1.4.0
[Summary]
StormByte Buffer is the byte-buffer module of the StormByte C++ suite.
It depends on StormByte Base and optionally StormByte Logger. This repository is not Base, Config, Crypto, Database, Logger, Multimedia, Network or System.
Public headers under StormByte/buffer/ cover FIFO, SharedFIFO, Ring, Producer/Consumer, Hopper, Sink, Bridge, Pipeline and StormByte::Buffer::IO (buffered binary sources and sinks).
If you landed here from a release link and have not read the tree:
- What this module is, how to build it, and short examples: README.md
- License: GNU Lesser General Public License version 3 or later, LICENSE
Added
StormByte::Buffer::IO. Buffered binary sources and sinks, separate from FIFO / Ring / Hopper. Public surface:Status,State,Result,ToString,BufferedReader,BufferedWriter,BufferedFileReader,BufferedFileWriter.IO::Backendis the PIMPL and is not a public include.Status/Result/State.Ok,End,Error,Failed,TryAgainplus a bytecount.TryAgainis backpressure or a boundedMaxWait.State:Idle,Missing,Directory,Permission,NotWritable,Fault,Unavailable.constexpr ToStringforStatusandState.BufferedReader. Public base for a binary origin. Leaves implementOriginOpen,OriginClose,OriginPull,OriginCanSeek,OriginSeek,OriginHasSizeandOriginSize. OptionalSetup()runs once fromOpenbeforeOriginOpen. Construction isUnavailable; a successfulOpenisIdle.Closeis idempotent;Openis not.operator boolis Idle and notEoF.- Reader
Read/Peekinto aFIFOor a writablestd::span<std::byte>. Destination overwritten only onOk/Endwith a non-zero count. Empty span is{Ok, 0}. FIFOn == 0serves the cached span atTell.MaxWait0mswaits without limit. - Reader
Seek/Tell/IsSeekable/IsSized/Size. Absolute or relative only. End-relative isSeek(*Size() + off, Absolute)when sized. SeekableSeekalways callsOriginSeek, including a cache hit. Non-seekableSeekisFailedand does not call the hook. Seek is not O(1). Cache is a map of owned spans; overlap merges;MaxMemoryevicts farthest fromTell;0stores nothing and still serves from the origin. Prefetch stops onSeekand on move (Rebind); the nextRead/Peekrequests it again. BufferedFileReader.ifstreamleaf, seekable and sized. Path-only constructor probes device throughput atSetupand setsReadAhead(window clamped 16 KiB–1 MiB) withMaxMemory1 MiB. Explicit(path, read_ahead, max_memory)keeps those knobs. Does not open in the constructor.BufferedWriter. Public base for a binary sink. Leaves implementOriginOpen,OriginClose,OriginPush,OriginFlushandOriginTruncate. OptionalSetup()andWillWrite. NoSeek.Tellis bytes accepted sinceOpenorTruncate.Closeflushes then closes; a flush failure isFault.- Writer
Write(const FIFO&),Write(FIFO&)andWrite(std::span<const std::byte>). Atomic.WriteChunkandBackPressure(in chunks): either knob0is direct; both> 0use an SPSCLockFreeRingcapped atBackPressure * WriteChunkbytes. Overflow isTryAgain.Dirty()is unread ring bytes.Flush()drains the ring and callsOriginFlush. BufferedFileWriter.ofstreamleaf, binary append. Creates the file when the parent exists (nomkdir -p). Path-only constructor probes the device atSetupand setsWriteChunkplusBackPressure4. Explicit(path, write_chunk, backpressure)keeps those knobs.Truncateoverwrites.- Device throughput probe (private): Linux / Windows / macOS classification (HDD, SATA SSD, NVMe gen, USB, network at 80 % of NIC). Nominal rates, not a benchmark. Device knobs have no setters;
MaxMemoryandMaxWaitstay settable. LockFreeRing::FrontSpan,ConsumeandWrite(std::span<const std::byte>).ExternalWriter::Occupied.Bridgepumps anyExternalReader/IOreader into anyExternalWriter/IOwriter.Drainrespects sink backpressure. Worker auto-drains; publicPassthroughis gone.high_water == 0means no extra occupancy cap. The worker starts, including whenhigh_wateris 0. Pause is onlyDrainer(Toggle).- Two-argument
Bridgeconstructors forBufferedWritersinks:
Bridge(const IO::BufferedReader&, IO::BufferedWriter&)and
Bridge(ExternalReader&, IO::BufferedWriter&). No occupancy cap at
the Bridge layer. Same pump path ashigh_water == 0. Intended for
BufferedFileWriter(WriteChunk / BackPressure already cap Dirty).
Pairings into FIFO / SharedFIFO / Ring / Producer keep the
three-argument constructor.
Removed
Sink::BindandSink::Bind(int, Sink&). Wire withTo(key)/>>/<<.
Tests
BufferedFileReaderTests. Fixtures undertest/files/. SpanRead/Peek,Tell,Seek(absolute, relative, end viaSize, cache hit,MaxMemory0), path-only vs explicit constructors, move with prefetch stopped.BufferedFileWriterTests. Temp files viaStormByte::System::TempFileName. Direct(path, 0, 0), path-only device knobs, Dirty / Flush / BackPressure / Truncate / move.BufferedMeteredFileTests. Selective override example (BytesRead/BytesWritten).- Bridge coverage for pipe close-while-started,
high_water0, and the two-argument writer ctors (test_io_uncapped_ctor,test_buf_to_io_uncapped_ctor).