Skip to main content

Module runtime

Module runtime 

Source
Expand description

The async runtime a driver runs on, injected per driver.

The engine is sans-I/O; the driver owns sockets, tasks and timers. Everything of those that touches a reactor or a clock goes through one object-safe trait, Runtime, given to each driver as an Arc<dyn Runtime> (StreamDriver::with_runtime, PeerDriver::with_runtime):

Injected (reactor or clock)Not injected (executor-agnostic, one implementation)
spawning a task (Runtime::spawn)channels and wake-ups between the driver’s tasks
the clock and timers (Runtime::now, Runtime::sleep_until)sleep, timeout, yield_now: free functions on top
UDP sockets, multicast included (Runtime::bind_udp, Runtime::bind_udp_multicast)
TCP listeners and connections (Runtime::listen_tcp, Runtime::connect_tcp)
name resolution (Runtime::resolve_host and the optional record lookups)
running a future to completion (Runtime::block_on)

There is no global or default runtime in the library, and none can be set: each driver is given its own. Cargo features only decide which built-in runtime types exist (runtime-tokio, on by default: TokioRuntime; runtime-smol: SmolRuntime; runtime-mock: MockRuntime, virtual time and an in-memory network); they never decide what the driver uses, and several can be on at once. With default-features = false and no built-in runtime the crate builds without any of them, and an application implements Runtime for its own executor (the custom-runtime example).

The design follows the upstream project’s “Bring Your Own Async Runtime” (webrtc.rs, 2026-07-30), with one addition: the clock (Runtime::now) is the runtime’s, because the driver stamps every engine input with a time and a virtual clock must be the one both the engine and the timers see.

Re-exports§

pub use mock::MockClock;
pub use mock::MockNet;
pub use mock::MockRuntime;

Modules§

mock
MockRuntime (feature runtime-mock): virtual time and an in-memory network, so that driven connections run deterministically and a 30-second timeout takes no wall time.

Structs§

Elapsed
timeout ran out.
MulticastConfig
What a multicast socket is bound and joined to.
MulticastInterfaceSelector
Applies a Transmit::source to a real multicast socket bound to the unspecified address: before a datagram to a multicast group, it sets the interface the datagram leaves by (IP_MULTICAST_IF to the source address, IPV6_MULTICAST_IF to the index of the interface that holds it) when it differs from the last one set. The system then sends from that interface’s address: on Linux exactly the address given (IP_MULTICAST_IF with an address sets the source), on macOS and Windows the interface’s address, the same one where the interface has one address of the family. For built-in and third-party runtimes whose sockets have a file descriptor.
RecvMeta
What AsyncUdpSocket::poll_recv says about one buffer it filled.
SmolRuntime
The smol runtime: tasks on smol’s global executor, timers and sockets on async-io’s reactor, name lookups on smol’s thread pool. It needs no setup and can be used from any thread, inside or outside smol::block_on.
TokioRuntime
The tokio runtime.
TrafficClassMarker
Applies a Transmit::traffic_class to a real socket: sets IP_TOS / IPV6_TCLASS when the value differs from the last one set, and stops asking once the platform refused (its datagrams then leave unmarked, AsyncUdpSocket::unmarked). For built-in and third-party runtimes whose sockets have a file descriptor.
Transmit
One datagram (or, with segment_size, several of one size back to back) to send.

Traits§

AsyncTcpListener
A TCP listener of a runtime.
AsyncTcpStream
A TCP connection of a runtime. &self methods: the driver’s reader and writer tasks share one Arc.
AsyncUdpSocket
A UDP socket of a runtime, in the poll form of quinn-udp’s so that batched send and receive (sendmmsg, recvmmsg, GSO, GRO) fit.
JoinHandle
A task spawned with Runtime::spawn. Dropping it detaches the task.
Runtime
What a driver needs from an async runtime: the primitives that touch a reactor or a clock.

Functions§

interface_index
The index of the interface that holds the IPv6 address ip (what IPV6_MULTICAST_IF and an IPv6 group membership name an interface by), None when no interface of the host holds it.
interface_name
The name of the interface that holds ip, None when no interface of the host holds it.
reset_on_close
Makes socket’s close abortive (SO_LINGER 0: RST instead of FIN), for AsyncTcpStream::reset_on_close.
set_and_read_traffic_class
Sets socket’s TOS / Traffic Class and reads it back (for AsyncTcpStream::set_traffic_class).
sleep
Waits duration on runtime’s clock.
std_multicast
A non-blocking std UDP socket joined as config says: for IPv4 what rtci-mdns’ MulticastSocket builds (bound to the group on Linux, to 0.0.0.0 elsewhere), for IPv6 [::]:port, IPv6 only; a membership of the group on every interface of MulticastConfig::interfaces (the default interface when there is none).
std_tcp_bound
A non-blocking TCP socket bound to local, for a runtime to connect to a peer.
std_tcp_connect_start
Starts a non-blocking TCP connection from local to remote: the socket is bound, and the handshake runs. A runtime waits for it to become writable, then reads take_error and peer_addr (what async-io’s own connect does), for runtimes whose connect cannot bind a local address first.
std_tcp_listener
A non-blocking std TCP listener on local, backlog 128.
std_udp
A non-blocking std UDP socket on local: what the built-in runtimes wrap.
timeout
future’s output, or Elapsed if duration of runtime’s clock passes first.
timeout_at
future’s output, or Elapsed if runtime’s clock reaches deadline first.
yield_now
Gives other tasks a turn: pending once, with the task woken at once.

Type Aliases§

BoxFuture
A boxed future that can move between threads.