{"id":13407557,"url":"https://github.com/tokio-rs/mio","last_synced_at":"2025-05-12T16:25:16.163Z","repository":{"id":19875061,"uuid":"23138984","full_name":"tokio-rs/mio","owner":"tokio-rs","description":"Metal I/O library for Rust.","archived":false,"fork":false,"pushed_at":"2025-04-15T13:28:51.000Z","size":3341,"stargazers_count":6604,"open_issues_count":26,"forks_count":770,"subscribers_count":127,"default_branch":"master","last_synced_at":"2025-05-05T14:18:56.988Z","etag":null,"topics":["asynchronous","networking","non-blocking","rust"],"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/tokio-rs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-08-20T06:52:12.000Z","updated_at":"2025-05-03T14:16:41.000Z","dependencies_parsed_at":"2023-07-15T15:35:14.588Z","dependency_job_id":"b357760f-216c-4f3b-a749-88dc10ae4288","html_url":"https://github.com/tokio-rs/mio","commit_stats":{"total_commits":1446,"total_committers":239,"mean_commits":6.050209205020921,"dds":0.686030428769018,"last_synced_commit":"cbb53c71a29868f4decfcb70d16a926a956f3a2d"},"previous_names":["carllerche/mio"],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Fmio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Fmio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Fmio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Fmio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tokio-rs","download_url":"https://codeload.github.com/tokio-rs/mio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253650947,"owners_count":21942232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["asynchronous","networking","non-blocking","rust"],"created_at":"2024-07-30T20:00:42.884Z","updated_at":"2025-05-12T16:25:16.140Z","avatar_url":"https://github.com/tokio-rs.png","language":"Rust","funding_links":[],"categories":["I/O Abstractions","Libraries","Rust","库 Libraries","库","Rust 程序设计","IO","异步（Asynchronous）","Repository app"],"sub_categories":["Asynchronous","异步 Asynchronous","异步","网络服务_其他","Network I/O","天文（Astronomy）"],"readme":"# Mio – Metal I/O\n\nMio is a fast, low-level I/O library for Rust focusing on non-blocking APIs and\nevent notification for building high performance I/O apps with as little\noverhead as possible over the OS abstractions.\n\n[![Crates.io][crates-badge]][crates-url]\n[![MIT licensed][mit-badge]][mit-url]\n[![Build Status][actions-badge]][actions-url]\n[![Build Status][cirrus-badge]][cirrus-url]\n\n[crates-badge]: https://img.shields.io/crates/v/mio.svg\n[crates-url]: https://crates.io/crates/mio\n[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[mit-url]: LICENSE\n[actions-badge]: https://github.com/tokio-rs/mio/workflows/CI/badge.svg\n[actions-url]: https://github.com/tokio-rs/mio/actions?query=workflow%3ACI+branch%3Amaster\n[cirrus-badge]: https://api.cirrus-ci.com/github/tokio-rs/mio.svg\n[cirrus-url]: https://cirrus-ci.com/github/tokio-rs/mio\n\n**API documentation**\n\n* [v1](https://docs.rs/mio/^1)\n* [v0.8](https://docs.rs/mio/^0.8)\n\nThis is a low level library, if you are looking for something easier to get\nstarted with, see [Tokio](https://tokio.rs).\n\n## Usage\n\nTo use `mio`, first add this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nmio = \"1\"\n```\n\nNext we can start using Mio. The following is quick introduction using\n`TcpListener` and `TcpStream`. Note that `features = [\"os-poll\", \"net\"]` must be\nspecified for this example.\n\n```rust\nuse std::error::Error;\n\nuse mio::net::{TcpListener, TcpStream};\nuse mio::{Events, Interest, Poll, Token};\n\n// Some tokens to allow us to identify which event is for which socket.\nconst SERVER: Token = Token(0);\nconst CLIENT: Token = Token(1);\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n    // Create a poll instance.\n    let mut poll = Poll::new()?;\n    // Create storage for events.\n    let mut events = Events::with_capacity(128);\n\n    // Setup the server socket.\n    let addr = \"127.0.0.1:13265\".parse()?;\n    let mut server = TcpListener::bind(addr)?;\n    // Start listening for incoming connections.\n    poll.registry()\n        .register(\u0026mut server, SERVER, Interest::READABLE)?;\n\n    // Setup the client socket.\n    let mut client = TcpStream::connect(addr)?;\n    // Register the socket.\n    poll.registry()\n        .register(\u0026mut client, CLIENT, Interest::READABLE | Interest::WRITABLE)?;\n\n    // Start an event loop.\n    loop {\n        // Poll Mio for events, blocking until we get an event.\n        poll.poll(\u0026mut events, None)?;\n\n        // Process each event.\n        for event in events.iter() {\n            // We can use the token we previously provided to `register` to\n            // determine for which socket the event is.\n            match event.token() {\n                SERVER =\u003e {\n                    // If this is an event for the server, it means a connection\n                    // is ready to be accepted.\n                    //\n                    // Accept the connection and drop it immediately. This will\n                    // close the socket and notify the client of the EOF.\n                    let connection = server.accept();\n                    drop(connection);\n                }\n                CLIENT =\u003e {\n                    if event.is_writable() {\n                        // We can (likely) write to the socket without blocking.\n                    }\n\n                    if event.is_readable() {\n                        // We can (likely) read from the socket without blocking.\n                    }\n\n                    // Since the server just shuts down the connection, let's\n                    // just exit from our event loop.\n                    return Ok(());\n                }\n                // We don't expect any events with tokens other than those we provided.\n                _ =\u003e unreachable!(),\n            }\n        }\n    }\n}\n```\n\n## Features\n\n* Non-blocking TCP, UDP, UDS\n* I/O event queue backed by epoll, kqueue, and IOCP\n* Zero allocations at runtime\n* Platform specific extensions\n\n## Non-goals\n\nThe following are specifically omitted from Mio and are left to the user\nor higher-level libraries.\n\n* File operations\n* Thread pools / multi-threaded event loop\n* Timers\n\n## Platforms\n\nCurrently supported platforms:\n\n* Android (API level 21)\n* DragonFly BSD\n* FreeBSD\n* Linux\n* NetBSD\n* OpenBSD\n* Windows\n* iOS\n* macOS\n\nMio can handle interfacing with each of the event systems of the aforementioned\nplatforms. The details of their implementation are further discussed in the\n`Poll` type of the API documentation (see above).\n\nMio generally supports the same versions of the above mentioned platforms as\nRust the language (rustc) does, unless otherwise noted.\n\nThe Windows implementation for polling sockets is using the [wepoll] strategy.\nThis uses the Windows AFD system to access socket readiness events.\n\n[wepoll]: https://github.com/piscisaureus/wepoll\n\n### Unsupported\n\n* Wine, see [issue #1444]\n\n[issue #1444]: https://github.com/tokio-rs/mio/issues/1444\n\n## MSRV Policy\n\nThe MSRV (Minimum Supported Rust Version) is fixed for a given minor (1.x)\nversion. However it can be increased when bumping minor versions, i.e. going\nfrom 1.0 to 1.1 allows us to increase the MSRV. Users unable to increase their\nRust version can use an older minor version instead. Below is a list of Mio versions\nand their MSRV:\n\n * v0.8: Rust 1.46.\n * v1.0: Rust 1.70.\n\nNote however that Mio also has dependencies, which might have different MSRV\npolicies. We try to stick to the above policy when updating dependencies, but\nthis is not always possible.\n\n## Unsupported flags\n\nMio uses different implementations to support the same functionality depending\non the platform. Mio generally uses the \"best\" implementation possible, where\n\"best\" usually means most efficient for Mio's use case. However this means that\nthe implementation is often specific to a limited number of platforms, meaning\nwe often have multiple implementations for the same functionality. In some cases\nit might be required to not use the \"best\" implementation, but another\nimplementation Mio supports (on other platforms). **Mio does not officially\nsupport secondary implementations on platforms**, however we do have various cfg\nflags to force another implementation for these situations.\n\nCurrent flags:\n * `mio_unsupported_force_poll_poll`, uses an implementation based on `poll(2)`\n   for `mio::Poll`.\n * `mio_unsupported_force_waker_pipe`, uses an implementation based on `pipe(2)`\n   for `mio::Waker`.\n\n**Again, Mio does not officially supports this**. Furthermore these flags may\ndisappear in the future.\n\n## Community\n\nA group of Mio users hang out on [Discord], this can be a good place to go for\nquestions. It's also possible to open a [new issue on GitHub] to ask questions,\nreport bugs or suggest new features.\n\n[Discord]: https://discord.gg/tokio\n[new issue on GitHub]: https://github.com/tokio-rs/mio/issues/new\n\n## Contributing\n\nInterested in getting involved? We would love to help you! For simple\nbug fixes, just submit a PR with the fix and we can discuss the fix\ndirectly in the PR. If the fix is more complex, start with an issue.\n\nIf you want to propose an API change, create an issue to start a\ndiscussion with the community. Also, feel free to talk with us in Discord.\n\nFinally, be kind. We support the [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokio-rs%2Fmio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftokio-rs%2Fmio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokio-rs%2Fmio/lists"}