Skip to main content

Crate binger_udp

Crate binger_udp 

Source
Expand description

Cross-platform, batch-native UDP I/O with platform-optimal syscalls.

binger-udp gives you a clean batch API for sending and receiving UDP datagrams, automatically selecting the most efficient system call available on the current platform:

PlatformSendRecv
Linuxsendmmsg / sendmsg w/ GSOrecvmmsg
macOSsendmsg_x (via dlsym)recvmsg_x (via dlsym)
WindowsWSASendMsgWSARecvMsg (via WSAIoctl)
Anysendto / recvfrom fallbackrecvfrom fallback

§Quick start

use std::error::Error;
use binger_udp::{BingerUdp, SendBatch, RecvBatch, Config};

let socket = BingerUdp::from_std(
    std::net::UdpSocket::bind("0.0.0.0:0")?,
    Config::default(),
)?;

// Batch-send 32 packets in one syscall
let mut send = SendBatch::<32>::new();
send.push(b"hello", "192.168.1.1:8080".parse().unwrap())?;
let sent = socket.send_batch(&mut send).await?;

// Batch-receive up to 32 packets in one syscall
let mut recv = RecvBatch::<32>::new(2048);
let n = socket.recv_batch(&mut recv).await?;

Re-exports§

pub use batch::RecvBatch;
pub use batch::SendBatch;
pub use bufs::BufferPool;
pub use error::BingerError;
pub use socket::platform_capabilities;
pub use socket::BingerUdp;
pub use socket::Config;
pub use socket::PlatformCaps;

Modules§

batch
bufs
error
sockaddr
socket