@@ -135,15 +135,17 @@ 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) => {
146
+ amt -= x;
147
+ continue ;
148
+ }
147
149
}
148
150
}
149
151
}
@@ -219,10 +221,10 @@ async fn reset_writable() {
219
221
let mut guard = afd_a. writable ( ) . await . unwrap ( ) ;
220
222
221
223
// 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
- { }
224
+ let mut bytes = 0 ;
225
+ while let Ok ( Ok ( amt ) ) = guard . try_io ( |_| afd_a. get_ref ( ) . write ( & [ 0 ; 512 ] [ ..] ) ) {
226
+ bytes += amt ;
227
+ }
226
228
227
229
// Writable state should be cleared now.
228
230
let writable = afd_a. writable ( ) ;
@@ -234,7 +236,7 @@ async fn reset_writable() {
234
236
}
235
237
236
238
// Read from the other side; we should become writable now.
237
- drain ( & b) ;
239
+ drain ( & b, bytes ) ;
238
240
239
241
let _ = writable. await . unwrap ( ) ;
240
242
}
@@ -386,7 +388,10 @@ async fn poll_fns() {
386
388
let afd_b = Arc :: new ( AsyncFd :: new ( b) . unwrap ( ) ) ;
387
389
388
390
// Fill up the write side of A
389
- while afd_a. get_ref ( ) . write ( & [ 0 ; 512 ] ) . is_ok ( ) { }
391
+ let mut bytes = 0 ;
392
+ while let Ok ( amt) = afd_a. get_ref ( ) . write ( & [ 0 ; 512 ] ) {
393
+ bytes += amt;
394
+ }
390
395
391
396
let waker = TestWaker :: new ( ) ;
392
397
@@ -446,7 +451,7 @@ async fn poll_fns() {
446
451
}
447
452
448
453
// Make it writable now
449
- drain ( afd_b. get_ref ( ) ) ;
454
+ drain ( afd_b. get_ref ( ) , bytes ) ;
450
455
451
456
// now we should be writable (ie - the waker for poll_write should still be registered after we wake the read side)
452
457
let _ = write_fut. await ;
0 commit comments