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): nativeio_uringthrough compio (seecompio.rs).runtime-tokio: a thin adapter over tokio streams (seetokio.rs).runtime-smol: a thin adapter over smol’s async-io streams (seesmol.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§
- Local
Runtime - 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.
- Unix
Listener - A Unix socket server, listening for connections.
- Unix
Stream - A Unix stream between two local sockets on Windows & WSL.
Traits§
- ToSocket
Addrs - A trait for objects which can be converted or resolved to one or more
SocketAddrvalues.
Functions§
- bind_
reuseport - Bind a TCP listener with
SO_REUSEPORTso multiple acceptors can share one port with in-kernel load balancing. Seecrate::tcp::reuseport_listener. - join
- Await a spawned task and return its output.
- sleep
- Waits until
durationhas 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
Futureto complete before the specified duration has elapsed.
Type Aliases§
- Join
Handle - Handle to a spawned task. Kept alive keeps the task running; dropping it detaches under compio.
- Owned
Read Half - Owned read half of a split TCP stream.
- Owned
Write Half - Owned write half of a split TCP stream. See
OwnedReadHalf.