@@ -135,15 +135,14 @@ fn socketpair() -> (FileDescriptor, FileDescriptor) {
135
135
fds
136
136
}
137
137
138
- fn drain ( mut fd : & FileDescriptor ) {
138
+ fn drain ( mut fd : & FileDescriptor , mut amt : usize ) {
139
139
let mut buf = [ 0u8 ; 512 ] ;
140
- #[ allow( clippy:: unused_io_amount) ]
141
- loop {
140
+ while amt > 0 {
142
141
match fd. read ( & mut buf[ ..] ) {
143
- Err ( e) if e. kind ( ) == ErrorKind :: WouldBlock => break ,
142
+ Err ( e) if e. kind ( ) == ErrorKind :: WouldBlock => { }
144
143
Ok ( 0 ) => panic ! ( "unexpected EOF" ) ,
145
144
Err ( e) => panic ! ( "unexpected error: {:?}" , e) ,
146
- Ok ( _ ) => continue ,
145
+ Ok ( x ) => amt -= x ,
147
146
}
148
147
}
149
148
}
@@ -219,10 +218,10 @@ async fn reset_writable() {
219
218
let mut guard = afd_a. writable ( ) . await . unwrap ( ) ;
220
219
221
220
// Write until we get a WouldBlock. This also clears the ready state.
222
- while guard
223
- . try_io ( |_| afd_a. get_ref ( ) . write ( & [ 0 ; 512 ] [ ..] ) )
224
- . is_ok ( )
225
- { }
221
+ let mut bytes = 0 ;
222
+ while let Ok ( Ok ( amt ) ) = guard . try_io ( |_| afd_a. get_ref ( ) . write ( & [ 0 ; 512 ] [ ..] ) ) {
223
+ bytes += amt ;
224
+ }
226
225
227
226
// Writable state should be cleared now.
228
227
let writable = afd_a. writable ( ) ;
@@ -234,7 +233,7 @@ async fn reset_writable() {
234
233
}
235
234
236
235
// Read from the other side; we should become writable now.
237
- drain ( & b) ;
236
+ drain ( & b, bytes ) ;
238
237
239
238
let _ = writable. await . unwrap ( ) ;
240
239
}
@@ -386,7 +385,10 @@ async fn poll_fns() {
386
385
let afd_b = Arc :: new ( AsyncFd :: new ( b) . unwrap ( ) ) ;
387
386
388
387
// Fill up the write side of A
389
- while afd_a. get_ref ( ) . write ( & [ 0 ; 512 ] ) . is_ok ( ) { }
388
+ let mut bytes = 0 ;
389
+ while let Ok ( amt) = afd_a. get_ref ( ) . write ( & [ 0 ; 512 ] ) {
390
+ bytes += amt;
391
+ }
390
392
391
393
let waker = TestWaker :: new ( ) ;
392
394
@@ -446,7 +448,7 @@ async fn poll_fns() {
446
448
}
447
449
448
450
// Make it writable now
449
- drain ( afd_b. get_ref ( ) ) ;
451
+ drain ( afd_b. get_ref ( ) , bytes ) ;
450
452
451
453
// now we should be writable (ie - the waker for poll_write should still be registered after we wake the read side)
452
454
let _ = write_fut. await ;
0 commit comments