Skip to content

Commit 9a2f86f

Browse files
bors[bot]cemeyer
andauthored
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>
2 parents e94bf0e + b16e70e commit 9a2f86f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
5050
(#[1531](https://github.com/nix-rust/nix/pull/1531))
5151
- Added `MAP_ANONYMOUS` for all operating systems.
5252
(#[1534](https://github.com/nix-rust/nix/pull/1534))
53+
- Added read/write accessors for 'events' on `PollFd`.
54+
(#[1517](https://github.com/nix-rust/nix/pull/1517))
5355

5456
### Changed
5557

src/poll.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ impl PollFd {
3535
}
3636
}
3737

38-
/// Returns the events that occured in the last call to `poll` or `ppoll`.
38+
/// Returns the events that occured in the last call to `poll` or `ppoll`. Will only return
39+
/// `None` if the kernel provides status flags that Nix does not know about.
3940
pub fn revents(self) -> Option<PollFlags> {
4041
PollFlags::from_bits(self.pollfd.revents)
4142
}
43+
44+
/// The events of interest for this `PollFd`.
45+
pub fn events(self) -> PollFlags {
46+
PollFlags::from_bits(self.pollfd.events).unwrap()
47+
}
48+
49+
/// Modify the events of interest for this `PollFd`.
50+
pub fn set_events(&mut self, events: PollFlags) {
51+
self.pollfd.events = events.bits();
52+
}
4253
}
4354

4455
impl AsRawFd for PollFd {

test/test_poll.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ fn test_pollfd_fd() {
7272
let pfd = PollFd::new(0x1234, PollFlags::empty());
7373
assert_eq!(pfd.as_raw_fd(), 0x1234);
7474
}
75+
76+
#[test]
77+
fn test_pollfd_events() {
78+
let mut pfd = PollFd::new(-1, PollFlags::POLLIN);
79+
assert_eq!(pfd.events(), PollFlags::POLLIN);
80+
pfd.set_events(PollFlags::POLLOUT);
81+
assert_eq!(pfd.events(), PollFlags::POLLOUT);
82+
}

0 commit comments

Comments
 (0)