pub struct RingReader<R> { /* private fields */ }Expand description
The reading end of a CDBG ring: takes frames, never waits, never allocates.
Implementations§
Source§impl<R: Region> RingReader<R>
impl<R: Region> RingReader<R>
Sourcepub unsafe fn new(region: R) -> Result<Self, RingError>
pub unsafe fn new(region: R) -> Result<Self, RingError>
Read the ring in region, after validating its descriptor.
§Safety
This must be the ring’s only reader for as long as it lives: two readers
would race on read_ptr.
Sourcepub fn into_region(self) -> R
pub fn into_region(self) -> R
The region back.
Sourcepub fn snapshot(&self) -> Descriptor
pub fn snapshot(&self) -> Descriptor
A point-in-time copy of the descriptor.
Sourcepub fn drain(&mut self, on_frame: impl FnMut(&[u8])) -> Result<usize, RingError>
pub fn drain(&mut self, on_frame: impl FnMut(&[u8])) -> Result<usize, RingError>
Take every frame that was in the ring when the call began, handing each to
on_frame, and return how many there were.
The batch is bounded by one snapshot of write_ptr: frames the writer
appends while the drain runs wait for the next call. A drain that chased the
live cursor could run for as long as the writer kept up, starving whatever
the caller does between drains (decoding, emitting, checking for shutdown).
Allocation-free; a frame is never longer than
MAX_FRAME_LEN.
Trait Implementations§
Source§impl<R: Region> TransportError for RingReader<R>
impl<R: Region> TransportError for RingReader<R>
Source§impl<R: Region> TryRecvTransport for RingReader<R>
Copies the next frame into buf and consumes it.
impl<R: Region> TryRecvTransport for RingReader<R>
Copies the next frame into buf and consumes it.
TryError::WouldBlock means the ring is empty. A frame longer than buf is
RingError::BufferTooSmall and stays unread, so the caller can retry with a
buffer of max_recv_size bytes, which
always fits.