diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-09-20 03:51:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-20 03:51:59 +0000 |
commit | 9a2f86f4cf9bddefc1878a124b4ee6f83e6ef064 (patch) | |
tree | c0c94b2d4f52a11c9da3db92b933811a339f4ccc | |
parent | e94bf0e444f4e910d2837d6827809da32e8492c1 (diff) | |
parent | b16e70eebf3b6c5c8f5e7e6860ff4b7b1ba3fa04 (diff) | |
download | nix-9a2f86f4cf9bddefc1878a124b4ee6f83e6ef064.zip |
Merge #1517
1517: Fix #411 - Provide accessors for 'events' in PollFd r=asomers a=cemeyer
Test: `cargo test --test test test_pollfd_events`
Co-authored-by: Conrad Meyer <cem@FreeBSD.org>
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/poll.rs | 13 | ||||
-rw-r--r-- | test/test_poll.rs | 8 |
3 files changed, 22 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 52104501..f81268a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). (#[1531](https://github.com/nix-rust/nix/pull/1531)) - Added `MAP_ANONYMOUS` for all operating systems. (#[1534](https://github.com/nix-rust/nix/pull/1534)) +- Added read/write accessors for 'events' on `PollFd`. + (#[1517](https://github.com/nix-rust/nix/pull/1517)) ### Changed diff --git a/src/poll.rs b/src/poll.rs index 0eaf7e1d..8556c1bb 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -35,10 +35,21 @@ impl PollFd { } } - /// Returns the events that occured in the last call to `poll` or `ppoll`. + /// Returns the events that 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. pub fn revents(self) -> Option<PollFlags> { PollFlags::from_bits(self.pollfd.revents) } + + /// The events of interest for this `PollFd`. + pub fn events(self) -> PollFlags { + PollFlags::from_bits(self.pollfd.events).unwrap() + } + + /// Modify the events of interest for this `PollFd`. + pub fn set_events(&mut self, events: PollFlags) { + self.pollfd.events = events.bits(); + } } impl AsRawFd for PollFd { diff --git a/test/test_poll.rs b/test/test_poll.rs index ee89c4a0..e4b369f3 100644 --- a/test/test_poll.rs +++ b/test/test_poll.rs @@ -72,3 +72,11 @@ fn test_pollfd_fd() { let pfd = PollFd::new(0x1234, PollFlags::empty()); assert_eq!(pfd.as_raw_fd(), 0x1234); } + +#[test] +fn test_pollfd_events() { + let mut pfd = PollFd::new(-1, PollFlags::POLLIN); + assert_eq!(pfd.events(), PollFlags::POLLIN); + pfd.set_events(PollFlags::POLLOUT); + assert_eq!(pfd.events(), PollFlags::POLLOUT); +} |