@@ -36,7 +36,7 @@ macro_rules! impl_facade {
3636 $crate:: error!( "{} change to running state failed !" , co. name( ) ) ;
3737 }
3838 }
39- $crate:: info!( "exit syscall {} {:?}" , syscall, r) ;
39+ $crate:: info!( "exit syscall {} {:?} {} " , syscall, r, std :: io :: Error :: last_os_error ( ) ) ;
4040 r
4141 }
4242 }
@@ -63,8 +63,9 @@ macro_rules! impl_nio_read {
6363 $crate:: syscall:: common:: set_non_blocking( $fd) ;
6464 }
6565 let start_time = $crate:: common:: now( ) ;
66- let mut r;
67- loop {
66+ let mut left_time = $crate:: syscall:: common:: recv_time_limit( $fd) ;
67+ let mut r = 0 ;
68+ while left_time > 0 {
6869 r = self . inner. $syscall( fn_ptr, $fd, $( $arg, ) * ) ;
6970 if r != -1 as _ {
7071 $crate:: syscall:: common:: reset_errno( ) ;
@@ -73,9 +74,10 @@ macro_rules! impl_nio_read {
7374 let error_kind = std:: io:: Error :: last_os_error( ) . kind( ) ;
7475 if error_kind == std:: io:: ErrorKind :: WouldBlock {
7576 //wait read event
76- let wait_time = std :: time :: Duration :: from_nanos ( start_time
77+ left_time = start_time
7778 . saturating_add( $crate:: syscall:: common:: recv_time_limit( $fd) )
78- . saturating_sub( $crate:: common:: now( ) ) )
79+ . saturating_sub( $crate:: common:: now( ) ) ;
80+ let wait_time = std:: time:: Duration :: from_nanos( left_time)
7981 . min( $crate:: common:: constants:: SLICE ) ;
8082 if $crate:: net:: EventLoops :: wait_read_event(
8183 $fd as _,
@@ -119,9 +121,10 @@ macro_rules! impl_nio_read_buf {
119121 $crate:: syscall:: common:: set_non_blocking( $fd) ;
120122 }
121123 let start_time = $crate:: common:: now( ) ;
124+ let mut left_time = $crate:: syscall:: common:: recv_time_limit( $fd) ;
122125 let mut received = 0 ;
123126 let mut r = 0 ;
124- while received < $len {
127+ while received < $len && left_time > 0 {
125128 r = self . inner. $syscall(
126129 fn_ptr,
127130 $fd,
@@ -140,9 +143,10 @@ macro_rules! impl_nio_read_buf {
140143 let error_kind = std:: io:: Error :: last_os_error( ) . kind( ) ;
141144 if error_kind == std:: io:: ErrorKind :: WouldBlock {
142145 //wait read event
143- let wait_time = std :: time :: Duration :: from_nanos ( start_time
146+ left_time = start_time
144147 . saturating_add( $crate:: syscall:: common:: recv_time_limit( $fd) )
145- . saturating_sub( $crate:: common:: now( ) ) )
148+ . saturating_sub( $crate:: common:: now( ) ) ;
149+ let wait_time = std:: time:: Duration :: from_nanos( left_time)
146150 . min( $crate:: common:: constants:: SLICE ) ;
147151 if $crate:: net:: EventLoops :: wait_read_event(
148152 $fd as _,
@@ -187,8 +191,15 @@ macro_rules! impl_nio_read_iovec {
187191 if blocking {
188192 $crate:: syscall:: common:: set_non_blocking( $fd) ;
189193 }
190- let vec = unsafe { Vec :: from_raw_parts( $iov. cast_mut( ) , $iovcnt as usize , $iovcnt as usize ) } ;
191194 let start_time = $crate:: common:: now( ) ;
195+ let mut left_time = $crate:: syscall:: common:: recv_time_limit( $fd) ;
196+ let vec = unsafe {
197+ Vec :: from_raw_parts(
198+ $iov. cast_mut( ) ,
199+ $iovcnt as usize ,
200+ $iovcnt as usize
201+ )
202+ } ;
192203 let mut length = 0 ;
193204 let mut received = 0usize ;
194205 let mut r = 0 ;
@@ -204,7 +215,7 @@ macro_rules! impl_nio_read_iovec {
204215 for i in vec. iter( ) . skip( index) {
205216 arg. push( * i) ;
206217 }
207- while received < length {
218+ while received < length && left_time > 0 {
208219 if 0 != offset {
209220 arg[ 0 ] = windows_sys:: Win32 :: Networking :: WinSock :: WSABUF {
210221 buf: ( arg[ 0 ] . buf as usize + offset) as windows_sys:: core:: PSTR ,
@@ -238,9 +249,10 @@ macro_rules! impl_nio_read_iovec {
238249 let error_kind = std:: io:: Error :: last_os_error( ) . kind( ) ;
239250 if error_kind == std:: io:: ErrorKind :: WouldBlock {
240251 //wait read event
241- let wait_time = std :: time :: Duration :: from_nanos ( start_time
252+ left_time = start_time
242253 . saturating_add( $crate:: syscall:: common:: recv_time_limit( $fd) )
243- . saturating_sub( $crate:: common:: now( ) ) )
254+ . saturating_sub( $crate:: common:: now( ) ) ;
255+ let wait_time = std:: time:: Duration :: from_nanos( left_time)
244256 . min( $crate:: common:: constants:: SLICE ) ;
245257 if $crate:: net:: EventLoops :: wait_read_event(
246258 $fd as _,
@@ -297,9 +309,10 @@ macro_rules! impl_nio_write_buf {
297309 $crate:: syscall:: common:: set_non_blocking( $fd) ;
298310 }
299311 let start_time = $crate:: common:: now( ) ;
312+ let mut left_time = $crate:: syscall:: common:: send_time_limit( $fd) ;
300313 let mut sent = 0 ;
301314 let mut r = 0 ;
302- while sent < $len {
315+ while sent < $len && left_time > 0 {
303316 r = self . inner. $syscall(
304317 fn_ptr,
305318 $fd,
@@ -318,9 +331,10 @@ macro_rules! impl_nio_write_buf {
318331 let error_kind = std:: io:: Error :: last_os_error( ) . kind( ) ;
319332 if error_kind == std:: io:: ErrorKind :: WouldBlock {
320333 //wait write event
321- let wait_time = std :: time :: Duration :: from_nanos ( start_time
334+ left_time = start_time
322335 . saturating_add( $crate:: syscall:: common:: send_time_limit( $fd) )
323- . saturating_sub( $crate:: common:: now( ) ) )
336+ . saturating_sub( $crate:: common:: now( ) ) ;
337+ let wait_time = std:: time:: Duration :: from_nanos( left_time)
324338 . min( $crate:: common:: constants:: SLICE ) ;
325339 if $crate:: net:: EventLoops :: wait_write_event(
326340 $fd as _,
@@ -365,8 +379,15 @@ macro_rules! impl_nio_write_iovec {
365379 if blocking {
366380 $crate:: syscall:: common:: set_non_blocking( $fd) ;
367381 }
368- let vec = unsafe { Vec :: from_raw_parts( $iov. cast_mut( ) , $iovcnt as usize , $iovcnt as usize ) } ;
369382 let start_time = $crate:: common:: now( ) ;
383+ let mut left_time = $crate:: syscall:: common:: send_time_limit( $fd) ;
384+ let vec = unsafe {
385+ Vec :: from_raw_parts(
386+ $iov. cast_mut( ) ,
387+ $iovcnt as usize ,
388+ $iovcnt as usize
389+ )
390+ } ;
370391 let mut length = 0 ;
371392 let mut sent = 0usize ;
372393 let mut r = 0 ;
@@ -382,7 +403,7 @@ macro_rules! impl_nio_write_iovec {
382403 for i in vec. iter( ) . skip( index) {
383404 arg. push( * i) ;
384405 }
385- while sent < length {
406+ while sent < length && left_time > 0 {
386407 if 0 != offset {
387408 arg[ 0 ] = windows_sys:: Win32 :: Networking :: WinSock :: WSABUF {
388409 buf: ( arg[ 0 ] . buf as usize + offset) as windows_sys:: core:: PSTR ,
@@ -410,9 +431,10 @@ macro_rules! impl_nio_write_iovec {
410431 let error_kind = std:: io:: Error :: last_os_error( ) . kind( ) ;
411432 if error_kind == std:: io:: ErrorKind :: WouldBlock {
412433 //wait write event
413- let wait_time = std :: time :: Duration :: from_nanos ( start_time
434+ left_time = start_time
414435 . saturating_add( $crate:: syscall:: common:: send_time_limit( $fd) )
415- . saturating_sub( $crate:: common:: now( ) ) )
436+ . saturating_sub( $crate:: common:: now( ) ) ;
437+ let wait_time = std:: time:: Duration :: from_nanos( left_time)
416438 . min( $crate:: common:: constants:: SLICE ) ;
417439 if $crate:: net:: EventLoops :: wait_write_event(
418440 $fd as _,
0 commit comments