pub struct Ring<T> {
pub mmap: RingMmap<T>,
pub len: usize,
pub mod_mask: u32,
}Expand description
A generic, safe wrapper for an AF_XDP ring buffer.
This struct provides safe methods to interact with a memory-mapped ring, handling atomic operations for producer/consumer indices and access to descriptors.
Fields§
§mmap: RingMmap<T>The memory-mapped components of the ring.
len: usizeThe number of descriptors the ring can hold.
mod_mask: u32A mask used for wrapping around the ring (len - 1).
Implementations§
Source§impl<T> Ring<T>where
T: Copy,
impl<T> Ring<T>where
T: Copy,
Sourcepub fn frame_size(&self) -> u64
pub fn frame_size(&self) -> u64
Returns the size of a single UMEM frame.
Sourcepub fn mmap(
fd: i32,
len: usize,
ring_type: u64,
offsets: &xdp_ring_offset,
) -> Result<Self, Error>
pub fn mmap( fd: i32, len: usize, ring_type: u64, offsets: &xdp_ring_offset, ) -> Result<Self, Error>
Memory-maps a ring from a file descriptor.
§How it works
This function calls the lower-level mmap_ring function to perform the mmap
syscall with the correct offsets for the given ring type. It then initializes
a Ring struct to manage the mapped memory.
Sourcepub fn update_producer(&mut self, value: u32)
pub fn update_producer(&mut self, value: u32)
Atomically updates the producer index of the ring.
Sourcepub fn update_consumer(&mut self, value: u32)
pub fn update_consumer(&mut self, value: u32)
Atomically updates the consumer index of the ring.
Sourcepub fn flags(&self) -> u32
pub fn flags(&self) -> u32
Atomically reads the flags of the ring.
Flags can indicate states like XDP_RING_NEED_WAKEUP.
Sourcepub fn increment(&self, value: &mut u32) -> u32
pub fn increment(&self, value: &mut u32) -> u32
Increments a value, wrapping it around the ring size.
Sourcepub fn mut_desc_at(&mut self, index: u32) -> &mut T
pub fn mut_desc_at(&mut self, index: u32) -> &mut T
Returns a mutable reference to the descriptor at a given index.
§Panics
This function will panic in debug builds if the index is out of bounds.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Ring<T>
impl<T> RefUnwindSafe for Ring<T>where
T: RefUnwindSafe,
impl<T> !Send for Ring<T>
impl<T> !Sync for Ring<T>
impl<T> Unpin for Ring<T>
impl<T> UnwindSafe for Ring<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more