// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include #include // A received message, from the socket until the last consumer lets go of the shared_ptr to it struct ReceiveBufferRegion { uint8_t *data = nullptr; size_t size = 0; }; // Bounds the bytes a puller holds in received messages, handed out and taken back in arrival order class ReceiveRingBuffer { struct State; std::shared_ptr state; public: explicit ReceiveRingBuffer(size_t capacity); // Blocks for the bytes; nullptr once stopped. A request larger than the capacity is served from the heap, at once std::shared_ptr Allocate(size_t size); // Releases every waiter in Allocate; the regions already handed out stay valid. void Stop(); size_t GetCapacity() const; // Bytes held in live regions right now / at most since construction (heap fallbacks included). size_t GetUtilization() const; size_t GetMaxUtilization() const; };