Skip to main content

BatchUdpSocket

Struct BatchUdpSocket 

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

A non-owning wrapper around a UDP socket file descriptor providing vectorized batch send and receive operations via libc::sendmmsg and libc::recvmmsg.

Implementations§

Source§

impl BatchUdpSocket

Source

pub fn new(sock: &UdpSocket) -> Self

Create a new BatchUdpSocket borrowing the raw file descriptor of sock.

Source

pub const fn from_raw_fd(fd: RawFd) -> Self

Create a new BatchUdpSocket from an existing raw file descriptor.

Source

pub const fn raw_fd(&self) -> RawFd

Return the underlying raw file descriptor.

Source

pub fn recvmmsg_batch<const N: usize>( &mut self, buffers: &mut [[u8; 2048]; N], out: &mut [ReceivedDatagram; N], ) -> Result<usize>

Receive a burst of up to N datagrams into buffers via libc::recvmmsg.

For each received datagram:

  • The datagram payload bytes are written into buffers[i].
  • Metadata (byte length and source address) is recorded in out[i].

Returns the number of datagrams actually received (0 if the socket would block).

§Errors

Returns an io::Error if the underlying recvmmsg syscall fails with any error other than EAGAIN or EWOULDBLOCK.

Source

pub fn sendmmsg_batch( &mut self, packets: &[(&[u8], SocketAddr)], ) -> Result<usize>

Send a burst of up to BATCH_SIZE (32) datagrams in a single libc::sendmmsg syscall.

If packets.len() > BATCH_SIZE, only the first BATCH_SIZE packets are submitted. Returns the number of datagrams accepted by the kernel (0 if the socket would block).

§Errors

Returns an io::Error if the underlying sendmmsg syscall fails with an unrecoverable error.

Source

pub fn sendmmsg_burst<const N: usize>( &mut self, packets: &[(&[u8], SocketAddr)], ) -> Result<usize>

Send a burst of up to N datagrams in a single libc::sendmmsg syscall.

If packets.len() > N, only the first N packets are submitted. Returns the number of datagrams accepted by the kernel (0 if the socket would block).

§Errors

Returns an io::Error if the underlying sendmmsg syscall fails with an unrecoverable error.

Trait Implementations§

Source§

impl AsRawFd for BatchUdpSocket

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for BatchUdpSocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.