diff options
author | Jonathan <jonathanwoollettlight@gmail.com> | 2022-11-21 01:59:17 +0000 |
---|---|---|
committer | Jonathan <jonathanwoollettlight@gmail.com> | 2022-11-29 01:41:31 +0000 |
commit | 92dd75475915990ab8804f01833964d990a9aeea (patch) | |
tree | 8d1a4e016fc5aa07eb95c333f25382e0ef229cb0 /src | |
parent | 89699b1d7f302f6d70f65f650de224ca3afcd62d (diff) | |
download | nix-92dd75475915990ab8804f01833964d990a9aeea.zip |
PollFd utility functions
Diffstat (limited to 'src')
-rw-r--r-- | src/poll.rs | 20 |
1 files changed, 20 insertions, 0 deletions
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() |