tokio_fast_udp/tokio_fast_udp.rs
1//! Fast cross-platform UDP I/O for tokio.
2//!
3//! Provides async UDP sockets that leverage modern OS syscalls for high
4//! throughput:
5//!
6//! - **GSO** (Generic Segmentation Offload) on Linux: send a single large
7//! buffer that the kernel/NIC splits into multiple UDP datagrams.
8//! - **GRO** (Generic Receive Offload) on Linux: receive multiple coalesced
9//! datagrams in one syscall.
10//! - **ECN** (Explicit Congestion Notification): send and receive IP-level
11//! congestion marks.
12//! - **SO_REUSEPORT** (Linux): bind multiple sockets to the same address:port
13//! for kernel-level load balancing across processes/threads.
14//!
15//! On platforms without these optimizations (macOS, Windows, etc.) a
16//! portable `sendmsg`/`recvmsg` fallback is used so the same application code
17//! compiles and runs everywhere.
18//!
19//! # Quick start
20//!
21//! ```no_run
22//! use tokio_fast_udp::{FastUdpSocket, ReceiveItem, SendItem};
23//!
24//! #[tokio::main]
25//! async fn main() -> std::io::Result<()> {
26//! let socket = FastUdpSocket::build("127.0.0.1:9000".parse().unwrap())
27//! .bind()?;
28//!
29//! let dst = "127.0.0.1:9001".parse().unwrap();
30//! let items = [SendItem::new(dst, b"hello")];
31//! socket.send_many(&items).await?;
32//!
33//! let mut buf = vec![0u8; 1500];
34//! let mut recv = [ReceiveItem::new(&mut buf)];
35//! socket.receive_many(&mut recv).await?;
36//! println!("got {} bytes", recv[0].len());
37//! Ok(())
38//! }
39//! ```
40
41mod capability;
42mod ecn;
43mod item;
44mod socket;
45
46pub use capability::Capabilities;
47pub use ecn::Ecn;
48pub use item::{ReceiveItem, SendItem};
49pub use socket::{FastUdpSocket, FastUdpSocketBuilder};
50
51#[cfg(test)]
52mod tests;