pub struct RingConsumer<M> { /* private fields */ }Expand description
Consumer (device) side of a packed virtqueue.
The consumer polls for available buffer chains submitted by the driver, processes them, and marks them as used. This is typically used by the device/host side.
§Lifecycle
- Poll: Call
poll_availableto get buffers - Process: Read from readable buffers, write to writable buffers
- Complete: Call
submit_usedto return buffers - Notify: If
submit_used_with_notifyreturns true, signal the driver
Implementations§
Source§impl<M: MemOps> RingConsumer<M>
impl<M: MemOps> RingConsumer<M>
pub fn new(layout: Layout, mem: M) -> Self
Sourcepub fn poll_available(&mut self) -> Result<(u16, BufferChain), RingError>
pub fn poll_available(&mut self) -> Result<(u16, BufferChain), RingError>
Poll for an available buffer chain.
Returns the chain ID and a BufferChain containing all buffers.
The chain ID must be passed to submit_used
when processing is complete.
§Returns
Ok((id, chain))- A buffer chain is availableErr(RingError::WouldBlock)- No buffers availableErr(RingError::BadChain)- Malformed chain (driver bug)
Sourcepub fn submit_used(
&mut self,
id: u16,
written_len: u32,
) -> Result<(), RingError>
pub fn submit_used( &mut self, id: u16, written_len: u32, ) -> Result<(), RingError>
Publish a single used descriptor for the chain identified by id. written_len is the total bytes produced by the device (for writable part).
§Arguments
id- The chain ID frompoll_availablewritten_len- Total bytes written to writable buffers
§Errors
RingError::InvalidState- Unknown ID or already completed
Sourcepub fn peek_available(&self) -> Result<bool, RingError>
pub fn peek_available(&self) -> Result<bool, RingError>
Try to peek whether the next chain is available without consuming it.
Sourcepub fn submit_used_with_notify(
&mut self,
id: u16,
written_len: u32,
) -> Result<bool, RingError>
pub fn submit_used_with_notify( &mut self, id: u16, written_len: u32, ) -> Result<bool, RingError>
Submit a used descriptor and return whether to notify the driver.
Sourcepub fn num_inflight(&self) -> usize
pub fn num_inflight(&self) -> usize
Get number of inflight (submitted but not yet used) descriptors.
Sourcepub fn avail_cursor(&self) -> RingCursor
pub fn avail_cursor(&self) -> RingCursor
Get a snapshot of the current avail cursor position.
Sourcepub fn used_cursor(&self) -> RingCursor
pub fn used_cursor(&self) -> RingCursor
Get a snapshot of the current used cursor position.
Sourcepub fn disable_avail_notifications(&mut self) -> Result<(), RingError>
pub fn disable_avail_notifications(&mut self) -> Result<(), RingError>
Device disables available-buffer notifications from driver to device.
This is the device-side mirror of “disable callbacks” but for avail kicks.
Sourcepub fn enable_avail_notifications(&mut self) -> Result<(), RingError>
pub fn enable_avail_notifications(&mut self) -> Result<(), RingError>
Device enables available-buffer notifications from driver to device.
Sourcepub fn enable_avail_notifications_desc(
&mut self,
off: u16,
wrap: bool,
) -> Result<(), RingError>
pub fn enable_avail_notifications_desc( &mut self, off: u16, wrap: bool, ) -> Result<(), RingError>
Device enables descriptor-specific available notifications (EVENT_IDX / DESC mode).
This tells the driver: “Kick me when you reach avail index (off, wrap)”.
Sourcepub fn enable_avail_notifications_for_next(&mut self) -> Result<(), RingError>
pub fn enable_avail_notifications_for_next(&mut self) -> Result<(), RingError>
Convenience: enable DESC mode for “next avail cursor” (device wants a kick when new buffers arrive at the next index it will poll).