Skip to content

Commit 92dd754

Browse files
PollFd utility functions
1 parent 89699b1 commit 92dd754

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
99
- Added `SockaddrStorage::{as_unix_addr, as_unix_addr_mut}`
1010
([#1871](https://github.com/nix-rust/nix/pull/1871))
1111
- Added `MntFlags` and `unmount` on all of the BSDs.
12+
- Added `any()` and `all()` to `poll::PollFd`.
13+
([#1877](https://github.com/nix-rust/nix/pull/1877))
14+
- Add `MntFlags` and `unmount` on all of the BSDs.
1215
([#1849](https://github.com/nix-rust/nix/pull/1849))
1316
- Added a 'Statfs::flags' method.
1417
([#1849](https://github.com/nix-rust/nix/pull/1849))

src/poll.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ impl PollFd {
3737
PollFlags::from_bits(self.pollfd.revents)
3838
}
3939

40+
/// Returns if any of the events of interest occured in the last call to `poll` or `ppoll`. Will
41+
/// only return `None` if the kernel provides status flags that Nix does not know about.
42+
///
43+
/// Equivalent to `x.revents()? != PollFlags::empty()`.
44+
///
45+
/// This is marginally more efficient than [`PollFd::all`].
46+
pub fn any(self) -> Option<bool> {
47+
Some(self.revents()? != PollFlags::empty())
48+
}
49+
50+
/// Returns if all the events of interest occured in the last call to `poll` or `ppoll`. Will
51+
/// only return `None` if the kernel provides status flags that Nix does not know about.
52+
///
53+
/// Equivalent to `x.revents()? & x.events() == x.events()`.
54+
///
55+
/// This is marginally less efficient than [`PollFd::any`].
56+
pub fn all(self) -> Option<bool> {
57+
Some(self.revents()? & self.events() == self.events())
58+
}
59+
4060
/// The events of interest for this `PollFd`.
4161
pub fn events(self) -> PollFlags {
4262
PollFlags::from_bits(self.pollfd.events).unwrap()

0 commit comments

Comments
 (0)