Skip to content
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

Initial support for poll-based backend #1687

Merged
merged 24 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a6edda7
Implement poll-based backend
jasta Jul 7, 2023
496bc0e
Fixed syntax error in ci workflow
jasta Jul 24, 2023
2889557
Fix build break with --no-default-features --features net
jasta Jul 25, 2023
1813a63
Fix mio_unsupported_force_poll_poll release builds
jasta Jul 25, 2023
cfc13bc
Fix non-conforming usage of log::trace
jasta Jul 25, 2023
ca576a5
Run rustfmt
jasta Jul 25, 2023
ad3cc96
Update src/sys/unix/selector/poll.rs
jasta Jul 26, 2023
4b8a935
poll: Optimize register corner case
jasta Jul 26, 2023
037a538
poll: Slight change to error message consistency
jasta Jul 26, 2023
5fda03c
poll: Fix event copy/paste debug_details formatting
jasta Jul 26, 2023
f7d0885
poll: Manually fix missing rustfmt case
jasta Jul 26, 2023
a4c72a8
poll: Fix try_clone not carrying has_waker state forward
jasta Jul 26, 2023
1de715c
poll: Simplify and optimize pending_wake_tokens to use a singular Token
jasta Jul 26, 2023
0ce239e
poll: No longer special case poll returning 0 and redundantly checkin…
jasta Jul 26, 2023
e15d449
poll: Copy timeout determination logic from epoll impl
jasta Jul 26, 2023
c61d221
poll: Clarify nested poll loop behaviour slightly
jasta Jul 26, 2023
fa88f19
poll: Further clarify nested poll loop behaviour
jasta Jul 26, 2023
185dbf5
poll: rename notified_events for consistency
jasta Jul 26, 2023
71c635f
poll: Minor documentation for pending_wake_token behaviour
jasta Jul 26, 2023
0970313
poll: Document design choice quirks in comments
jasta Jul 30, 2023
fc0a153
poll: Avoid early return on error in deregister_all
jasta Jul 30, 2023
8570ec9
poll: Rerun rustfmt
jasta Jul 30, 2023
189a117
poll: Fix target_os="wasi" compilation error
jasta Jul 30, 2023
a7c41ee
poll: Fix MSRV by not using std::os::fd
jasta Jul 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ jobs:
run: cargo test --all-features
- name: Tests release build
run: cargo test --release --all-features
TestPoll:
runs-on: ubuntu-latest
jasta marked this conversation as resolved.
Show resolved Hide resolved
timeout-minutes: 10
env:
RUSTFLAGS: "--cfg mio_unsupported_force_poll_poll"
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Tests
run: cargo test --all-features
- name: Tests release build
run: cargo test --release --all-features
MinimalVersions:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
Expand Down Expand Up @@ -133,6 +145,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- Test
- TestPoll
- MinimalVersions
- MSRV
- Nightly
Expand Down
12 changes: 5 additions & 7 deletions src/io_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ where
) -> io::Result<()> {
#[cfg(debug_assertions)]
self.selector_id.associate(registry)?;
registry
.selector()
.register(self.inner.as_raw_fd(), token, interests)
self.state
.register(registry, token, interests, self.inner.as_raw_fd())
}

fn reregister(
Expand All @@ -155,15 +154,14 @@ where
) -> io::Result<()> {
#[cfg(debug_assertions)]
self.selector_id.check_association(registry)?;
registry
.selector()
.reregister(self.inner.as_raw_fd(), token, interests)
self.state
.reregister(registry, token, interests, self.inner.as_raw_fd())
}

fn deregister(&mut self, registry: &Registry) -> io::Result<()> {
#[cfg(debug_assertions)]
self.selector_id.remove_association(registry)?;
registry.selector().deregister(self.inner.as_raw_fd())
self.state.deregister(registry, self.inner.as_raw_fd())
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/poll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{event, sys, Events, Interest, Token};
#[cfg(unix)]
#[cfg(all(unix, not(mio_unsupported_force_poll_poll)))]
use std::os::unix::io::{AsRawFd, RawFd};
use std::time::Duration;
use std::{fmt, io};
Expand Down Expand Up @@ -411,7 +411,7 @@ impl Poll {
}
}

