tokio only.Expand description
Async real-socket UDP adapter over the sans-IO SRT engine.
The sans-IO crate::caller::CallerHandshake / crate::listener::ListenerHandshake
engines never touch a socket — they turn state transitions into typed events
and byte buffers. The ARQ sender/receiver, TSBPD scheduler, and LiveCC
pacing controller follow the same contract: all take caller-supplied
now: core::time::Duration and never read a wall clock.
This module is the thin tokio layer that actually moves bytes over a
tokio::net::UdpSocket, drives the handshake to completion, and then
runs a background driver task per connection that pumps socket RX →
engines → socket TX and, crucially, drives the timers (retransmit, ACK,
NAK, TSBPD release, keep-alive, pacing) from the connection’s own next
deadline (Driver::poll_timeout) — so loss recovery keeps making progress
even when the application is neither sending nor receiving at that instant,
without a fixed tick. The sans-IO core stays no_std; the adapter is pure
plumbing.
Timeouts and the datagram size are explicit: IoConfig
(connect/handshake/read_idle/write, max_datagram). Datagrams are
bytes::Bytes, one exactly-sized allocation per received datagram (never a
view into a shared chunk, which would pin the whole chunk while one packet
is held); the payload handed to the application is a slice of it, so there
is no further copy.
§Why a background task
SRT reliability is bidirectional and continuous: a receiver that detects a
gap emits a NAK, and the sender must react to that NAK by retransmitting
— long after the application handed it the original payload. A purely
pull-based send/recv (one that only advances the protocol while the
app is blocked inside a call) deadlocks the moment a fire-and-forget sender
stops calling send: the inbound NAK is never drained and the lost packet
is never resent. The driver task decouples protocol progress from
application call timing: SrtSocket::send enqueues a payload,
SrtSocket::recv awaits a delivered payload, and the task in between
runs the select loop (RX / app-send / next deadline) until the peer shuts
down, falls silent, or the SrtSocket is dropped.
§Connection lifetime
- Keep-alive (§3.2.3): after one second without sending anything, the driver sends a Keep-Alive, so a quiet sender is not mistaken for a dead one by a peer’s own idle timeout (libsrt’s default is five seconds).
- Peer idle timeout: five seconds without any packet from the peer
ends the connection (
SrtSocket::recvthen returnsNone). - Shutdown (§3.2.7): dropping an
SrtSocketsends the peer a SHUTDOWN so it closes at once instead of waiting out its idle timeout; a received SHUTDOWN ends the connection. - Backpressure:
SrtSocket::sendwaits while the sender already holds a full flow window of unacknowledged packets, so a stalled or dead peer cannot make the send buffer grow without bound.
§Structure
SrtListener— binds a UDP port and accepts incoming SRT connections, returning aSrtSocketper connected peer.SrtSocket— a handle to an established SRT connection (caller or listener role) with asyncsendandrecvfor application payloads; the actual protocol runs on the background driver task the handle owns.
§Feature gate
Only available with features = ["tokio"] (implies std). Without the
tokio feature, the crate stays no_std+alloc and nothing in this
module is compiled.
Structs§
- IoConfig
- Timeouts and sizes for the tokio adapter, carried by
SrtConfigintoSrtSocket::connectandSrtListener::bind. - Socket
Stats - A snapshot of one connection’s
Counters, returned bySrtSocket::stats. - SrtConfig
- Everything one SRT connection or listener is configured by: the handshake
this side advertises and the adapter’s timeouts and sizes. Every
SrtSocketandSrtListenerconstructor takesimpl Into<SrtConfig>, so a bareHandshakeConfig(defaultIoConfig) is accepted as is and a full config isSrtConfig::new(handshake).with_io(io). - SrtListener
- An SRT listener that accepts incoming Caller connections.
- SrtSocket
- A handle to an established SRT connection over UDP.
Constants§
- MAX_
MAX_ DATAGRAM - Largest accepted
IoConfig::max_datagram: the biggest UDP payload. - MIN_
MAX_ DATAGRAM - Smallest accepted
IoConfig::max_datagram: a full SRT header (16 bytes) plus room for a control CIF. A smaller request is clamped up to this (and a larger one down toMAX_MAX_DATAGRAM). - SRT_
TIMEOUTS - The SRT adapter’s default
Timeouts: 10 s to resolve and bind, a 5 s caller handshake, and 5 s for both an idle peer (libsrt’sSRTO_PEERIDLETIMEOdefault of 5000 ms) and a singlesend_to.