summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-09-07 23:50:23 +0000
committerGitHub <noreply@github.com>2021-09-07 23:50:23 +0000
commit53fea96dd41926fb8527ac1ad35ada2ba106e454 (patch)
treef0d13836632673219798894738e114cef2d4803d
parent630700eb7c525b461d8f32b591e39a786cc3e2a0 (diff)
parentb0b7beb2a8772dd492272c4896425cde46b8dce9 (diff)
downloadnix-53fea96dd41926fb8527ac1ad35ada2ba106e454.zip
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 <cem@FreeBSD.org>
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/poll.rs8
-rw-r--r--test/test_poll.rs8
3 files changed, 17 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc93a76f..a3b5b82a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
(#[1511](https://github.com/nix-rust/nix/pull/1511))
- Added `Ipv4RecvErr` and `Ipv6RecvErr` sockopts and associated control messages.
(#[1514](https://github.com/nix-rust/nix/pull/1514))
+- Added `AsRawFd` implementation on `PollFd`.
+ (#[1516](https://github.com/nix-rust/nix/pull/1516))
### Changed
diff --git a/src/poll.rs b/src/poll.rs
index e814337a..0eaf7e1d 100644
--- a/src/poll.rs
+++ b/src/poll.rs
@@ -3,7 +3,7 @@
use crate::sys::time::TimeSpec;
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
use crate::sys::signal::SigSet;
-use std::os::unix::io::RawFd;
+use std::os::unix::io::{AsRawFd, RawFd};
use crate::Result;
use crate::errno::Errno;
@@ -41,6 +41,12 @@ impl PollFd {
}
}
+impl AsRawFd for PollFd {
+ fn as_raw_fd(&self) -> RawFd {
+ self.pollfd.fd
+ }
+}
+
libc_bitflags! {
/// These flags define the different events that can be monitored by `poll` and `ppoll`
pub struct PollFlags: libc::c_short {
diff --git a/test/test_poll.rs b/test/test_poll.rs
index 0395512b..ee89c4a0 100644
--- a/test/test_poll.rs
+++ b/test/test_poll.rs
@@ -64,3 +64,11 @@ fn test_ppoll() {
assert_eq!(nfds, 1);
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
}
+
+#[test]
+fn test_pollfd_fd() {
+ use std::os::unix::io::AsRawFd;
+
+ let pfd = PollFd::new(0x1234, PollFlags::empty());
+ assert_eq!(pfd.as_raw_fd(), 0x1234);
+}