pub struct OwningQueue<H: Hal, const SIZE: usize, const BUFFER_SIZE: usize> { /* private fields */ }alloc only.Expand description
A wrapper around VirtQueue that owns all the buffers that are passed to the queue.
Implementations§
Source§impl<H: Hal, const SIZE: usize, const BUFFER_SIZE: usize> OwningQueue<H, SIZE, BUFFER_SIZE>
impl<H: Hal, const SIZE: usize, const BUFFER_SIZE: usize> OwningQueue<H, SIZE, BUFFER_SIZE>
Sourcepub fn new(queue: VirtQueue<H, SIZE>) -> Result<Self>
pub fn new(queue: VirtQueue<H, SIZE>) -> Result<Self>
Constructs a new OwningQueue wrapping around the given VirtQueue.
This will allocate SIZE buffers of BUFFER_SIZE bytes each and add them to the queue.
The caller is responsible for notifying the device if should_notify returns true.
Sourcepub fn should_notify(&self) -> bool
pub fn should_notify(&self) -> bool
Returns whether the driver should notify the device after adding a new buffer to the virtqueue.
This will be false if the device has suppressed notifications.
Sourcepub fn set_dev_notify(&mut self, enable: bool)
pub fn set_dev_notify(&mut self, enable: bool)
Tells the device whether to send used buffer notifications.
Sourcepub fn poll<T>(
&mut self,
transport: &mut impl Transport,
handler: impl FnOnce(&[u8]) -> Result<Option<T>>,
) -> Result<Option<T>>
pub fn poll<T>( &mut self, transport: &mut impl Transport, handler: impl FnOnce(&[u8]) -> Result<Option<T>>, ) -> Result<Option<T>>
Checks whether there are any buffers which the device has marked as used so the driver
should now process. If so, passes the first one to the handle function and then adds it
back to the queue.
Returns an error if there is an error accessing the queue or handler returns an error.
Returns Ok(None) if there are no pending buffers to handle, or if handler returns
Ok(None).
If handler panics then the buffer will not be added back to the queue, so this should be
avoided.