Skip to main content

RingConsumer

Struct RingConsumer 

Source
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

  1. Poll: Call poll_available to get buffers
  2. Process: Read from readable buffers, write to writable buffers
  3. Complete: Call submit_used to return buffers
  4. Notify: If submit_used_with_notify returns true, signal the driver

Implementations§

Source§

impl<M: MemOps> RingConsumer<M>

Source

pub fn new(layout: Layout, mem: M) -> Self

Source

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 available
  • Err(RingError::WouldBlock) - No buffers available
  • Err(RingError::BadChain) - Malformed chain (driver bug)
Source

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 from poll_available
  • written_len - Total bytes written to writable buffers
§Errors
Source

pub fn peek_available(&self) -> Result<bool, RingError>

Try to peek whether the next chain is available without consuming it.

Source

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.

Source

pub fn num_free(&self) -> usize

Get number of free descriptors in the ring.

Source

pub fn num_inflight(&self) -> usize

Get number of inflight (submitted but not yet used) descriptors.

Source

pub fn is_full(&self) -> bool

Check if the ring is full (no free descriptors).

Source

pub fn len(&self) -> usize

Get descriptor table length

Source

pub fn mem(&self) -> &M

Get memory accessor reference

Source

pub fn avail_cursor(&self) -> RingCursor

Get a snapshot of the current avail cursor position.

Source

pub fn used_cursor(&self) -> RingCursor

Get a snapshot of the current used cursor position.

Source

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.

Source

pub fn enable_avail_notifications(&mut self) -> Result<(), RingError>

Device enables available-buffer notifications from driver to device.

Source

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)”.

Source

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).

Source

pub fn reset(&mut self)

Reset to initial state matching a freshly zeroed ring. Does not reallocate internal buffers.

Trait Implementations§

Source§

impl<M: Debug> Debug for RingConsumer<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> Freeze for RingConsumer<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for RingConsumer<M>
where M: RefUnwindSafe,

§

impl<M> Send for RingConsumer<M>
where M: Send,

§

impl<M> Sync for RingConsumer<M>
where M: Sync,

§

impl<M> Unpin for RingConsumer<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for RingConsumer<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for RingConsumer<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more