Skip to main content

DgramSock

Struct DgramSock 

Source
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

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn send(&self, buf: &[u8]) -> Result<usize>

Send on the connected peer (see connect).

Source

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.

Source

pub fn backend(&self) -> DgramBackend

Which backend was selected.

Source

pub fn send_to(&self, buf: &[u8], addr: SocketAddr) -> Result<usize>

Source

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.

Source

pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>

Source

pub fn recv_with_kts( &self, buf: &mut [u8], ) -> Result<(usize, SocketAddr, Option<i128>)>

Receive one datagram with the kernel arrival timestamp when available.

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Source

pub fn set_nonblocking(&self, nb: bool) -> Result<()>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.