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
impl BatchUdpSocket
Sourcepub fn new(sock: &UdpSocket) -> Self
pub fn new(sock: &UdpSocket) -> Self
Create a new BatchUdpSocket borrowing the raw file descriptor of sock.
Sourcepub const fn from_raw_fd(fd: RawFd) -> Self
pub const fn from_raw_fd(fd: RawFd) -> Self
Create a new BatchUdpSocket from an existing raw file descriptor.
Sourcepub fn recvmmsg_batch<const N: usize>(
&mut self,
buffers: &mut [[u8; 2048]; N],
out: &mut [ReceivedDatagram; N],
) -> Result<usize>
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.
Sourcepub fn sendmmsg_batch(
&mut self,
packets: &[(&[u8], SocketAddr)],
) -> Result<usize>
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.
Sourcepub fn sendmmsg_burst<const N: usize>(
&mut self,
packets: &[(&[u8], SocketAddr)],
) -> Result<usize>
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.