@@ -533,8 +533,9 @@ macro_rules! impl_nio_read_iovec {
533533 let mut received = 0usize ;
534534 let mut r = windows_sys:: Win32 :: Networking :: WinSock :: SOCKET_ERROR ;
535535 let mut index = 0 ;
536- ' outer: for iovec in & vec {
537- let mut offset = received. saturating_sub( length) ;
536+ for iovec in & vec {
537+ let stage = length;
538+ let mut offset = received. saturating_sub( stage) ;
538539 length += iovec. len as usize ;
539540 if received > length {
540541 index += 1 ;
@@ -545,6 +546,7 @@ macro_rules! impl_nio_read_iovec {
545546 arg. push( * i) ;
546547 }
547548 while received < length && left_time > 0 {
549+ // Assuming len is 4, but only 1 is read, at this point we should continue trying to fill the current WSABUF
548550 if 0 != offset {
549551 arg[ 0 ] = windows_sys:: Win32 :: Networking :: WinSock :: WSABUF {
550552 buf: ( arg[ 0 ] . buf as usize + offset) as windows_sys:: core:: PSTR ,
@@ -563,12 +565,13 @@ macro_rules! impl_nio_read_iovec {
563565 ) ;
564566 if r != windows_sys:: Win32 :: Networking :: WinSock :: SOCKET_ERROR {
565567 $crate:: syscall:: reset_errno( ) ;
566- // WSARecv returns 0 on success; actual byte count is in *$recvd
567- received += unsafe { * $recvd } as usize ;
568- r = 0 ;
569- unsafe { $recvd. write( received. try_into( ) . expect( "overflow" ) ) } ;
570- // WSARecv returns as soon as any data is received
571- break ' outer;
568+ received += unsafe { usize :: try_from( * $recvd) . expect( "overflow" ) } ;
569+ if received >= length {
570+ r = 0 ;
571+ unsafe { $recvd. write( received. try_into( ) . expect( "overflow" ) ) } ;
572+ break ;
573+ }
574+ offset = received. saturating_sub( stage) ;
572575 }
573576 let error_kind = std:: io:: Error :: last_os_error( ) . kind( ) ;
574577 if error_kind == std:: io:: ErrorKind :: WouldBlock {
@@ -802,8 +805,7 @@ macro_rules! impl_nio_write_iovec {
802805 ) ;
803806 if r != windows_sys:: Win32 :: Networking :: WinSock :: SOCKET_ERROR {
804807 $crate:: syscall:: reset_errno( ) ;
805- // WSASend returns 0 on success; actual byte count is in *$sent
806- sent += unsafe { * $sent } as usize ;
808+ sent += unsafe { usize :: try_from( * $sent) . expect( "overflow" ) } ;
807809 if sent >= length {
808810 r = 0 ;
809811 unsafe { $sent. write( sent. try_into( ) . expect( "overflow" ) ) } ;
0 commit comments