async-smux
A lightweight asynchronous smux (Simple MUltipleXing) library for smol/async-std and any async runtime compatible to futures
.
async-smux
consumes a struct implementing AsyncRead + AsyncWrite + Unpin + Send
, like TcpStream
and TlsStream
, to create a Mux<T>
struct. And then you may spawn multiple MuxStream<T>
s (up to 4294967295) over Mux<T>
, which also implements AsyncRead + AsyncWrite + Unpin + Send
.
Benchmark
Here is a simple benchmarking result on my local machine, comparing to the original version smux (written in go).
Implementation | Throughput (TCP) | Handshake |
---|---|---|
smux (go) | 0.4854 GiB/s | 17.070 K/s |
async-smux (rust) | 1.0550 GiB/s | 81.774 K/s |
Run cargo bench
to test it by yourself. Check out /benches
directory for more details.
Laziness
No thread or task will be spawned by this library. It just spawns a few future
s. So it's totally runtime-independent.
Mux
and MuxStream
are completely lazy and will DO NOTHING if you don't poll()
them.
Any polling operation, including .read()
,.write()
, accept()
and connect()
, will push Mux
and MuxStream
working.
Specification
VERSION(1B) | CMD(1B) | LENGTH(2B) | STREAMID(4B) | DATA(LENGTH)
VERSION: 1
CMD:
SYN(0)
FIN(1)
PSH(2)
NOP(3)
STREAMID: Randomly chosen number
Example
use ;
use ;
use *;
async