From 81beb445659ff99b91cfce679ca63d78d23c692d Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 21 May 2017 10:24:08 -0600 Subject: [PATCH 1/3] POSIX AIO support, try 2 Support POSIX AIO, post-01635df . A concrete implementation will be added by the mio-aio and tokio-file crates --- Cargo.toml | 2 +- src/reactor/mod.rs | 65 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fab1172f3..b3a06a6fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ appveyor = { repository = "alexcrichton/tokio-core" } [dependencies] bytes = "0.4" log = "0.3" -mio = "0.6.7" +mio = { git = "https://github.com/carllerche/mio", rev = "d8576d9" } scoped-tls = "0.1.0" slab = "0.3" iovec = "0.1" diff --git a/src/reactor/mod.rs b/src/reactor/mod.rs index e2b509583..e06b65cc3 100644 --- a/src/reactor/mod.rs +++ b/src/reactor/mod.rs @@ -469,7 +469,8 @@ impl Inner { mio::Token(TOKEN_START + entry.index() * 2), mio::Ready::readable() | mio::Ready::writable() | - platform::hup(), + platform::hup() | + platform::aio(), mio::PollOpt::edge())); Ok((sched.readiness.clone(), entry.insert(sched).index())) } @@ -747,7 +748,7 @@ impl FnBox for F { } fn read_ready() -> mio::Ready { - mio::Ready::readable() | platform::hup() + mio::Ready::readable() | platform::hup() | platform::aio() } const READ: usize = 1 << 0; @@ -775,11 +776,18 @@ fn usize2ready(bits: usize) -> mio::Ready { ready | platform::usize2ready(bits) } -#[cfg(unix)] +#[cfg(all(unix, not(any(target_os = "freebsd", target_os = "dragonfly"))))] mod platform { use mio::Ready; use mio::unix::UnixReady; + pub fn aio() -> Ready { + // Even though some of these platforms define EVFILT_AIO, they + // don't implement it with their reactors, so there's no point + // to using it. + Ready::empty() + } + pub fn hup() -> Ready { UnixReady::hup().into() } @@ -811,10 +819,61 @@ mod platform { } } +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +mod platform { + use mio::Ready; + use mio::unix::UnixReady; + + pub fn aio() -> Ready { + UnixReady::aio().into() + } + + pub fn hup() -> Ready { + UnixReady::hup().into() + } + + const HUP: usize = 1 << 2; + const ERROR: usize = 1 << 3; + const AIO: usize = 1 << 4; + + pub fn ready2usize(ready: Ready) -> usize { + let ready = UnixReady::from(ready); + let mut bits = 0; + if ready.is_aio() { + bits |= AIO; + } + if ready.is_error() { + bits |= ERROR; + } + if ready.is_hup() { + bits |= HUP; + } + bits + } + + pub fn usize2ready(bits: usize) -> Ready { + let mut ready = UnixReady::from(Ready::empty()); + if bits & AIO != 0 { + ready.insert(UnixReady::aio()); + } + if bits & HUP != 0 { + ready.insert(UnixReady::hup()); + } + if bits & ERROR != 0 { + ready.insert(UnixReady::error()); + } + ready.into() + } +} + #[cfg(windows)] mod platform { use mio::Ready; + pub fn aio() -> Ready { + Ready::empty() + } + pub fn hup() -> Ready { Ready::empty() } From 42f73cb0ecb7975cb0eaa76a4e0f96a949f32846 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 21 May 2017 11:01:48 -0600 Subject: [PATCH 2/3] Revert changes to read_ready and add platform::all() --- src/reactor/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/reactor/mod.rs b/src/reactor/mod.rs index e06b65cc3..9b6523e83 100644 --- a/src/reactor/mod.rs +++ b/src/reactor/mod.rs @@ -469,8 +469,7 @@ impl Inner { mio::Token(TOKEN_START + entry.index() * 2), mio::Ready::readable() | mio::Ready::writable() | - platform::hup() | - platform::aio(), + platform::all(), mio::PollOpt::edge())); Ok((sched.readiness.clone(), entry.insert(sched).index())) } @@ -748,7 +747,7 @@ impl FnBox for F { } fn read_ready() -> mio::Ready { - mio::Ready::readable() | platform::hup() | platform::aio() + mio::Ready::readable() | platform::hup() } const READ: usize = 1 << 0; @@ -788,6 +787,10 @@ mod platform { Ready::empty() } + pub fn all() -> Ready { + hup() + } + pub fn hup() -> Ready { UnixReady::hup().into() } @@ -828,6 +831,10 @@ mod platform { UnixReady::aio().into() } + pub fn all() -> Ready { + hup() | aio() + } + pub fn hup() -> Ready { UnixReady::hup().into() } @@ -874,6 +881,11 @@ mod platform { Ready::empty() } + pub fn all() -> Ready { + // No platform-specific Readinesses for Windows + Ready::empty() + } + pub fn hup() -> Ready { Ready::empty() } From 363e15f36cb5791d20433360a1f50a455392f991 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Wed, 7 Jun 2017 22:36:32 -0600 Subject: [PATCH 3/3] Respond to alexchrichton's comments * Combine the FreeBSD/Dragonfly platform with the other Unix platform * Remove the Windows platform::aio method * Update deps --- Cargo.toml | 4 ++-- src/reactor/mod.rs | 53 +--------------------------------------------- 2 files changed, 3 insertions(+), 54 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b3a06a6fd..b4819cdf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,12 +19,12 @@ appveyor = { repository = "alexcrichton/tokio-core" } [dependencies] bytes = "0.4" log = "0.3" -mio = { git = "https://github.com/carllerche/mio", rev = "d8576d9" } +mio = "0.6.9" scoped-tls = "0.1.0" slab = "0.3" iovec = "0.1" tokio-io = "0.1" -futures = "0.1.11" +futures = "0.1.14" [dev-dependencies] env_logger = { version = "0.3", default-features = false } diff --git a/src/reactor/mod.rs b/src/reactor/mod.rs index 9b6523e83..b3e54907f 100644 --- a/src/reactor/mod.rs +++ b/src/reactor/mod.rs @@ -775,54 +775,7 @@ fn usize2ready(bits: usize) -> mio::Ready { ready | platform::usize2ready(bits) } -#[cfg(all(unix, not(any(target_os = "freebsd", target_os = "dragonfly"))))] -mod platform { - use mio::Ready; - use mio::unix::UnixReady; - - pub fn aio() -> Ready { - // Even though some of these platforms define EVFILT_AIO, they - // don't implement it with their reactors, so there's no point - // to using it. - Ready::empty() - } - - pub fn all() -> Ready { - hup() - } - - pub fn hup() -> Ready { - UnixReady::hup().into() - } - - const HUP: usize = 1 << 2; - const ERROR: usize = 1 << 3; - - pub fn ready2usize(ready: Ready) -> usize { - let ready = UnixReady::from(ready); - let mut bits = 0; - if ready.is_error() { - bits |= ERROR; - } - if ready.is_hup() { - bits |= HUP; - } - bits - } - - pub fn usize2ready(bits: usize) -> Ready { - let mut ready = UnixReady::from(Ready::empty()); - if bits & HUP != 0 { - ready.insert(UnixReady::hup()); - } - if bits & ERROR != 0 { - ready.insert(UnixReady::error()); - } - ready.into() - } -} - -#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +#[cfg(unix)] mod platform { use mio::Ready; use mio::unix::UnixReady; @@ -877,10 +830,6 @@ mod platform { mod platform { use mio::Ready; - pub fn aio() -> Ready { - Ready::empty() - } - pub fn all() -> Ready { // No platform-specific Readinesses for Windows Ready::empty()