-
Notifications
You must be signed in to change notification settings - Fork 739
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
Poll selector #1602
Poll selector #1602
Changes from all commits
dae7fc0
e6151cf
9cae6f5
4430339
2acc95a
3ebbf05
a2d4448
1652f75
1f0292e
21850e8
2baaade
ef6b580
d09c48f
a366956
f44704a
ce45088
942f439
ecde672
976bf25
a2d5fd0
fa04dbc
9bd3c3c
b39cd6e
200dfb5
f2aea09
65c7153
ca105df
77e3250
6ea8066
aefc00a
2628894
1387b17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/ | ||
.cargo | ||
Cargo.lock | ||
target* | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,10 +1,26 @@ | ||||
use crate::{event, sys, Events, Interest, Token}; | ||||
use log::trace; | ||||
#[cfg(unix)] | ||||
use std::os::unix::io::{AsRawFd, RawFd}; | ||||
use std::time::Duration; | ||||
use std::{fmt, io}; | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit.
Suggested change
|
||||
#[cfg(all( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't repeat this |
||||
unix, | ||||
any( | ||||
target_os = "android", | ||||
target_os = "illumos", | ||||
target_os = "linux", | ||||
target_os = "redox", | ||||
target_os = "dragonfly", | ||||
target_os = "freebsd", | ||||
target_os = "ios", | ||||
target_os = "macos", | ||||
target_os = "netbsd", | ||||
target_os = "openbsd" | ||||
), | ||||
not(feature = "force-old-poll") | ||||
))] | ||||
use std::os::unix::io::{AsRawFd, RawFd}; | ||||
|
||||
/// Polls for readiness events on all registered values. | ||||
/// | ||||
/// `Poll` allows a program to monitor a large number of [`event::Source`]s, | ||||
|
@@ -412,7 +428,22 @@ impl Poll { | |||
} | ||||
} | ||||
|
||||
#[cfg(unix)] | ||||
#[cfg(all( | ||||
unix, | ||||
any( | ||||
target_os = "android", | ||||
target_os = "illumos", | ||||
target_os = "linux", | ||||
target_os = "redox", | ||||
target_os = "dragonfly", | ||||
target_os = "freebsd", | ||||
target_os = "ios", | ||||
target_os = "macos", | ||||
target_os = "netbsd", | ||||
target_os = "openbsd" | ||||
), | ||||
not(feature = "force-old-poll") | ||||
))] | ||||
impl AsRawFd for Poll { | ||||
fn as_raw_fd(&self) -> RawFd { | ||||
self.registry.as_raw_fd() | ||||
|
@@ -697,15 +728,45 @@ impl fmt::Debug for Registry { | |||
} | ||||
} | ||||
|
||||
#[cfg(unix)] | ||||
#[cfg(all( | ||||
unix, | ||||
any( | ||||
target_os = "android", | ||||
target_os = "illumos", | ||||
target_os = "linux", | ||||
target_os = "redox", | ||||
target_os = "dragonfly", | ||||
target_os = "freebsd", | ||||
target_os = "ios", | ||||
target_os = "macos", | ||||
target_os = "netbsd", | ||||
target_os = "openbsd" | ||||
), | ||||
not(feature = "force-old-poll") | ||||
))] | ||||
impl AsRawFd for Registry { | ||||
fn as_raw_fd(&self) -> RawFd { | ||||
self.selector.as_raw_fd() | ||||
} | ||||
} | ||||
|
||||
cfg_os_poll! { | ||||
#[cfg(unix)] | ||||
#[cfg(all( | ||||
unix, | ||||
any( | ||||
target_os = "android", | ||||
target_os = "illumos", | ||||
target_os = "linux", | ||||
target_os = "redox", | ||||
target_os = "dragonfly", | ||||
target_os = "freebsd", | ||||
target_os = "ios", | ||||
target_os = "macos", | ||||
target_os = "netbsd", | ||||
target_os = "openbsd" | ||||
), | ||||
not(feature = "force-old-poll") | ||||
))] | ||||
#[test] | ||||
pub fn as_raw_fd() { | ||||
let poll = Poll::new().unwrap(); | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ macro_rules! syscall { | |
|
||
cfg_os_poll! { | ||
mod selector; | ||
pub(crate) use self::selector::{event, Event, Events, Selector}; | ||
pub(crate) use self::selector::{event, Event, Events, Selector, IoSourceState}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to put this inside of |
||
|
||
mod sourcefd; | ||
pub use self::sourcefd::SourceFd; | ||
|
@@ -32,28 +32,6 @@ cfg_os_poll! { | |
pub use self::uds::SocketAddr; | ||
} | ||
|
||
cfg_io_source! { | ||
use std::io; | ||
|
||
// Both `kqueue` and `epoll` don't need to hold any user space state. | ||
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) | ||
} | ||
} | ||
} | ||
|
||
cfg_os_ext! { | ||
pub(crate) mod pipe; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ use crate::{event, Interest, Registry, Token}; | |
/// | ||
/// ``` | ||
/// # use std::io; | ||
/// # use std::io::Read; | ||
/// # | ||
/// # use mio::{Poll, Events, Interest, Token}; | ||
/// # use mio::unix::pipe; | ||
|
@@ -138,6 +139,15 @@ use crate::{event, Interest, Registry, Token}; | |
/// println!("Sender dropped!"); | ||
/// return Ok(()); | ||
/// }, | ||
/// PIPE_RECV => { | ||
/// // Some platforms only signal a read readines event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: s/readines/readiness/ |
||
/// println!("Pipe is readable due to dropped sender!"); | ||
/// | ||
/// // Reading from a closed pipe always returns Ok(0) | ||
/// let mut buf = [0; 1]; | ||
/// assert_eq!(receiver.read(&mut buf).ok(), Some(0)); | ||
/// return Ok(()); | ||
/// } | ||
/// _ => unreachable!(), | ||
/// } | ||
/// } | ||
|
@@ -163,7 +173,7 @@ pub fn new() -> io::Result<(Sender, Receiver)> { | |
} | ||
} | ||
|
||
#[cfg(any(target_os = "ios", target_os = "macos"))] | ||
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "haiku"))] | ||
unsafe { | ||
// For platforms that don't have `pipe2(2)` we need to manually set the | ||
// correct flags on the file descriptor. | ||
|
@@ -172,9 +182,7 @@ pub fn new() -> io::Result<(Sender, Receiver)> { | |
} | ||
|
||
for fd in &fds { | ||
if libc::fcntl(*fd, libc::F_SETFL, libc::O_NONBLOCK) != 0 | ||
|| libc::fcntl(*fd, libc::F_SETFD, libc::FD_CLOEXEC) != 0 | ||
{ | ||
if libc::fcntl(*fd, libc::F_SETFL, libc::O_NONBLOCK | libc::FD_CLOEXEC) != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As pointed out by @Thomasdezeeuw elsewhere: "This uses |
||
let err = io::Error::last_os_error(); | ||
// Don't leak file descriptors. Can't handle error though. | ||
let _ = libc::close(fds[0]); | ||
|
@@ -195,6 +203,7 @@ pub fn new() -> io::Result<(Sender, Receiver)> { | |
target_os = "macos", | ||
target_os = "illumos", | ||
target_os = "redox", | ||
target_os = "haiku", | ||
)))] | ||
compile_error!("unsupported target for `mio::unix::pipe`"); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not going to add a feature for this or support
poll
on any OS that has something better (e.g.epoll
orkqueue
). Mio is complex enough as-is it maintain with the matrix OSs architectures we're not getting selectors in the mix as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also be removed once this PR is ready, I currently use this to develop the
poll
selector on Linux because development on Haiku and the espidf is quite hard. I still run the tests for Haiku, but this allows me to iron out bugs on a system which is easy to develop for.TL;DR: Will be removed when PR is ready