{"id":48415104,"url":"https://github.com/black-binary/async-smux","last_synced_at":"2026-04-06T07:06:45.819Z","repository":{"id":115501641,"uuid":"303905865","full_name":"black-binary/async-smux","owner":"black-binary","description":"A lightweight asynchronous smux multiplexing library","archived":false,"fork":false,"pushed_at":"2025-04-25T15:51:55.000Z","size":117,"stargazers_count":57,"open_issues_count":0,"forks_count":19,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-25T16:50:45.819Z","etag":null,"topics":["async","async-smux","async-std","rust","smol","smux"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/black-binary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-10-14T04:49:35.000Z","updated_at":"2025-04-25T15:51:59.000Z","dependencies_parsed_at":"2024-11-30T18:20:09.373Z","dependency_job_id":"537f4792-6324-4c9b-89b1-e1342fff36a4","html_url":"https://github.com/black-binary/async-smux","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/black-binary/async-smux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/black-binary%2Fasync-smux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/black-binary%2Fasync-smux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/black-binary%2Fasync-smux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/black-binary%2Fasync-smux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/black-binary","download_url":"https://codeload.github.com/black-binary/async-smux/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/black-binary%2Fasync-smux/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31463018,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-smux","async-std","rust","smol","smux"],"created_at":"2026-04-06T07:06:44.360Z","updated_at":"2026-04-06T07:06:45.812Z","avatar_url":"https://github.com/black-binary.png","language":"Rust","readme":"# async-smux\n\n[crates.io](https://crates.io/crates/async_smux)\n\nA lightweight asynchronous [smux](https://github.com/xtaci/smux) (Simple MUltipleXing) library for smol/async-std and any async runtime compatible to `futures`.\n\n![img](https://raw.githubusercontent.com/xtaci/smux/master/mux.jpg)\n\n`async-smux` consumes a struct implementing `AsyncRead + AsyncWrite + Unpin + Send`, like `TcpStream` and `TlsStream`, to create a `Mux\u003cT\u003e` struct. And then you may spawn multiple `MuxStream\u003cT\u003e`s (up to 4294967295) over `Mux\u003cT\u003e`, which also implements `AsyncRead + AsyncWrite + Unpin + Send`.\n\n## Benchmark\n\nHere is a simple benchmarking result on my local machine, comparing to the original version smux (written in go).\n\n| Implementation    | Throughput (TCP) | Handshake  |\n| ----------------- | ---------------- | ---------- |\n| smux (go)         | 0.4854 GiB/s     | 17.070 K/s |\n| async-smux (rust) | 1.0550 GiB/s     | 81.774 K/s |\n\nRun `cargo bench` to test it by yourself. Check out `/benches` directory for more details.\n\n## Laziness\n\nNo thread or task will be spawned by this library. It just spawns a few `future`s. So it's totally runtime-independent.\n\n`Mux` and `MuxStream` are completely lazy and will DO NOTHING if you don't `poll()` them.\n\nAny polling operation, including `.read()` ,`.write()`, `accept()` and `connect()`, will push `Mux` and `MuxStream` working.\n\n## Specification\n\n```text\nVERSION(1B) | CMD(1B) | LENGTH(2B) | STREAMID(4B) | DATA(LENGTH)\n\nVERSION: 1\n\nCMD:\n    SYN(0)\n    FIN(1)\n    PSH(2)\n    NOP(3)\n\nSTREAMID: Randomly chosen number\n```\n\n## Example\n\n```rust\nuse async_smux::{Mux, MuxConfig};\nuse async_std::net::{TcpListener, TcpStream};\nuse async_std::prelude::*;\n\nasync fn echo_server() {\n    let listener = TcpListener::bind(\"0.0.0.0:12345\").await.unwrap();\n    let (stream, _) = listener.accept().await.unwrap();\n    let mux = Mux::new(stream, MuxConfig::default());\n    loop {\n        let mut mux_stream = mux.accept().await.unwrap();\n        let mut buf = [0u8; 1024];\n        let size = mux_stream.read(\u0026mut buf).await.unwrap();\n        mux_stream.write(\u0026buf[..size]).await.unwrap();\n    }\n}\n\nfn main() {\n    async_std::task::spawn(echo_server());\n    async_std::task::block_on(async {\n        smol::Timer::after(std::time::Duration::from_secs(1)).await;\n        let stream = TcpStream::connect(\"127.0.0.1:12345\").await.unwrap();\n        let mux = Mux::new(stream, MuxConfig::default());\n        for i in 0..100 {\n            let mut mux_stream = mux.connect().await.unwrap();\n            let mut buf = [0u8; 1024];\n            mux_stream.write(b\"hello\").await.unwrap();\n            let size = mux_stream.read(\u0026mut buf).await.unwrap();\n            let reply = String::from_utf8(buf[..size].to_vec()).unwrap();\n            println!(\"{}: {}\", i, reply);\n        }\n    });\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblack-binary%2Fasync-smux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblack-binary%2Fasync-smux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblack-binary%2Fasync-smux/lists"}