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
impl XdpSocket
Sourcepub fn open(ifindex: IfIndex, config: XdpConfig) -> Result<Self>
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).
Sourcepub fn recv(&mut self) -> Result<Block<'_>>
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.
Sourcepub fn as_fd(&self) -> BorrowedFd<'_>
pub fn as_fd(&self) -> BorrowedFd<'_>
Borrows the socket file descriptor for readiness integration.
Sourcepub fn send(&mut self, frame: &[u8]) -> Result<usize>
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.
Sourcepub fn send_batch(&mut self, frames: &[&[u8]]) -> Result<usize>
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).