pub struct ReadableChain<'a, 'b, N: DriverNotify, M: DriverMem> { /* private fields */ }
Expand description
Access the readable portion of a descriptor chain.
Provides access to the read-only portion of a descriptor chain. Can be [constructed directly]
(ReadableChain::new) from a DescChain
and once finished with can either be dropped or
converted to a WritableChain
if there are writable portions as well.
As the ReadableChain
takes ownership of the DescChain
dropping the ReadableChain
will automatically return the DescChain
to the Queue
.
For devices and protocols where it is useful, the chain can also be explicitly returned via the
return_complete
method to validate full consumption of the chain.
Implementations§
Source§impl<'a, 'b, N: DriverNotify, M: DriverMem> ReadableChain<'a, 'b, N, M>
impl<'a, 'b, N: DriverNotify, M: DriverMem> ReadableChain<'a, 'b, N, M>
Sourcepub fn new(chain: DescChain<'a, 'b, N>, mem: &'a M) -> Self
pub fn new(chain: DescChain<'a, 'b, N>, mem: &'a M) -> Self
Construct a ReadableChain
from a DescChain
.
Requires a reference to a DriverMem
in order to perform translation into
DeviceRange
.
Sourcepub fn return_complete(self) -> Result<(), ChainCompleteError>
pub fn return_complete(self) -> Result<(), ChainCompleteError>
Immediately return a fully consumed chain.
This both drops the chain, thus returning the underlying DescChain
to the [Queue
]
(crate::queue::Queue), and also checks if it was fully walked, generating an error if not.
Fully walked here means that there are no readable or writable sections that had not been
iterated over.
For virtio queues where the device is expected to fully consume what it is sent, and there is not expected to be anything to write, this provides a way to both check for correct device and driver functionality.
Sourcepub fn next_with_limit(
&mut self,
limit: usize,
) -> Option<Result<DeviceRange<'a>, ChainError>>
pub fn next_with_limit( &mut self, limit: usize, ) -> Option<Result<DeviceRange<'a>, ChainError>>
Request the next range of readable bytes, up to a limit.
As the DeviceRange
returned here represents a contiguous range this may return a smaller
range than requested by limit
, even if there is more readable descriptor(s) remaining. In
this way the caller is directly exposed to size of the underlying descriptors in the chain
as queued by the driver.
A return value of None
indicates there are no more readable descriptors, however there
may still be readable descriptors.
Should this ever return a Some(Err(_))
it will always yield a None
in future calls as
the chain will be deemed corrupt. If walking and attempting to recover from corrupt chains
is desirable, beyond just reporting an error, then you must use the DescChain
directly
and not this interface.
Sourcepub fn next(&mut self) -> Option<Result<DeviceRange<'a>, ChainError>>
pub fn next(&mut self) -> Option<Result<DeviceRange<'a>, ChainError>>
Request the next range of readable bytes.
Similar to next_with_limit
except limit is implicitly usize::MAX
.
This will therefore walk the descriptors in the structure as they were provided by the
driver.
Sourcepub fn remaining(&self) -> Result<Remaining, ChainError>
pub fn remaining(&self) -> Result<Remaining, ChainError>
Query readable bytes and descriptors remaining.
Returns the number of readable bytes and descriptors remaining in the chain. This does not
imply that calling next_with_limit
with the result will return that
much, see next_with_limit
for more details.
Trait Implementations§
Source§impl<'a, 'b, N: DriverNotify, M: DriverMem> Read for ReadableChain<'a, 'b, N, M>
impl<'a, 'b, N: DriverNotify, M: DriverMem> Read for ReadableChain<'a, 'b, N, M>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more