net-mux is an asynchronous connection multiplexing library built on
Tokio. It turns a single ordered, connection-oriented byte stream
(TCP, TLS-over-TCP, KCP, ...) into many concurrent bidirectional logical
streams.
Features
- Credit-based per-stream flow control. Slow consumers do not stall
other streams; total memory is bounded by
max_streams * initial_stream_window. - Correct
AsyncRead/AsyncWrite. Large user writes are transparently fragmented; back-pressure surfaces asPoll::Pending. - Half-close.
shutdown()closes only the write half, mirroring TCP semantics. - Keepalive. Periodic
Pingframes with timeout-driven session shutdown. - Graceful close.
Session::close().awaitflushes outstanding frames, emits aGoAway, and joins all background tasks. - Lock-free hot paths. Atomic windows, atomic stream state, single outbound queue.
See docs/architecture.md and
docs/protocol.md for the deeper design notes.
Quick start
use ;
use ;
use TcpStream;
async
Examples
Echo
The server echoes each line received over a fresh multiplexed stream; the client reads stdin, opens one stream per line, and prints the reply.
Reverse tunnel
If you start an HTTP service on 127.0.0.1:8000
(e.g. python -m http.server 8000), it becomes reachable on
http://127.0.0.1:8001 via the tunnel.
Configuration
use Config;
use Duration;
let cfg = builder
.initial_stream_window
.max_frame_size
.max_streams
.keepalive_interval
.build;