summaryrefslogtreecommitdiffstats
path: root/third_party/rust/nix/test/test_poll.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/nix/test/test_poll.rs')
-rw-r--r--third_party/rust/nix/test/test_poll.rs31
1 files changed, 11 insertions, 20 deletions
diff --git a/third_party/rust/nix/test/test_poll.rs b/third_party/rust/nix/test/test_poll.rs
index 045ccd3df1..fcb325494e 100644
--- a/third_party/rust/nix/test/test_poll.rs
+++ b/third_party/rust/nix/test/test_poll.rs
@@ -1,9 +1,9 @@
use nix::{
errno::Errno,
- poll::{poll, PollFd, PollFlags},
- unistd::{close, pipe, write},
+ poll::{poll, PollFd, PollFlags, PollTimeout},
+ unistd::{pipe, write},
};
-use std::os::unix::io::{BorrowedFd, FromRawFd, OwnedFd};
+use std::os::unix::io::{AsFd, BorrowedFd};
macro_rules! loop_while_eintr {
($poll_expr: expr) => {
@@ -20,32 +20,25 @@ macro_rules! loop_while_eintr {
#[test]
fn test_poll() {
let (r, w) = pipe().unwrap();
- let r = unsafe { OwnedFd::from_raw_fd(r) };
- let mut fds = [PollFd::new(&r, PollFlags::POLLIN)];
+ let mut fds = [PollFd::new(r.as_fd(), PollFlags::POLLIN)];
// Poll an idle pipe. Should timeout
- let nfds = loop_while_eintr!(poll(&mut fds, 100));
+ let nfds = loop_while_eintr!(poll(&mut fds, PollTimeout::from(100u8)));
assert_eq!(nfds, 0);
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));
- write(w, b".").unwrap();
+ write(&w, b".").unwrap();
// Poll a readable pipe. Should return an event.
- let nfds = poll(&mut fds, 100).unwrap();
+ let nfds = poll(&mut fds, PollTimeout::from(100u8)).unwrap();
assert_eq!(nfds, 1);
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
- close(w).unwrap();
}
// ppoll(2) is the same as poll except for how it handles timeouts and signals.
// Repeating the test for poll(2) should be sufficient to check that our
// bindings are correct.
-#[cfg(any(
- target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "linux"
-))]
+#[cfg(any(linux_android, freebsdlike))]
#[test]
fn test_ppoll() {
use nix::poll::ppoll;
@@ -54,8 +47,7 @@ fn test_ppoll() {
let timeout = TimeSpec::milliseconds(1);
let (r, w) = pipe().unwrap();
- let r = unsafe { OwnedFd::from_raw_fd(r) };
- let mut fds = [PollFd::new(&r, PollFlags::POLLIN)];
+ let mut fds = [PollFd::new(r.as_fd(), PollFlags::POLLIN)];
// Poll an idle pipe. Should timeout
let sigset = SigSet::empty();
@@ -63,19 +55,18 @@ fn test_ppoll() {
assert_eq!(nfds, 0);
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));
- write(w, b".").unwrap();
+ write(&w, b".").unwrap();
// Poll a readable pipe. Should return an event.
let nfds = ppoll(&mut fds, Some(timeout), None).unwrap();
assert_eq!(nfds, 1);
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
- close(w).unwrap();
}
#[test]
fn test_pollfd_events() {
let fd_zero = unsafe { BorrowedFd::borrow_raw(0) };
- let mut pfd = PollFd::new(&fd_zero, PollFlags::POLLIN);
+ let mut pfd = PollFd::new(fd_zero.as_fd(), PollFlags::POLLIN);
assert_eq!(pfd.events(), PollFlags::POLLIN);
pfd.set_events(PollFlags::POLLOUT);
assert_eq!(pfd.events(), PollFlags::POLLOUT);