pub struct DgramSock { /* private fields */ }Expand description
A datagram socket whose backend is chosen at runtime: io_uring where available, plain UDP otherwise. Same surface either way.
Implementations§
Source§impl DgramSock
impl DgramSock
Sourcepub fn wrap(sock: UdpSocket) -> Self
pub fn wrap(sock: UdpSocket) -> Self
Wrap a bound UdpSocket, auto-detecting the io_uring backend. Honors
SUBETHA_DGRAM (iouring / udp); otherwise prefers io_uring on
Linux and falls back to plain UDP when the ring cannot be created.
Sourcepub fn demux(real: Arc<UdpSocket>, queue: DemuxQueue) -> Self
pub fn demux(real: Arc<UdpSocket>, queue: DemuxQueue) -> Self
Build a demux-backed socket: inbound datagrams are popped from queue
(fed by a demux reader that classifies one real socket’s datagrams by
first wire byte), outbound sends forward to real. The unified
Sens-O-Matic endpoint uses this to fan one socket out to its per-code
RLC and RS receivers without modifying either.
Sourcepub fn demux_counted(
real: Arc<UdpSocket>,
queue: DemuxQueue,
sent: Arc<AtomicU64>,
) -> Self
pub fn demux_counted( real: Arc<UdpSocket>, queue: DemuxQueue, sent: Arc<AtomicU64>, ) -> Self
Like demux but tallies every datagram sent through it
into sent (the unified endpoint’s raw-loss numerator).
Sourcepub fn demux_probe(&self) -> Option<(u64, u64, u64, u64)>
pub fn demux_probe(&self) -> Option<(u64, u64, u64, u64)>
Demux-backend queue probe: (pop_attempts, pop_yields, queue_ptr, queue_len), or None for a non-demux backend.
queue_ptr is the shared queue’s Arc address, comparable
against the pushing reader’s record of the same.
Sourcepub fn from_udp(sock: UdpSocket) -> Self
pub fn from_udp(sock: UdpSocket) -> Self
Wrap a bound UdpSocket as a plain-UDP DgramSock WITHOUT the io_uring
auto-upgrade. The Reed-Solomon transport drives the raw fd directly for
GRO / TTL / ECN / connected-send / Windows USO, so it needs the Udp
backend (reachable via as_udp); wrap’s io_uring
upgrade would hide the fd. Sets no sockopts of its own - that transport
manages its own recvmsg cmsgs and control-buffer sizing, so adding the
RX-timestamp cmsg here could overflow its control buffer.
Sourcepub fn as_udp(&self) -> Option<&UdpSocket>
pub fn as_udp(&self) -> Option<&UdpSocket>
The underlying UdpSocket when this is a plain-UDP backend (the only
backend with a directly-usable fd), else None. Lets a transport that
needs raw-fd socket features keep them on the standalone path and fall
back cleanly on the demux / io_uring / wire paths.
Sourcepub fn connect(&self, addr: SocketAddr) -> Result<()>
pub fn connect(&self, addr: SocketAddr) -> Result<()>
Connect the socket to addr so send can omit it. Udp
connects the kernel socket; Demux records the peer for its forwarded
send. io_uring / wire are not used by the connected-send transport.
Sourcepub fn recv(&self, buf: &mut [u8]) -> Result<usize>
pub fn recv(&self, buf: &mut [u8]) -> Result<usize>
Receive on the connected socket (see connect). Udp
uses the kernel connected recv; Demux pops its demux queue.
Sourcepub fn backend(&self) -> DgramBackend
pub fn backend(&self) -> DgramBackend
Which backend was selected.
pub fn send_to(&self, buf: &[u8], addr: SocketAddr) -> Result<usize>
Sourcepub fn send_gso(
&self,
batch: &[u8],
seg_size: u16,
addr: SocketAddr,
) -> Result<()>
pub fn send_gso( &self, batch: &[u8], seg_size: u16, addr: SocketAddr, ) -> Result<()>
Ship batch (an integer number of seg_size-byte datagrams concatenated)
to addr in ONE sendmsg via UDP GSO (UDP_SEGMENT) - the kernel slices
it into batch.len() / seg_size wire datagrams, replicating IP+UDP
headers. Collapses the per-datagram syscall + stack-traversal cost (~62x
fewer syscalls at MTU). Falls back to one send_to per segment on
backends without a UDP fd (Wire) or non-Linux. batch.len() MUST be a
multiple of seg_size, and seg_size * n_segs must fit a single IP
datagram (<= 65535) - the caller caps the batch.
pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
Sourcepub fn recv_with_kts(
&self,
buf: &mut [u8],
) -> Result<(usize, SocketAddr, Option<i128>)>
pub fn recv_with_kts( &self, buf: &mut [u8], ) -> Result<(usize, SocketAddr, Option<i128>)>
Receive one datagram with the kernel arrival timestamp when available.