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(featureruntime-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
timeoutran out.- Multicast
Config - What a multicast socket is bound and joined to.
- Multicast
Interface Selector - Applies a
Transmit::sourceto 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_IFto the source address,IPV6_MULTICAST_IFto 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_IFwith 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. - Recv
Meta - What
AsyncUdpSocket::poll_recvsays about one buffer it filled. - Smol
Runtime - 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 outsidesmol::block_on. - Tokio
Runtime - The tokio runtime.
- Traffic
Class Marker - Applies a
Transmit::traffic_classto a real socket: setsIP_TOS/IPV6_TCLASSwhen 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§
- Async
TcpListener - A TCP listener of a runtime.
- Async
TcpStream - A TCP connection of a runtime.
&selfmethods: the driver’s reader and writer tasks share oneArc. - Async
UdpSocket - 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. - Join
Handle - 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(whatIPV6_MULTICAST_IFand an IPv6 group membership name an interface by),Nonewhen no interface of the host holds it. - interface_
name - The name of the interface that holds
ip,Nonewhen no interface of the host holds it. - reset_
on_ close - Makes
socket’s close abortive (SO_LINGER0: RST instead of FIN), forAsyncTcpStream::reset_on_close. - set_
and_ read_ traffic_ class - Sets
socket’s TOS / Traffic Class and reads it back (forAsyncTcpStream::set_traffic_class). - sleep
- Waits
durationonruntime’s clock. - std_
multicast - A non-blocking std UDP socket joined as
configsays: for IPv4 what rtci-mdns’MulticastSocketbuilds (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 ofMulticastConfig::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
localtoremote: the socket is bound, and the handshake runs. A runtime waits for it to become writable, then readstake_errorandpeer_addr(what async-io’s ownconnectdoes), 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, orElapsedifdurationofruntime’s clock passes first.- timeout_
at future’s output, orElapsedifruntime’s clock reachesdeadlinefirst.- 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.