Skip to main content

binger_udp/
lib.rs

1//! Cross-platform, batch-native UDP I/O with platform-optimal syscalls.
2//!
3//! `binger-udp` gives you a clean batch API for sending and receiving UDP
4//! datagrams, automatically selecting the most efficient system call available
5//! on the current platform:
6//!
7//! | Platform | Send | Recv |
8//! |----------|------|------|
9//! | Linux | `sendmmsg` / `sendmsg` w/ GSO | `recvmmsg` |
10//! | macOS | `sendmsg_x` (via `dlsym`) | `recvmsg_x` (via `dlsym`) |
11//! | Windows | `WSASendMsg` | `WSARecvMsg` (via `WSAIoctl`) |
12//! | Any | `sendto` / `recvfrom` fallback | `recvfrom` fallback |
13//!
14//! # Quick start
15//!
16//! ```rust,no_run
17//! use std::error::Error;
18//! use binger_udp::{BingerUdp, SendBatch, RecvBatch, Config};
19//!
20//! # async fn example() -> Result<(), Box<dyn Error>> {
21//! let socket = BingerUdp::from_std(
22//!     std::net::UdpSocket::bind("0.0.0.0:0")?,
23//!     Config::default(),
24//! )?;
25//!
26//! // Batch-send 32 packets in one syscall
27//! let mut send = SendBatch::<32>::new();
28//! send.push(b"hello", "192.168.1.1:8080".parse().unwrap())?;
29//! let sent = socket.send_batch(&mut send).await?;
30//!
31//! // Batch-receive up to 32 packets in one syscall
32//! let mut recv = RecvBatch::<32>::new(2048);
33//! let n = socket.recv_batch(&mut recv).await?;
34//! # Ok(()) }
35//! ```
36
37pub mod batch;
38pub mod bufs;
39pub mod error;
40#[cfg(feature = "metrics")]
41pub mod metrics;
42mod platform;
43pub mod sockaddr;
44pub mod socket;
45mod sys;
46
47#[cfg(feature = "timestamping")]
48pub use batch::Timestamp;
49pub use batch::{RecvBatch, SendBatch};
50pub use bufs::BufferPool;
51pub use error::BingerError;
52#[cfg(feature = "metrics")]
53pub use metrics::BingerMetrics;
54pub use socket::{platform_capabilities, BingerUdp, Config, PlatformCaps};