Skip to main content

Module rt

Module rt 

Source
Expand description

Runtime-agnostic networking types (TCP/Unix streams, listeners).

These resolve to the active backend (compio by default, tokio with the runtime-tokio feature, smol with the runtime-smol feature). Socket constructors such as from_unix_stream accept the types re-exported here, so application code never names a runtime crate directly. Runtime facade: the single place that names a concrete async runtime.

Monocoque’s whole socket stack is generic over the I/O traits from compio::io (an owned-buffer, completion-style interface that maps cleanly onto io_uring). Those traits, and the buffer types in compio::buf, are the abstraction the rest of the code is written against, and they stay the same no matter which runtime drives the sockets.

What actually differs between runtimes is small: how you open a connection, how you spawn a task, and how you arm a timer. This module collects exactly those pieces behind one set of names so the rest of the crate (and the ZMTP layer above it) never mentions compio, tokio, or smol directly.

Each backend lives in its own file and is exposed under one shared name, backend, selected by a Cargo feature. Only one is ever compiled:

  • runtime-compio (default): native io_uring through compio (see compio.rs).
  • runtime-tokio: a thin adapter over tokio streams (see tokio.rs).
  • runtime-smol: a thin adapter over smol’s async-io streams (see smol.rs).

The tokio and smol adapters implement the same compio::io traits by reading straight into the owned buffer’s memory, so there is no extra copy on the data path. Exactly one of the three must be enabled.

Structs§

LocalRuntime
A self-contained runtime owned by a single thread.
TcpListener
A TCP socket server, listening for connections.
TcpStream
A TCP stream between a local and a remote socket.
UnixListener
A Unix socket server, listening for connections.
UnixStream
A Unix stream between two local sockets on Windows & WSL.

Traits§

ToSocketAddrs
A trait for objects which can be converted or resolved to one or more SocketAddr values.

Functions§

bind_reuseport
Bind a TCP listener with SO_REUSEPORT so multiple acceptors can share one port with in-kernel load balancing. See crate::tcp::reuseport_listener.
join
Await a spawned task and return its output.
sleep
Waits until duration has elapsed.
spawn
Spawn a task on the current runtime and return its handle.
spawn_blocking
Run a blocking closure off the async executor and await its result.
spawn_detached
Spawn a task and let it run on its own, discarding the handle.
timeout
Require a Future to complete before the specified duration has elapsed.

Type Aliases§

JoinHandle
Handle to a spawned task. Kept alive keeps the task running; dropping it detaches under compio.
OwnedReadHalf
Owned read half of a split TCP stream.
OwnedWriteHalf
Owned write half of a split TCP stream. See OwnedReadHalf.