#[cfg(unix)]
#[cfg(all(unix, not(mio_unsupported_force_poll_poll)))]
impl AsRawFd for Poll {
fn as_raw_fd(&self) -> RawFd {
self.registry.as_raw_fd()
Expand Down Expand Up @@ -696,15 +696,18 @@ impl fmt::Debug for Registry {
}
}

#[cfg(unix)]
#[cfg(all(unix, not(mio_unsupported_force_poll_poll)))]
impl AsRawFd for Registry {
fn as_raw_fd(&self) -> RawFd {
self.selector.as_raw_fd()
}
}

cfg_os_poll! {
#[cfg(unix)]
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll)
))]
#[test]
pub fn as_raw_fd() {
let poll = Poll::new().unwrap();
Expand Down
31 changes: 30 additions & 1 deletion src/sys/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ cfg_io_source! {
use std::io;
#[cfg(windows)]
use std::os::windows::io::RawSocket;
#[cfg(unix)]
use std::os::unix::io::RawFd;

#[cfg(windows)]
#[cfg(any(windows, unix))]
use crate::{Registry, Token, Interest};

pub(crate) struct IoSourceState;
Expand All @@ -44,6 +46,33 @@ cfg_io_source! {
}
}

#[cfg(unix)]
impl IoSourceState {
pub fn register(
&mut self,
_: &Registry,
_: Token,
_: Interest,
_: RawFd,
) -> io::Result<()> {
os_required!()
}

pub fn reregister(
&mut self,
_: &Registry,
_: Token,
_: Interest,
_: RawFd,
) -> io::Result<()> {
os_required!()
}

pub fn deregister(&mut self, _: &Registry, _: RawFd) -> io::Result<()> {
os_required!()
}
}

#[cfg(windows)]
impl IoSourceState {
pub fn register(
Expand Down
68 changes: 54 additions & 14 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,65 @@ cfg_os_poll! {
}

cfg_io_source! {
use std::io;

// Both `kqueue` and `epoll` don't need to hold any user space state.
pub(crate) struct IoSourceState;
#[cfg(not(mio_unsupported_force_poll_poll))]
mod stateless_io_source {
use std::io;
use std::os::unix::io::RawFd;
use crate::Registry;
use crate::Token;
use crate::Interest;

impl IoSourceState {
pub fn new() -> IoSourceState {
IoSourceState
}
pub(crate) struct IoSourceState;

impl IoSourceState {
pub fn new() -> IoSourceState {
IoSourceState
}

pub fn do_io<T, F, R>(&self, f: F, io: &T) -> io::Result<R>
where
F: FnOnce(&T) -> io::Result<R>,
{
// We don't hold state, so we can just call the function and
// return.
f(io)
}

pub fn do_io<T, F, R>(&self, f: F, io: &T) -> io::Result<R>
where
F: FnOnce(&T) -> io::Result<R>,
{
// We don't hold state, so we can just call the function and
// return.
f(io)
pub fn register(
&mut self,
registry: &Registry,
token: Token,
interests: Interest,
fd: RawFd,
) -> io::Result<()> {
// Pass through, we don't have any state
registry.selector().register(fd, token, interests)
}

pub fn reregister(
&mut self,
registry: &Registry,
token: Token,
interests: Interest,
fd: RawFd,
) -> io::Result<()> {
// Pass through, we don't have any state
registry.selector().reregister(fd, token, interests)
}

pub fn deregister(&mut self, registry: &Registry, fd: RawFd) -> io::Result<()> {
// Pass through, we don't have any state
registry.selector().deregister(fd)
}
}
}

#[cfg(not(mio_unsupported_force_poll_poll))]
pub(crate) use self::stateless_io_source::IoSourceState;

#[cfg(mio_unsupported_force_poll_poll)]
pub(crate) use self::selector::IoSourceState;
}

cfg_os_ext! {
Expand Down
74 changes: 46 additions & 28 deletions src/sys/unix/selector/mod.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
#[cfg(any(
target_os = "android",
target_os = "illumos",
target_os = "linux",
target_os = "redox",
#[cfg(all(
not(mio_unsupported_force_poll_poll),
any(
target_os = "android",
target_os = "illumos",
target_os = "linux",
target_os = "redox",
)
))]
mod epoll;

#[cfg(any(
target_os = "android",
target_os = "illumos",
target_os = "linux",
target_os = "redox",
#[cfg(all(
not(mio_unsupported_force_poll_poll),
any(
target_os = "android",
target_os = "illumos",
target_os = "linux",
target_os = "redox",
)
))]
pub(crate) use self::epoll::{event, Event, Events, Selector};

#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "tvos",
target_os = "watchos",
#[cfg(mio_unsupported_force_poll_poll)]
mod poll;

#[cfg(mio_unsupported_force_poll_poll)]
pub(crate) use self::poll::{event, Event, Events, IoSourceState, Selector};

#[cfg(all(
not(mio_unsupported_force_poll_poll),
any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "tvos",
target_os = "watchos",
)
))]
mod kqueue;

#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "tvos",
target_os = "watchos",
#[cfg(all(
not(mio_unsupported_force_poll_poll),
any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "tvos",
target_os = "watchos",
),
))]
pub(crate) use self::kqueue::{event, Event, Events, Selector};

Expand Down
Loading