-
Notifications
You must be signed in to change notification settings - Fork 673
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
add poll module in Android #672
Conversation
Good find. Could you also enable the poll tests for Android in test/test.rs ? |
Actually |
Also you'll want to change |
I included the module and the test unconditionally. |
There is an issue on FreeBSD, seem that the same symbols in rust-lang/libc#663 should be added to FreeBSD and DragonFly. I'll update that. |
85f1e2e
to
d8d3ab9
Compare
Should be good to merge now. |
@ndusart We're waiting for In the mean time can you add a CHANGELOG entry for this? I think putting it under the Added section makes sense since this is just an exposure of more functionality on some platforms, versus a change in an actual API. |
CHANGELOG.md
Outdated
@@ -22,6 +22,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |||
and nix::Error::UnsupportedOperation}` | |||
([#614](https://github.com/nix-rust/nix/pull/614)) | |||
- Added `cfmakeraw`, `cfsetspeed`, and `tcgetsid`. ([#527](https://github.com/nix-rust/nix/pull/527)) | |||
- Added `nix::poll` module for all platforms |
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.
Can you also state that ppoll
was added for FreeBSD, DragonflyBSD?
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.
Done
This needs a rebase. I'd also like to ask if you could, as part of this PR, whip up some documentation for this module now that it's supported for all platforms. It'd be much appreciated! |
src/poll.rs
Outdated
@@ -1,19 +1,30 @@ | |||
#[cfg(any(target_os = "linux", target_os = "android"))] | |||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "dragonfly"))] |
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.
Can you alphabetize the list of target OSes here since you're already modifying it?
src/poll.rs
Outdated
use sys::time::TimeSpec; | ||
#[cfg(any(target_os = "linux", target_os = "android"))] | ||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "dragonfly"))] |
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.
Can you alphabetize the list of target OSes here since you're already modifying it?
src/poll.rs
Outdated
/// pthread_sigmask(SIG_SETMASK, &origmask, NULL); | ||
/// ``` | ||
/// | ||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "dragonfly"))] |
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.
Can you alphabetize the list of target OSes here since you're already modifying it?
src/poll.rs
Outdated
@@ -23,26 +34,81 @@ impl PollFd { | |||
} | |||
} | |||
|
|||
/// Returns the events that occured in the last call to `poll` or `ppoll`. | |||
pub fn revents(&self) -> Option<EventFlags> { | |||
EventFlags::from_bits(self.pollfd.revents) | |||
} | |||
} | |||
|
|||
libc_bitflags! { | |||
pub flags EventFlags: libc::c_short { |
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.
The bitflag itself needs a doccomment above this line.
@@ -53,7 +119,32 @@ pub fn poll(fds: &mut [PollFd], timeout: libc::c_int) -> Result<libc::c_int> { | |||
Errno::result(res) | |||
} | |||
|
|||
#[cfg(any(target_os = "linux", target_os = "android"))] | |||
/// `ppoll()` allows an application to safely wait until either a file |
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.
Let's try to shorten this a bit so it looks better in the docs. The man page starts with "wait for some event on a file descriptor". I think that's descriptive and succinct and I suggest you use that here instead.
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.
Ok, I wanted to focus on the difference between poll
and ppoll
. Should I just put the first line of man, and redirect to the web page for more info ?
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.
Distinguishing them would be good, I just wanted the description to be a little shorter so I grabbed it from the man page. Maybe instead say "Like poll()
but can also wait for signals". How's that sound?
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.
poll
returns also on signals but the caller do not control what. But I agree that something like "Like poll()
but let you precise what signals may interrupt it" is enough. I'll change that.
src/poll.rs
Outdated
/// This is a wrapper around `libc::pollfd`. | ||
/// | ||
/// It's meant to be used as an argument to the [`poll`](fn.poll.html) and | ||
/// [`ppoll`](fn.ppoll.html) functions to specify the events of interested |
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.
"interest"
Thanks for the docs, it looks a lot better! There's some minor things to clean up here, but nothing major. |
The requested changes have been made. |
@Susurrus does this PR seem ok ? |
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.
Just some minor grammar/documentation changes. Then this is ready to roll I think. Thanks for your hard work on the docs, definitely helps me understand this functionality!
src/poll.rs
Outdated
/// This is a wrapper around `libc::pollfd`. | ||
/// | ||
/// It's meant to be used as an argument to the [`poll`](fn.poll.html) and | ||
/// [`ppoll`](fn.ppoll.html) functions to specify the events of interes |
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.
"interest"
src/poll.rs
Outdated
#[repr(C)] | ||
#[derive(Clone, Copy)] | ||
pub struct PollFd { | ||
pollfd: libc::pollfd, | ||
} | ||
|
||
impl PollFd { | ||
pub fn new(fd: libc::c_int, events: EventFlags) -> PollFd { | ||
/// Creates a new `PollFd` specifying the events of interested |
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.
"interest"
src/poll.rs
Outdated
/// `poll` waits for one of a set of file descriptors to become ready to perform I/O. | ||
/// ([`poll(2)`](http://man7.org/linux/man-pages/man2/poll.2.html)) | ||
/// | ||
/// `fds` is a slice containing all [`PollFd`](struct.PollFd.html) to poll. |
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 know it's a slice by the datatype, just say "fds
contains all ..."
src/poll.rs
Outdated
/// ([`poll(2)`](http://man7.org/linux/man-pages/man2/poll.2.html)) | ||
/// | ||
/// `fds` is a slice containing all [`PollFd`](struct.PollFd.html) to poll. | ||
/// The function will return as soon as one event registered in one of the `PollFd` occurs. |
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.
"The function will return as soon as any events occur for any of the PollFd
s." Something like that, this is a bit more readable I think.
src/poll.rs
Outdated
/// descriptor becomes ready or until a signal is caught. | ||
/// ([`poll(2)`](http://man7.org/linux/man-pages/man2/poll.2.html)) | ||
/// | ||
/// `ppoll` behaves like `poll`, but let you precise what signals may interrupt it |
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.
"specify" instead of "precise"
@Susurrus : done, thanks for your feedback ! |
@ndusart Thanks for your hard work on this, I know it took a while to work through my rigorous review process, and to deal with upstream, but it's contributions like this that make cc @berkowski bors r+ |
672: add poll module in Android r=Susurrus `poll` functions are defined in Android as well. libc is missing some constant, but once rust-lang/libc#663 is merged, it'll be good to merge here. Closes #711
@Susurrus you wouldn't be a good reviewer if you wasn't a bit nitpicking about PR :p It didn't take too long, it's just that the different timezones make that small successive revisions takes more time unfortunately. |
poll
functions are defined in Android as well.libc is missing some constant, but once rust-lang/libc#663 is merged, it'll be good to merge here.
Closes #711