@@ -6,7 +6,7 @@ use h2::{self, RecvError, SendError};
66use futures:: future:: poll_fn;
77use futures:: { ready, Stream , StreamExt } ;
88
9- use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt } ;
9+ use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt , ReadBuf } ;
1010
1111use super :: assert:: assert_frame_eq;
1212use std:: pin:: Pin ;
@@ -147,10 +147,11 @@ impl Handle {
147147 poll_fn ( move |cx| {
148148 while buf. has_remaining ( ) {
149149 let res = Pin :: new ( self . codec . get_mut ( ) )
150- . poll_write_buf ( cx, & mut buf)
150+ . poll_write ( cx, & mut buf. bytes ( ) )
151151 . map_err ( |e| panic ! ( "write err={:?}" , e) ) ;
152152
153- ready ! ( res) . unwrap ( ) ;
153+ let n = ready ! ( res) . unwrap ( ) ;
154+ buf. advance ( n) ;
154155 }
155156
156157 Poll :: Ready ( ( ) )
@@ -294,8 +295,8 @@ impl AsyncRead for Handle {
294295 fn poll_read (
295296 mut self : Pin < & mut Self > ,
296297 cx : & mut Context < ' _ > ,
297- buf : & mut [ u8 ] ,
298- ) -> Poll < io:: Result < usize > > {
298+ buf : & mut ReadBuf ,
299+ ) -> Poll < io:: Result < ( ) > > {
299300 Pin :: new ( self . codec . get_mut ( ) ) . poll_read ( cx, buf)
300301 }
301302}
@@ -344,29 +345,29 @@ impl AsyncRead for Mock {
344345 fn poll_read (
345346 self : Pin < & mut Self > ,
346347 cx : & mut Context < ' _ > ,
347- buf : & mut [ u8 ] ,
348- ) -> Poll < io:: Result < usize > > {
348+ buf : & mut ReadBuf ,
349+ ) -> Poll < io:: Result < ( ) > > {
349350 assert ! (
350- buf. len ( ) > 0 ,
351+ buf. remaining ( ) > 0 ,
351352 "attempted read with zero length buffer... wut?"
352353 ) ;
353354
354355 let mut me = self . pipe . inner . lock ( ) . unwrap ( ) ;
355356
356357 if me. rx . is_empty ( ) {
357358 if me. closed {
358- return Poll :: Ready ( Ok ( 0 ) ) ;
359+ return Poll :: Ready ( Ok ( ( ) ) ) ;
359360 }
360361
361362 me. rx_task = Some ( cx. waker ( ) . clone ( ) ) ;
362363 return Poll :: Pending ;
363364 }
364365
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] ) ;
367368 me. rx . drain ( ..n) ;
368369
369- Poll :: Ready ( Ok ( n ) )
370+ Poll :: Ready ( Ok ( ( ) ) )
370371 }
371372}
372373
@@ -427,29 +428,29 @@ impl AsyncRead for Pipe {
427428 fn poll_read (
428429 self : Pin < & mut Self > ,
429430 cx : & mut Context < ' _ > ,
430- buf : & mut [ u8 ] ,
431- ) -> Poll < io:: Result < usize > > {
431+ buf : & mut ReadBuf ,
432+ ) -> Poll < io:: Result < ( ) > > {
432433 assert ! (
433- buf. len ( ) > 0 ,
434+ buf. remaining ( ) > 0 ,
434435 "attempted read with zero length buffer... wut?"
435436 ) ;
436437
437438 let mut me = self . inner . lock ( ) . unwrap ( ) ;
438439
439440 if me. tx . is_empty ( ) {
440441 if me. closed {
441- return Poll :: Ready ( Ok ( 0 ) ) ;
442+ return Poll :: Ready ( Ok ( ( ) ) ) ;
442443 }
443444
444445 me. tx_task = Some ( cx. waker ( ) . clone ( ) ) ;
445446 return Poll :: Pending ;
446447 }
447448
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] ) ;
450451 me. tx . drain ( ..n) ;
451452
452- Poll :: Ready ( Ok ( n ) )
453+ Poll :: Ready ( Ok ( ( ) ) )
453454 }
454455}
455456
@@ -479,5 +480,5 @@ impl AsyncWrite for Pipe {
479480}
480481
481482pub 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
483484}
0 commit comments