Skip to content

Commit 53fea96

Browse files
bors[bot]cemeyer
andauthored
Merge #1516
1516: Implement AsRawFd for PollFd r=asomers a=cemeyer Implement the trait on PollFd, providing an `as_raw_fd()` accessor to get the RawFd associated with the PollFd. Subsumes #1147, #1286. Closes #1146. Test: `cargo test --test test test_pollfd_fd` Co-authored-by: Conrad Meyer <[email protected]>
2 parents 630700e + b0b7beb commit 53fea96

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
3636
(#[1511](https://github.com/nix-rust/nix/pull/1511))
3737
- Added `Ipv4RecvErr` and `Ipv6RecvErr` sockopts and associated control messages.
3838
(#[1514](https://github.com/nix-rust/nix/pull/1514))
39+
- Added `AsRawFd` implementation on `PollFd`.
40+
(#[1516](https://github.com/nix-rust/nix/pull/1516))
3941

4042
### Changed
4143

src/poll.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::sys::time::TimeSpec;
44
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
55
use crate::sys::signal::SigSet;
6-
use std::os::unix::io::RawFd;
6+
use std::os::unix::io::{AsRawFd, RawFd};
77

88
use crate::Result;
99
use crate::errno::Errno;
@@ -41,6 +41,12 @@ impl PollFd {
4141
}
4242
}
4343

44+
impl AsRawFd for PollFd {
45+
fn as_raw_fd(&self) -> RawFd {
46+
self.pollfd.fd
47+
}
48+
}
49+
4450
libc_bitflags! {
4551
/// These flags define the different events that can be monitored by `poll` and `ppoll`
4652
pub struct PollFlags: libc::c_short {

test/test_poll.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,11 @@ fn test_ppoll() {
6464
assert_eq!(nfds, 1);
6565
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
6666
}
67+
68+
#[test]
69+
fn test_pollfd_fd() {
70+
use std::os::unix::io::AsRawFd;
71+
72+
let pfd = PollFd::new(0x1234, PollFlags::empty());
73+
assert_eq!(pfd.as_raw_fd(), 0x1234);
74+
}

0 commit comments

Comments
 (0)