Skip to content

io: remove mio from the public API. #2728

@carllerche

Description

@carllerche

Summary

Remove mio types from the Tokio public API. In practice, this means removing Registration and PollEvented. Some users currently depend on these types in order to integrate custom resources with Tokio. Instead of providing hook points based on mio, we would provide platform-specific "low level" resource types. For example, on *nix systems, we could provide an AsyncFd 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 and Registration 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, an AsyncFd type is provided.

struct AsyncFd { ... }

impl AsyncFd {
    // Create a new `AsyncFd`. This registers the FD w/ the io-driver with the
    // given `Interest`.
    pub fn new(fd: RawFd, interest: Interest) -> AsyncFd;

    // Awaits for a readiness event covering any of the given `Interest`. The
    // `Interest` provided here must be a subset of the `Interest` supplied to
    // `new`.
    pub async fn readiness(&self, interest: Interest) -> io::Result<Readiness>;
}

struct Interest(mio::Interest);

struct Readiness(mio::Readiness);

Usage would look something like this:

let interest = Interest::READABLE
    .add(Interest::WRITEABLE);

let my_fd = AsyncFd::new(fd, interest);

// Await only *read* interest
my_fd.readiness(Interest::READABLE).await;

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-proposalCategory: a proposal and request for commentsM-ioModule: tokio/io

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions