Struct Ring

Source
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: usize

The number of descriptors the ring can hold.

§mod_mask: u32

A mask used for wrapping around the ring (len - 1).

Implementations§

Source§

impl<T> Ring<T>
where T: Copy,

Source

pub fn frame_size(&self) -> u64

Returns the size of a single UMEM frame.

Source

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.

Source

pub fn consumer(&self) -> u32

Atomically reads the consumer index of the ring.

Source

pub fn producer(&self) -> u32

Atomically reads the producer index of the ring.

Source

pub fn update_producer(&mut self, value: u32)

Atomically updates the producer index of the ring.

Source

pub fn update_consumer(&mut self, value: u32)

Atomically updates the consumer index of the ring.

Source

pub fn flags(&self) -> u32

Atomically reads the flags of the ring.

Flags can indicate states like XDP_RING_NEED_WAKEUP.

Source

pub fn increment(&self, value: &mut u32) -> u32

Increments a value, wrapping it around the ring size.

Source

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.

Source

pub fn desc_at(&self, index: u32) -> T

Returns a copy of the descriptor at a given index.

§Panics

This function will panic in debug builds if the index is out of bounds.

Source§

impl Ring<u64>

Source

pub fn fill(&mut self, start_frame: u32)

Fills the ring (typically the Fill Ring) with UMEM frame addresses.

§Arguments
  • start_frame - The starting frame number to begin filling from.
Source§

impl Ring<XdpDesc>

Source

pub fn fill(&mut self, start_frame: u32)

Fills the ring (typically the TX ring) with default XdpDesc values.

This pre-populates the ring with descriptors pointing to corresponding UMEM frames.

§Arguments
  • start_frame - The starting frame number to begin filling from.
Source

pub fn set(&mut self, index: u32, len: u32)

Sets the descriptor at index to a specific length.

The address is calculated based on the index and frame size.

Trait Implementations§

Source§

impl<T: Default> Default for Ring<T>

Source§

fn default() -> Ring<T>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.