|
1 |
| -use nix::poll::{PollFlags, poll, PollFd}; |
2 |
| -use nix::unistd::{write, pipe}; |
| 1 | +use nix::{ |
| 2 | + Error, |
| 3 | + errno::Errno, |
| 4 | + poll::{PollFlags, poll, PollFd}, |
| 5 | + unistd::{write, pipe} |
| 6 | +}; |
| 7 | + |
| 8 | +macro_rules! loop_while_eintr { |
| 9 | + ($poll_expr: expr) => { |
| 10 | + loop { |
| 11 | + match $poll_expr { |
| 12 | + Ok(nfds) => break nfds, |
| 13 | + Err(Error::Sys(Errno::EINTR)) => (), |
| 14 | + Err(e) => panic!(e) |
| 15 | + } |
| 16 | + } |
| 17 | + } |
| 18 | +} |
3 | 19 |
|
4 | 20 | #[test]
|
5 | 21 | fn test_poll() {
|
6 | 22 | let (r, w) = pipe().unwrap();
|
7 | 23 | let mut fds = [PollFd::new(r, PollFlags::POLLIN)];
|
8 | 24 |
|
9 | 25 | // Poll an idle pipe. Should timeout
|
10 |
| - let nfds = poll(&mut fds, 100).unwrap(); |
| 26 | + let nfds = loop_while_eintr!(poll(&mut fds, 100)); |
11 | 27 | assert_eq!(nfds, 0);
|
12 | 28 | assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));
|
13 | 29 |
|
@@ -37,7 +53,8 @@ fn test_ppoll() {
|
37 | 53 | let mut fds = [PollFd::new(r, PollFlags::POLLIN)];
|
38 | 54 |
|
39 | 55 | // Poll an idle pipe. Should timeout
|
40 |
| - let nfds = ppoll(&mut fds, Some(timeout), SigSet::empty()).unwrap(); |
| 56 | + let sigset = SigSet::empty(); |
| 57 | + let nfds = loop_while_eintr!(ppoll(&mut fds, Some(timeout), sigset)); |
41 | 58 | assert_eq!(nfds, 0);
|
42 | 59 | assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));
|
43 | 60 |
|
|
0 commit comments