Skip to main content

XdpSocket

Struct XdpSocket 

Source
pub struct XdpSocket { /* private fields */ }
Expand description

An AF_XDP socket: UMEM + fill/completion/rx/tx rings bound to one interface queue.

Implementations§

Source§

impl XdpSocket

Source

pub fn open(ifindex: IfIndex, config: XdpConfig) -> Result<Self>

Opens an AF_XDP socket, registers a UMEM, sets up the four rings, and binds to (ifindex, config.queue_id).

Source

pub fn recv(&mut self) -> Result<Block<'_>>

Receives the currently-available batch of frames (non-blocking).

The returned Block borrows frame bytes directly from the UMEM; dropping it returns those chunks to the fill ring for the kernel to reuse. Use XdpSocket::as_fd with poll/ AsyncFd to wait for readiness. Returns an empty block when nothing is ready.

Source

pub fn as_fd(&self) -> BorrowedFd<'_>

Borrows the socket file descriptor for readiness integration.

Source

pub fn stats(&self) -> Result<Stats>

Reads AF_XDP drop/error statistics.

Source

pub fn send(&mut self, frame: &[u8]) -> Result<usize>

Sends a single frame by copying it into a free UMEM chunk and kicking the TX ring.

Non-blocking: returns WouldBlock when no free chunk or TX descriptor is available (wait for writability on XdpSocket::as_fd and retry). Completed transmissions are reclaimed opportunistically on each call.

Source

pub fn send_batch(&mut self, frames: &[&[u8]]) -> Result<usize>

Sends a batch of frames, returning how many were accepted before the UMEM or TX ring filled up (at least one, or WouldBlock).

Trait Implementations§

Source§

impl AsFd for XdpSocket

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for XdpSocket

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Send for XdpSocket

Auto Trait Implementations§

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, 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.