Skip to content

Commit

Permalink
PollFd utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWoollett-Light committed Nov 21, 2022
1 parent 33b5f92 commit f1df78e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [Unreleased] - ReleaseDate
### Added

- Added `any()` and `all()` to `poll::PollFd`.
([#1849](https://github.com/nix-rust/nix/pull/1849))
- Add `MntFlags` and `unmount` on all of the BSDs.
([#1849](https://github.com/nix-rust/nix/pull/1849))
- Added a 'Statfs::flags' method.
Expand Down
20 changes: 20 additions & 0 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ impl PollFd {
PollFlags::from_bits(self.pollfd.revents)
}

/// Returns if any of the events of interest occured in the last call to `poll` or `ppoll`. Will
/// only return `None` if the kernel provides status flags that Nix does not know about.
///
/// Equivalent to `x.revents()? != PollFlags::empty()`.
///
/// This is marginally more efficient than [`PollFd::all`].
pub fn any(self) -> Option<bool> {
Some(self.revents()? != PollFlags::empty())
}

/// Returns if all the events of interest occured in the last call to `poll` or `ppoll`. Will
/// only return `None` if the kernel provides status flags that Nix does not know about.
///
/// Equivalent to `x.revents()? & x.events() == x.events()`.
///
/// This is marginally less efficient than [`PollFd::any`].
pub fn all(self) -> Option<bool> {
Some(self.revents()? & self.events() == self.events())
}

/// The events of interest for this `PollFd`.
pub fn events(self) -> PollFlags {
PollFlags::from_bits(self.pollfd.events).unwrap()
Expand Down

0 comments on commit f1df78e

Please sign in to comment.