@@ -23,8 +23,7 @@ pub fn wait_write_fd<Fd: AsFd>(fd: Fd, timeout: Duration) -> io::Result<()> {
2323fn wait_fd < Fd : AsFd > ( fd : Fd , events : PollFlags , timeout : Duration ) -> io:: Result < ( ) > {
2424 use nix:: errno:: Errno :: { EIO , EPIPE } ;
2525
26- let fd = fd. as_fd ( ) ;
27- let mut fd = PollFd :: new ( & fd, events) ;
26+ let mut fd = PollFd :: new ( fd. as_fd ( ) , events) ;
2827
2928 let wait = match poll_clamped ( & mut fd, timeout) {
3029 Ok ( r) => r,
@@ -87,44 +86,39 @@ fn clamped_time_spec(duration: Duration) -> TimeSpec {
8786// by `poll`.
8887#[ cfg( not( target_os = "linux" ) ) ]
8988fn poll_clamped ( fd : & mut PollFd , timeout : Duration ) -> nix:: Result < c_int > {
90- let millis = clamped_millis_c_int ( timeout) ;
89+ let millis = clamped_duration_nix ( timeout) ;
9190 nix:: poll:: poll ( slice:: from_mut ( fd) , millis)
9291}
9392
9493#[ cfg( any( not( target_os = "linux" ) , test) ) ]
95- fn clamped_millis_c_int ( duration : Duration ) -> c_int {
96- let secs_limit = ( c_int:: MAX as u64 ) / 1000 ;
97- let secs = duration. as_secs ( ) ;
98-
99- if secs <= secs_limit {
100- secs as c_int * 1000 + duration. subsec_millis ( ) as c_int
101- } else {
102- c_int:: MAX
103- }
94+ fn clamped_duration_nix ( duration : Duration ) -> nix:: poll:: PollTimeout {
95+ nix:: poll:: PollTimeout :: try_from ( duration) . unwrap_or ( nix:: poll:: PollTimeout :: MAX )
10496}
10597
10698#[ cfg( test) ]
10799mod tests {
100+ use nix:: poll:: PollTimeout ;
101+
108102 use super :: * ;
109103 use crate :: tests:: timeout:: MONOTONIC_DURATIONS ;
110104
111105 #[ test]
112- fn clamped_millis_c_int_is_monotonic ( ) {
113- let mut last = clamped_millis_c_int ( Duration :: ZERO ) ;
106+ fn clamped_duration_nix_is_monotonic ( ) {
107+ let mut last = clamped_duration_nix ( Duration :: ZERO ) ;
114108
115109 for ( i, d) in MONOTONIC_DURATIONS . iter ( ) . enumerate ( ) {
116- let next = clamped_millis_c_int ( * d) ;
110+ let next = clamped_duration_nix ( * d) ;
117111 assert ! (
118112 next >= last,
119- "{next} >= {last} failed for {d:?} at index {i}"
113+ "{next:? } >= {last:? } failed for {d:?} at index {i}"
120114 ) ;
121115 last = next;
122116 }
123117 }
124118
125119 #[ test]
126- fn clamped_millis_c_int_zero_is_zero ( ) {
127- assert_eq ! ( 0 , clamped_millis_c_int ( Duration :: ZERO ) ) ;
120+ fn clamped_duration_nix_zero_is_zero ( ) {
121+ assert_eq ! ( PollTimeout :: ZERO , clamped_duration_nix ( Duration :: ZERO ) ) ;
128122 }
129123
130124 #[ test]
0 commit comments