This commit contains a few refactorings, but the major goal is to remove the `Arc` that's stored inside of each `ReadinessStream` and `Scheduled` slot in the event loop. The original purpose of this `Arc` was to share the I/O object among the concrete handle itself and the event loop. The event loop would then change how the socket is registered over time and then deregister it when it gets a "shutdown request". Nowadays, however, once an I/O object is registered with the event loop it's never updated. Additionally, we don't actually need to call `deregister` but can rather just instead close the I/O object itself and let the kernel/event loop take care of the cleanup. All we need to do on deregistering is free up the slab entry. The major result of this commit is that I/O objects no longer need to be `Sync` (as they're not stored in an `Arc`). Instead they just need to be `Send + 'static` as one might otherwise expect. Along the way this also refactors a few pieces here and there to make more sense in this new scheme. The `ReadinessStream` type now has a type parameter indicating an owned reference to the I/O object it wraps. This can be accessed via the `get_ref` and `get_mut` methods. Additionally I/O tokens on the event loop are now a full-fledged `IoToken` type which we can change in the future if we need to.
futures-mio
Bindings to the mio crate implementing the futures-io and futures
abstractions.
Usage
First, add this to your Cargo.toml:
[dependencies]
futures-mio = { git = "https://github.com/alexcrichton/futures-rs" }
Next, add this to your crate:
extern crate futures_mio;
Examples
There are a few small examples showing off how to use this library:
What is futures-mio?
This crate is a connection futures, a zero-cost implementation of futures in
Rust, and mio, a crate for zero-cost asynchronous I/O, and futures-io,
abstractions for I/O on top of the futures crate. The types and structures
implemented in futures-mio implement Future and Stream traits as
appropriate. For example connecting a TCP stream returns a Future resolving
to a TCP stream, and a TCP listener implements a stream of TCP streams
(accepted connections).
This crate also provides facilities such as:
- TCP streams
- TCP listeners
- UDP sockets
- Timeouts
- Data owned and local to the event loop
- An
Executorimplementation for a futures'Task
The intention of futures-mio is to provide a concrete implementation for
crates built on top of futures-io. For example you can easily turn a TCP
stream into a TLS/SSL stream with the futures-tls crate or use the
combinators to compose working with data on sockets.
Check out the documentation for more information, and more coming here soon!
License
futures-mio is primarily distributed under the terms of both the MIT license
and the Apache License (Version 2.0), with portions covered by various BSD-like
licenses.
See LICENSE-APACHE, and LICENSE-MIT for details.