Skip to content

Commit 51421ad

Browse files
committed
Add a PollFd::clear_revents function.
Add a utility function to zero out the `revents` field of a `PollFd`.
1 parent 15185a6 commit 51421ad

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/imp/libc/io/poll_fd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ impl<'fd> PollFd<'fd> {
8383
self.pollfd.fd = fd.as_fd().as_raw_fd() as LibcFd;
8484
}
8585

86+
/// Clears the ready events.
87+
#[inline]
88+
pub fn clear_revents(&mut self) {
89+
self.pollfd.revents = 0;
90+
}
91+
8692
/// Constructs a new `PollFd` holding `fd` and `events`.
8793
///
8894
/// This is the same as `new`, but can be used to avoid borrowing the

src/imp/linux_raw/io/poll_fd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ impl<'fd> PollFd<'fd> {
5656
self.fd = fd.as_fd();
5757
}
5858

59+
/// Clears the ready events.
60+
#[inline]
61+
pub fn clear_revents(&mut self) {
62+
self.revents = 0;
63+
}
64+
5965
/// Constructs a new `PollFd` holding `fd` and `events`.
6066
///
6167
/// This is the same as `new`, but can be used to avoid borrowing the

tests/io/poll.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ fn test_poll() {
2828
assert_eq!(poll_fds[0].revents(), PollFlags::IN);
2929
assert_eq!(poll_fds[0].as_fd().as_raw_fd(), reader.as_fd().as_raw_fd());
3030

31+
let mut temp = poll_fds[0].clone();
32+
assert_eq!(temp.revents(), PollFlags::IN);
33+
temp.clear_revents();
34+
assert!(temp.revents().is_empty());
35+
3136
// Read the byte from the pipe.
3237
let mut buf = [b'\0'];
3338
assert_eq!(with_retrying(|| read(&reader, &mut buf)).unwrap(), 1);

0 commit comments

Comments
 (0)