tokio_fast_udp/capability.rs
1/// Runtime-detected UDP optimization capabilities of a [`FastUdpSocket`].
2///
3/// All fields are determined at `build()` time by probing the kernel and
4/// applying any kill-switches from [`FastUdpSocketBuilder`]. Call
5/// [`FastUdpSocket::capabilities`] to inspect what the socket is using.
6///
7/// [`FastUdpSocket`]: crate::FastUdpSocket
8/// [`FastUdpSocket::capabilities`]: crate::FastUdpSocket::capabilities
9/// [`FastUdpSocketBuilder`]: crate::FastUdpSocketBuilder
10#[derive(Debug, Clone)]
11pub struct Capabilities {
12 /// Generic Segmentation Offload — send N packets via one `sendmsg` with
13 /// `UDP_SEGMENT`. Linux only.
14 pub gso: bool,
15 /// Generic Receive Offload — receive coalesced datagrams via `recvmsg`
16 /// with `UDP_GRO`. Linux only.
17 pub gro: bool,
18 /// `sendmmsg` batch send — multiple UDP datagrams in a single syscall.
19 /// Linux (and some other Unix) only.
20 pub sendmmsg: bool,
21 /// Explicit Congestion Notification — send/receive IP TOS/TCLASS ancillary
22 /// data.
23 pub ecn: bool,
24 /// Maximum number of datagrams the socket will attempt in a single batch
25 /// call.
26 pub max_batch: usize,
27}
28
29impl Capabilities {
30 /// No optimizations — portable single-datagram fallback on every path.
31 pub fn none() -> Self {
32 Capabilities {
33 gso: false,
34 gro: false,
35 sendmmsg: false,
36 ecn: false,
37 max_batch: 1,
38 }
39 }
40}