@@ -29,15 +29,15 @@ const POLLERR: c_short = 0x0008;
29
29
const POLLHUP : c_short = 0x0010 ;
30
30
const POLLNVAL : c_short = 0x0020 ;
31
31
32
- pub fn wait_read_fd ( fd : c_int , timeout : Duration ) -> io:: Result < ( ) > {
32
+ pub fn wait_read_fd ( fd : c_int , timeout : Option < Duration > ) -> io:: Result < ( ) > {
33
33
wait_fd ( fd, POLLIN , timeout)
34
34
}
35
35
36
- pub fn wait_write_fd ( fd : c_int , timeout : Duration ) -> io:: Result < ( ) > {
36
+ pub fn wait_write_fd ( fd : c_int , timeout : Option < Duration > ) -> io:: Result < ( ) > {
37
37
wait_fd ( fd, POLLOUT , timeout)
38
38
}
39
39
40
- fn wait_fd ( fd : c_int , events : c_short , timeout : Duration ) -> io:: Result < ( ) > {
40
+ fn wait_fd ( fd : c_int , events : c_short , timeout : Option < Duration > ) -> io:: Result < ( ) > {
41
41
use libc:: { EINTR , EPIPE , EIO } ;
42
42
43
43
let mut fds = vec ! ( pollfd { fd: fd, events: events, revents: 0 } ) ;
@@ -72,7 +72,7 @@ fn wait_fd(fd: c_int, events: c_short, timeout: Duration) -> io::Result<()> {
72
72
73
73
#[ cfg( target_os = "linux" ) ]
74
74
#[ inline]
75
- fn do_poll ( fds : & mut Vec < pollfd > , timeout : Duration ) -> c_int {
75
+ fn do_poll ( fds : & mut Vec < pollfd > , timeout : Option < Duration > ) -> c_int {
76
76
use std:: ptr;
77
77
78
78
use libc:: c_void;
@@ -86,31 +86,44 @@ fn do_poll(fds: &mut Vec<pollfd>, timeout: Duration) -> c_int {
86
86
fn ppoll ( fds : * mut pollfd , nfds : nfds_t , timeout_ts : * mut libc:: timespec , sigmask : * const sigset_t ) -> c_int ;
87
87
}
88
88
89
- let mut timeout_ts = libc:: timespec {
90
- tv_sec : timeout. as_secs ( ) as libc:: time_t ,
91
- tv_nsec : timeout. subsec_nanos ( ) as libc:: c_long ,
92
- } ;
89
+ if let Some ( timeout) = timeout {
90
+ let mut timeout_ts = libc:: timespec {
91
+ tv_sec : timeout. as_secs ( ) as libc:: time_t ,
92
+ tv_nsec : timeout. subsec_nanos ( ) as libc:: c_long ,
93
+ } ;
93
94
94
- unsafe {
95
- ppoll ( ( & mut fds[ ..] ) . as_mut_ptr ( ) ,
96
- fds. len ( ) as nfds_t ,
97
- & mut timeout_ts,
98
- ptr:: null ( ) )
95
+ unsafe {
96
+ ppoll ( ( & mut fds[ ..] ) . as_mut_ptr ( ) ,
97
+ fds. len ( ) as nfds_t ,
98
+ & mut timeout_ts,
99
+ ptr:: null ( ) )
100
+ }
101
+ } else {
102
+ unsafe {
103
+ ppoll ( ( & mut fds[ ..] ) . as_mut_ptr ( ) ,
104
+ fds. len ( ) as nfds_t ,
105
+ ptr:: null_mut ( ) ,
106
+ ptr:: null ( ) )
107
+ }
99
108
}
100
109
}
101
110
102
111
#[ cfg( not( target_os = "linux" ) ) ]
103
112
#[ inline]
104
- fn do_poll ( fds : & mut Vec < pollfd > , timeout : Duration ) -> c_int {
113
+ fn do_poll ( fds : & mut Vec < pollfd > , timeout : Option < Duration > ) -> c_int {
105
114
extern "C" {
106
115
fn poll ( fds : * mut pollfd , nfds : nfds_t , timeout : c_int ) -> c_int ;
107
116
}
108
117
109
- let milliseconds = timeout. as_secs ( ) * 1000 + timeout. subsec_nanos ( ) as u64 / 1_000_000 ;
118
+ let milliseconds = if let Some ( timeout) = timeout {
119
+ ( timeout. as_secs ( ) * 1000 + timeout. subsec_nanos ( ) as u64 / 1_000_000 ) as c_int
120
+ } else {
121
+ -1
122
+ } ;
110
123
111
124
unsafe {
112
125
poll ( ( & mut fds[ ..] ) . as_mut_ptr ( ) ,
113
126
fds. len ( ) as nfds_t ,
114
- milliseconds as c_int )
127
+ milliseconds)
115
128
}
116
129
}
0 commit comments