7#include <PhosphorChannel/phosphorchannel_export.h>
46PHOSPHORCHANNEL_EXPORT
bool offerRing(
int socket,
RingWriter& ring,
int timeoutMs, std::string* error);
53 static constexpr std::size_t
MaxCapacity = std::size_t(1) << 30;
57 static std::unique_ptr<RingWriter>
create(std::size_t
capacity, std::string
codec, std::string* error);
74 const std::string&
codec()
const
103 bool fits(std::uint64_t readPos, std::size_t bytes)
const;
109 int m_peerWakeFd = -1;
110 void* m_map =
nullptr;
111 std::size_t m_mapSize = 0;
112 std::size_t m_capacity = 0;
113 std::uint64_t m_writePos = 0;
114 std::uint64_t m_readPosSeen = 0;
116 bool m_closed =
false;
117 bool m_broken =
false;
118 bool m_offered =
false;
130 static std::unique_ptr<RingReader>
attach(
int memoryFd,
int wakeFd, std::string
codec, std::size_t maxCapacity,
169 void* m_map =
nullptr;
170 std::size_t m_mapSize = 0;
171 std::size_t m_capacity = 0;
172 std::uint64_t m_readPos = 0;
173 std::uint64_t m_writePosSeen = 0;
175 bool m_corrupt =
false;
176 bool m_closed =
false;
177 bool m_writerGone =
false;
int dataFd() const
Readable when the writer wrote after a read() returned Empty, closed the ring, or went away.
Definition Ring.h:154
static std::unique_ptr< RingReader > attach(int memoryFd, int wakeFd, std::string codec, std::size_t maxCapacity, std::string *error)
Maps the ring of a writer.
std::size_t capacity() const
Definition Ring.h:144
const std::string & codec() const
Definition Ring.h:140
void close()
Tells the writer that nothing reads any more: its writes return Closed.
RingReader & operator=(const RingReader &)=delete
RingReader(const RingReader &)=delete
ReadResult read(std::string &frame)
The next frame in frame, without waiting.
int spaceFd() const
Readable when the reader freed the space that a WouldBlock asked for, closed the ring,...
Definition Ring.h:83
static constexpr std::size_t MaxCapacity
Definition Ring.h:53
WriteResult tryWrite(std::string_view frame)
Writes one frame without waiting.
std::size_t maxFrame() const
The largest frame that the ring takes.
friend bool offerRing(int socket, RingWriter &ring, int timeoutMs, std::string *error)
Sends ring over socket and waits for the answer.
int memoryFd() const
The memfd of the ring.
Definition Ring.h:95
RingWriter(const RingWriter &)=delete
const std::string & codec() const
Definition Ring.h:74
std::size_t capacity() const
Definition Ring.h:70
void close()
Tells the reader that no frame follows.
WriteResult write(std::string_view frame, int timeoutMs)
Waits up to timeoutMs (-1: no limit) for space.
RingWriter & operator=(const RingWriter &)=delete
static std::unique_ptr< RingWriter > create(std::size_t capacity, std::string codec, std::string *error)
A ring of capacity bytes (rounded up to 8) for codec.
static constexpr std::size_t MinCapacity
The smallest and the largest data area, in bytes.
Definition Ring.h:52
WriteResult
Definition Channel.h:43
ReadResult
Definition Channel.h:56
PHOSPHORCHANNEL_EXPORT bool offerRing(int socket, RingWriter &ring, int timeoutMs, std::string *error)
Sends ring over socket and waits for the answer.