@@ -6,7 +6,7 @@ use h2::{self, RecvError, SendError};
6
6
use futures:: future:: poll_fn;
7
7
use futures:: { ready, Stream , StreamExt } ;
8
8
9
- use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt } ;
9
+ use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt , ReadBuf } ;
10
10
11
11
use super :: assert:: assert_frame_eq;
12
12
use std:: pin:: Pin ;
@@ -147,10 +147,11 @@ impl Handle {
147
147
poll_fn ( move |cx| {
148
148
while buf. has_remaining ( ) {
149
149
let res = Pin :: new ( self . codec . get_mut ( ) )
150
- . poll_write_buf ( cx, & mut buf)
150
+ . poll_write ( cx, & mut buf. bytes ( ) )
151
151
. map_err ( |e| panic ! ( "write err={:?}" , e) ) ;
152
152
153
- ready ! ( res) . unwrap ( ) ;
153
+ let n = ready ! ( res) . unwrap ( ) ;
154
+ buf. advance ( n) ;
154
155
}
155
156
156
157
Poll :: Ready ( ( ) )
@@ -294,8 +295,8 @@ impl AsyncRead for Handle {
294
295
fn poll_read (
295
296
mut self : Pin < & mut Self > ,
296
297
cx : & mut Context < ' _ > ,
297
- buf : & mut [ u8 ] ,
298
- ) -> Poll < io:: Result < usize > > {
298
+ buf : & mut ReadBuf ,
299
+ ) -> Poll < io:: Result < ( ) > > {
299
300
Pin :: new ( self . codec . get_mut ( ) ) . poll_read ( cx, buf)
300
301
}
301
302
}
@@ -344,29 +345,29 @@ impl AsyncRead for Mock {
344
345
fn poll_read (
345
346
self : Pin < & mut Self > ,
346
347
cx : & mut Context < ' _ > ,
347
- buf : & mut [ u8 ] ,
348
- ) -> Poll < io:: Result < usize > > {
348
+ buf : & mut ReadBuf ,
349
+ ) -> Poll < io:: Result < ( ) > > {
349
350
assert ! (
350
- buf. len ( ) > 0 ,
351
+ buf. remaining ( ) > 0 ,
351
352
"attempted read with zero length buffer... wut?"
352
353
) ;
353
354
354
355
let mut me = self . pipe . inner . lock ( ) . unwrap ( ) ;
355
356
356
357
if me. rx . is_empty ( ) {
357
358
if me. closed {
358
- return Poll :: Ready ( Ok ( 0 ) ) ;
359
+ return Poll :: Ready ( Ok ( ( ) ) ) ;
359
360
}
360
361
361
362
me. rx_task = Some ( cx. waker ( ) . clone ( ) ) ;
362
363
return Poll :: Pending ;
363
364
}
364
365
365
- let n = cmp:: min ( buf. len ( ) , me. rx . len ( ) ) ;
366
- buf[ ..n ] . copy_from_slice ( & me. rx [ ..n] ) ;
366
+ let n = cmp:: min ( buf. remaining ( ) , me. rx . len ( ) ) ;
367
+ buf. put_slice ( & me. rx [ ..n] ) ;
367
368
me. rx . drain ( ..n) ;
368
369
369
- Poll :: Ready ( Ok ( n ) )
370
+ Poll :: Ready ( Ok ( ( ) ) )
370
371
}
371
372
}
372
373
@@ -427,29 +428,29 @@ impl AsyncRead for Pipe {
427
428
fn poll_read (
428
429
self : Pin < & mut Self > ,
429
430
cx : & mut Context < ' _ > ,
430
- buf : & mut [ u8 ] ,
431
- ) -> Poll < io:: Result < usize > > {
431
+ buf : & mut ReadBuf ,
432
+ ) -> Poll < io:: Result < ( ) > > {
432
433
assert ! (
433
- buf. len ( ) > 0 ,
434
+ buf. remaining ( ) > 0 ,
434
435
"attempted read with zero length buffer... wut?"
435
436
) ;
436
437
437
438
let mut me = self . inner . lock ( ) . unwrap ( ) ;
438
439
439
440
if me. tx . is_empty ( ) {
440
441
if me. closed {
441
- return Poll :: Ready ( Ok ( 0 ) ) ;
442
+ return Poll :: Ready ( Ok ( ( ) ) ) ;
442
443
}
443
444
444
445
me. tx_task = Some ( cx. waker ( ) . clone ( ) ) ;
445
446
return Poll :: Pending ;
446
447
}
447
448
448
- let n = cmp:: min ( buf. len ( ) , me. tx . len ( ) ) ;
449
- buf[ ..n ] . copy_from_slice ( & me. tx [ ..n] ) ;
449
+ let n = cmp:: min ( buf. remaining ( ) , me. tx . len ( ) ) ;
450
+ buf. put_slice ( & me. tx [ ..n] ) ;
450
451
me. tx . drain ( ..n) ;
451
452
452
- Poll :: Ready ( Ok ( n ) )
453
+ Poll :: Ready ( Ok ( ( ) ) )
453
454
}
454
455
}
455
456
@@ -479,5 +480,5 @@ impl AsyncWrite for Pipe {
479
480
}
480
481
481
482
pub async fn idle_ms ( ms : u64 ) {
482
- tokio:: time:: delay_for ( Duration :: from_millis ( ms) ) . await
483
+ tokio:: time:: sleep ( Duration :: from_millis ( ms) ) . await
483
484
}
0 commit comments