File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
50
50
(#[ 1531] ( https://github.com/nix-rust/nix/pull/1531 ) )
51
51
- Added ` MAP_ANONYMOUS ` for all operating systems.
52
52
(#[ 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 ) )
53
55
54
56
### Changed
55
57
Original file line number Diff line number Diff line change @@ -35,10 +35,21 @@ impl PollFd {
35
35
}
36
36
}
37
37
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.
39
40
pub fn revents ( self ) -> Option < PollFlags > {
40
41
PollFlags :: from_bits ( self . pollfd . revents )
41
42
}
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
+ }
42
53
}
43
54
44
55
impl AsRawFd for PollFd {
Original file line number Diff line number Diff line change @@ -72,3 +72,11 @@ fn test_pollfd_fd() {
72
72
let pfd = PollFd :: new ( 0x1234 , PollFlags :: empty ( ) ) ;
73
73
assert_eq ! ( pfd. as_raw_fd( ) , 0x1234 ) ;
74
74
}
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
+ }
You can’t perform that action at this time.
0 commit comments