-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io: remove mio
from the public API.
#2728
Comments
Another option would be to move those types into a separate crate |
I believe you are referring to The biggest impact of this proposal would be that one would no longer be able to take a I believe that this will cause a bit of short/medium term turmoil but the |
I really would like "proper" windows async, that is some form of overlapped file IO, rather than threadpooled sync IO. IPC with named pipes in particular basically requires overlapped file IO, and I found it very hard to wrap manually wrapped file APIs so that they could be integrated with other tokio async APIs - my current code feels incredibly fragile. Not sure what that would look like if you really want to be extensible in an |
This refactors I/O registration in a few ways: - Cleans up the cached readiness in `PollEvented`. This cache used to be helpful when readiness was a linked list of `*mut Node`s in `Registration`. Previous refactors have turned `Registration` into just an `AtomicUsize` holding the current readiness, so the cache is just extra work and complexity. Gone. - Polling the `Registration` for readiness now gives a `ReadyEvent`, which includes the driver tick. This event must be passed back into `clear_readiness`, so that the readiness is only cleared from `Registration` if the tick hasn't changed. Previously, it was possible to clear the readiness even though another thread had *just* polled the driver and found the socket ready again. - Registration now also contains an `async fn readiness`, which stores wakers in an instrusive linked list. This allows an unbounded number of tasks to register for readiness (previously, only 1 per direction (read and write)). By using the intrusive linked list, there is no concern of leaking the storage of the wakers, since they are stored inside the `async fn` and released when the future is dropped. - Registration retains a `poll_readiness(Direction)` method, to support `AsyncRead` and `AsyncWrite`. They aren't able to use `async fn`s, and so there are 2 reserved slots for those methods. - IO types where it makes sense to have multiple tasks waiting on them now take advantage of this new `async fn readiness`, such as `UdpSocket` and `UnixDatagram`. Additionally, this makes the `io-driver` "feature" internal-only (no longer documented, not part of public API), and adds a second internal-only feature, `io-readiness`, to group together linked list part of registration that is only used by some of the IO types. After a bit of discussion, changing stream-based transports (like `TcpStream`) to have `async fn read(&self)` is punted, since that is likely too easy of a footgun to activate. Refs: #2779, #2728
I've started work on this issue. A couple thoughts:
|
|
This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: tokio-rs#2728
This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: tokio-rs#2728
This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: tokio-rs#2728
Relevant to the unsafety of |
This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: tokio-rs#2728
Curious around the motivation against having If the contract is such that ownership of the fd is taken, it will largely do the right thing by default when dropped. We already have the cc @bdonlan since you're working on this :) |
This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: tokio-rs#2728
This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: tokio-rs#2728
A PR for To close this issue, we need to audit |
I scanned and it looks like this is done. |
This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: tokio-rs#2728
* io: Add AsyncFd This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: #2728 * driver: fix shutdown notification unreliability Previously, there was a race window in which an IO driver shutting down could fail to notify ScheduledIo instances of this state; in particular, notification of outstanding ScheduledIo registrations was driven by `Driver::drop`, but registrations bypass `Driver` and go directly to a `Weak<Inner>`. The `Driver` holds the `Arc<Inner>` keeping `Inner` alive, but it's possible that a new handle could be registered (or a new readiness future created for an existing handle) after the `Driver::drop` handler runs and prior to `Inner` being dropped. This change fixes this in two parts: First, notification of outstanding ScheduledIo handles is pushed down into the drop method of `Inner` instead, and, second, we add state to ScheduledIo to ensure that we remember that the IO driver we're bound to has shut down after the initial shutdown notification, so that subsequent readiness future registrations can immediately return (instead of potentially blocking indefinitely). Fixes: #2924
Summary
Remove
mio
types from the Tokio public API. In practice, this means removingRegistration
andPollEvented
. Some users currently depend on these types in order to integrate custom resources with Tokio. Instead of providing hook points based onmio
, we would provide platform-specific "low level" resource types. For example, on *nix systems, we could provide anAsyncFd
type that provides access to readiness notifications.Motivation
Tokio cannot include public API dependencies on third party crates that do not match Tokio's stability guarantees. The Mio crate is not yet at a 1.0 release. We would like to be able to release Tokio 1.0 without blocking on Mio for 1.0. Additionally, we may want to change the low-level implementation details. For example, we may wish to switch the underlying implementation to an
io_uring
based backend or we may wish to provide windows integration directly instead of using the Mio compatibility layer.Given the open questions, the safest path forward is to decouple Tokio from Mio at this point in time.
Proposal
The
PollEvented
andRegistration
types are made private. In order to provide the ability to integrate with Tokio, platform-specific low-level resource types are provided. On *nix platforms, anAsyncFd
type is provided.Usage would look something like this:
This would only provide extensibility on *nix platforms. Extending Windows platforms would require a completely different API. As of now, Mio does not have a strategy for extending windows platforms. We would need to wait until one is developed.
The text was updated successfully, but these errors were encountered: