pub trait BufferAccess {
// Required methods
fn guest_memory(&self) -> &GuestMemory;
fn write_data(&mut self, id: RxId, data: &[u8]);
fn push_guest_addresses(&self, id: RxId, buf: &mut Vec<RxBufferSegment>);
fn capacity(&self, id: RxId) -> u32;
fn write_header(&mut self, id: RxId, metadata: &RxMetadata);
// Provided methods
fn write_packet(&mut self, id: RxId, metadata: &RxMetadata, data: &[u8]) { ... }
fn write_packet_segments(
&mut self,
id: RxId,
metadata: &RxMetadata,
segments: &[&[u8]],
) { ... }
}Expand description
Frontend-owned access to guest receive buffers.
Each frontend implements this trait to map RxId values to
guest memory regions. The backend writes received packet data
and metadata through these methods.
The frontend owns the BufferAccess and passes &mut references
to Queue methods. This means no Arc/Mutex is needed
between the frontend and backend for buffer access—the borrow
checker enforces exclusive access statically.
Required Methods§
Sourcefn guest_memory(&self) -> &GuestMemory
fn guest_memory(&self) -> &GuestMemory
The associated guest memory accessor.
Sourcefn write_data(&mut self, id: RxId, data: &[u8])
fn write_data(&mut self, id: RxId, data: &[u8])
Writes data to the specified buffer.
Sourcefn push_guest_addresses(&self, id: RxId, buf: &mut Vec<RxBufferSegment>)
fn push_guest_addresses(&self, id: RxId, buf: &mut Vec<RxBufferSegment>)
Appends the guest address segments for the specified buffer to buf.
Callers must clear buf before calling if they do not want segments
from a previous call to be retained.
Sourcefn write_header(&mut self, id: RxId, metadata: &RxMetadata)
fn write_header(&mut self, id: RxId, metadata: &RxMetadata)
Sets the packet metadata for the receive.
Provided Methods§
Sourcefn write_packet(&mut self, id: RxId, metadata: &RxMetadata, data: &[u8])
fn write_packet(&mut self, id: RxId, metadata: &RxMetadata, data: &[u8])
Writes the packet header and data in a single call.
Sourcefn write_packet_segments(
&mut self,
id: RxId,
metadata: &RxMetadata,
segments: &[&[u8]],
)
fn write_packet_segments( &mut self, id: RxId, metadata: &RxMetadata, segments: &[&[u8]], )
Writes the packet header and a payload composed of multiple discontiguous segments, in order, as a single logical packet.
This allows callers to hand off a frame whose bytes are not contiguous in memory (for example, an Ethernet/IP/TCP header followed by payload that wraps a ring buffer) without first linearizing it into a scratch buffer.
The default implementation copies the segments into a temporary
contiguous buffer and forwards to BufferAccess::write_packet.
Backends that write directly into guest memory should override this to
write each segment at its running offset and avoid the copy.