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.- Local
Interface - One address of one interface of the host (
Runtime::interfaces). - 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§
- dont_
fragment - The Don’t Fragment state
set_dont_fragmentset, as the operating system reports it (getsockopt):truefor DF / no local fragmentation. - enable_
ecn_ receive - Asks the system to report each received datagram’s TOS / Traffic Class byte
(
IP_RECVTOS,IPV6_RECVTCLASS), from whichrecv_from_with_ecnreads the ECN field (RFC 3168; RFC 6679 section 7.2.1: receivers “listen for ECT/CE”). Unix only; elsewhereUnsupported, and received datagrams carry no ECN. - host_
interfaces - The operating system’s interface addresses, with their prefix lengths and the temporary
flag (
shared::ifaces::temporary_ipv6_addresses: Linux, Android, macOS and iOS report it; elsewhere nothing is marked). - host_
preferred_ source Runtime::preferred_sourceon the operating system: the route to a documentation address (RFC 5737, RFC 3849), which only a default route covers.- host_
route_ source Runtime::route_sourceon the operating system.- 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. - recv_
from_ with_ ecn - Receives one datagram into
buf(recvmsg): its length, its sender, and the ECN codepoint of its IP header (the two low bits of the TOS / Traffic Class byte) when the system reports it (enable_ecn_receive). A datagram longer thanbufis truncated, asrecv_fromtruncates 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). - set_
dont_ fragment - Sets the Don’t Fragment state of
socket(IPv6 whenipv6):truesets the IPv4 DF bit and forbids local fragmentation over IPv6,falselets the datagram be fragmented. Linux and Android:IP_MTU_DISCOVER/IPV6_MTU_DISCOVERtoPMTUDISC_DOorPMTUDISC_DONT; Apple systems and FreeBSD:IP_DONTFRAG/IPV6_DONTFRAG. ElsewhereUnsupported. - 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.