Skip to main content

Module io

Module io 

Source
Available on crate feature 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::recv then returns None).
  • Shutdown (§3.2.7): dropping an SrtSocket sends the peer a SHUTDOWN so it closes at once instead of waiting out its idle timeout; a received SHUTDOWN ends the connection.
  • Backpressure: SrtSocket::send waits 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 a SrtSocket per connected peer.
  • SrtSocket — a handle to an established SRT connection (caller or listener role) with async send and recv for 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 (SrtSocket::connect_with, SrtListener::bind_with).
SocketStats
A snapshot of one connection’s Counters, returned by SrtSocket::stats.
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 to MAX_MAX_DATAGRAM).