summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan <jonathanwoollettlight@gmail.com>2022-11-21 01:59:17 +0000
committerJonathan <jonathanwoollettlight@gmail.com>2022-11-29 01:41:31 +0000
commit92dd75475915990ab8804f01833964d990a9aeea (patch)
tree8d1a4e016fc5aa07eb95c333f25382e0ef229cb0
parent89699b1d7f302f6d70f65f650de224ca3afcd62d (diff)
downloadnix-92dd75475915990ab8804f01833964d990a9aeea.zip
PollFd utility functions
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/poll.rs20
2 files changed, 23 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 267d1809..d406c1bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Added `SockaddrStorage::{as_unix_addr, as_unix_addr_mut}`
([#1871](https://github.com/nix-rust/nix/pull/1871))
- Added `MntFlags` and `unmount` on all of the BSDs.
+- Added `any()` and `all()` to `poll::PollFd`.
+ ([#1877](https://github.com/nix-rust/nix/pull/1877))
+- Add `MntFlags` and `unmount` on all of the BSDs.
([#1849](https://github.com/nix-rust/nix/pull/1849))
- Added a 'Statfs::flags' method.
([#1849](https://github.com/nix-rust/nix/pull/1849))
diff --git a/src/poll.rs b/src/poll.rs
index e1baa814..6f227fee 100644
--- a/src/poll.rs
+++ b/src/poll.rs
@@ -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()