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

add poll module in Android #672

Merged
merged 2 commits into from
Jul 30, 2017
Merged

add poll module in Android #672

merged 2 commits into from
Jul 30, 2017

Conversation

ndusart
Copy link
Contributor

@ndusart ndusart commented Jul 12, 2017

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

@asomers
Copy link
Member

asomers commented Jul 12, 2017

Good find. Could you also enable the poll tests for Android in test/test.rs ?

@Susurrus
Copy link
Contributor

Actually poll() and related constants are defined for all unix platforms. So we can just unconditionally enable that. But ppoll is only for android, linux, and freebsd/dragonfly, though the freebsd/dragonfly support is missing from ppoll, could you change that as well @ndusart?

@Susurrus
Copy link
Contributor

Also you'll want to change Cargo.toml to point to libc git for these tests to pass once rust-lang/libc#663 lands.

@ndusart
Copy link
Contributor Author

ndusart commented Jul 12, 2017

I included the module and the test unconditionally.
Could only test for linux and android though. Waiting to see the CI results.

@ndusart
Copy link
Contributor Author

ndusart commented Jul 12, 2017

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.

@ndusart ndusart force-pushed the android-poll branch 4 times, most recently from 85f1e2e to d8d3ab9 Compare July 13, 2017 15:43
@ndusart
Copy link
Contributor Author

ndusart commented Jul 13, 2017

Should be good to merge now.

@Susurrus
Copy link
Contributor

@ndusart We're waiting for nix to release before merging this. Either that or a new libc release happens before and then we can merge this in.

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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Susurrus
Copy link
Contributor

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"))]
Copy link
Contributor

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"))]
Copy link
Contributor

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"))]
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

@ndusart ndusart Jul 25, 2017

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 ?

Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"interest"

@Susurrus
Copy link
Contributor

Thanks for the docs, it looks a lot better! There's some minor things to clean up here, but nothing major.

@ndusart
Copy link
Contributor Author

ndusart commented Jul 26, 2017

The requested changes have been made.

@ndusart
Copy link
Contributor Author

ndusart commented Jul 27, 2017

@Susurrus does this PR seem ok ?

Copy link
Contributor

@Susurrus Susurrus left a 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
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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 PollFds." 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"specify" instead of "precise"

@ndusart
Copy link
Contributor Author

ndusart commented Jul 30, 2017

@Susurrus : done, thanks for your feedback !

@Susurrus
Copy link
Contributor

@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 nix great!

cc @berkowski

bors r+

bors bot added a commit that referenced this pull request Jul 30, 2017
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
@bors
Copy link
Contributor

bors bot commented Jul 30, 2017

@bors bors bot merged commit e19ffab into nix-rust:master Jul 30, 2017
@ndusart ndusart deleted the android-poll branch July 30, 2017 17:42
@ndusart
Copy link
Contributor Author

ndusart commented Jul 30, 2017

@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.

bors bot added a commit that referenced this pull request Aug 1, 2017
716: Fix changelog from bad merge r=Susurrus

Missed this when merging #672.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants