pub struct SendChain<M: MemOps, P: BufferProvider> { /* private fields */ }Expand description
A configured send chain ready for writing and submission.
Created by ChainBuilder::build. Write readable payload bytes directly on
the chain, then submit via VirtqProducer::submit.
§Examples
let mut sc = producer.chain().readable(64).writable(128).build()?;
sc.write_all(b"header")?.write_all(b" body")?;
let tok = producer.submit(sc)?;
let mut sc = producer.chain().readable(128).build()?;
sc.with_seg(0, |buf| serialize_into(buf))?;
let tok = producer.submit(sc)?;Copy writes (write/write_all) and direct writes (write_seg/with_seg)
must not be mixed on the same chain; doing so panics in debug builds.
If dropped without submitting, allocated buffers are returned to the pool.
Implementations§
Source§impl<M: MemOps, P: BufferProvider> SendChain<M, P>
impl<M: MemOps, P: BufferProvider> SendChain<M, P>
Sourcepub fn segment_count(&self) -> usize
pub fn segment_count(&self) -> usize
Number of producer-written readable segments in this chain.
Sourcepub fn write(&mut self, buf: &[u8]) -> Result<usize, VirtqError>
pub fn write(&mut self, buf: &[u8]) -> Result<usize, VirtqError>
Write bytes into payload segments, returning how many bytes were written.
Appends at the current aggregate write position and scatters across
readable segments in chain order. Uses MemOps::write (volatile on
host side). If buf is larger than the remaining capacity, writes as
many bytes as will fit.
§Errors
VirtqError::NoPayloadSegment- no readable buffer allocatedVirtqError::MemoryWriteError- underlying write failed
Sourcepub fn write_all(&mut self, buf: &[u8]) -> Result<&mut Self, VirtqError>
pub fn write_all(&mut self, buf: &[u8]) -> Result<&mut Self, VirtqError>
Write the entire buffer into payload segments.
Appends at the current aggregate write position and scatters across
readable segments in chain order. Uses MemOps::write (volatile on
host side).
§Errors
VirtqError::PayloadTooLarge- buf exceeds remaining capacityVirtqError::NoPayloadSegment- no readable buffer allocatedVirtqError::MemoryWriteError- underlying write failed
Sourcepub fn write_seg(
&mut self,
index: usize,
buf: &[u8],
) -> Result<&mut Self, VirtqError>
pub fn write_seg( &mut self, index: usize, buf: &[u8], ) -> Result<&mut Self, VirtqError>
Write bytes into one readable segment by index.
Writes from the start of the selected segment and records buf.len() as
that segment’s descriptor length.
§Errors
VirtqError::NoPayloadSegment-indexdoes not name a payload segmentVirtqError::PayloadTooLarge-bufexceeds the segment capacityVirtqError::MemoryWriteError- underlying write failed
Sourcepub fn with_seg<E>(
&mut self,
index: usize,
f: impl FnOnce(&mut [u8]) -> Result<usize, E>,
) -> Result<&mut Self, E>where
E: From<VirtqError>,
pub fn with_seg<E>(
&mut self,
index: usize,
f: impl FnOnce(&mut [u8]) -> Result<usize, E>,
) -> Result<&mut Self, E>where
E: From<VirtqError>,
Serialize directly into one readable segment by index.
The closure returns the number of valid bytes it wrote. The written length for that segment is recorded on success.
§Errors
VirtqError::NoPayloadSegment-indexdoes not name a payload segmentVirtqError::PayloadTooLarge- closure reports more bytes than segment capacityVirtqError::MemoryWriteError- the memory backend cannot expose a mutable slice