File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -84,9 +84,14 @@ impl<R: AsyncRead> AsyncRead for Take<R> {
84
84
return Poll :: Ready ( Ok ( ( ) ) ) ;
85
85
}
86
86
87
+ let buf_ptr = buf. filled ( ) . as_ptr ( ) ;
88
+
87
89
let me = self . project ( ) ;
88
90
let mut b = buf. take ( * me. limit_ as usize ) ;
91
+
89
92
ready ! ( me. inner. poll_read( cx, & mut b) ) ?;
93
+ assert_eq ! ( b. filled( ) . as_ptr( ) , buf_ptr) ;
94
+
90
95
let n = b. filled ( ) . len ( ) ;
91
96
92
97
// We need to update the original ReadBuf
Original file line number Diff line number Diff line change 1
1
#![ warn( rust_2018_idioms) ]
2
2
#![ cfg( feature = "full" ) ]
3
3
4
- use tokio:: io:: AsyncReadExt ;
4
+ use std:: pin:: Pin ;
5
+ use std:: task:: { Context , Poll } ;
6
+ use tokio:: io:: { self , AsyncRead , AsyncReadExt , ReadBuf } ;
5
7
use tokio_test:: assert_ok;
6
8
7
9
#[ tokio:: test]
@@ -14,3 +16,29 @@ async fn take() {
14
16
assert_eq ! ( n, 4 ) ;
15
17
assert_eq ! ( & buf, & b"hell\0 \0 " [ ..] ) ;
16
18
}
19
+
20
+ struct BadReader ;
21
+
22
+ impl AsyncRead for BadReader {
23
+ fn poll_read (
24
+ self : Pin < & mut Self > ,
25
+ _cx : & mut Context < ' _ > ,
26
+ read_buf : & mut ReadBuf < ' _ > ,
27
+ ) -> Poll < io:: Result < ( ) > > {
28
+ let vec = vec ! [ 0 ; 10 ] ;
29
+
30
+ let mut buf = ReadBuf :: new ( vec. leak ( ) ) ;
31
+ buf. put_slice ( & [ 123 ; 10 ] ) ;
32
+ * read_buf = buf;
33
+
34
+ Poll :: Ready ( Ok ( ( ) ) )
35
+ }
36
+ }
37
+
38
+ #[ tokio:: test]
39
+ #[ should_panic]
40
+ async fn bad_reader_fails ( ) {
41
+ let mut buf = Vec :: with_capacity ( 10 ) ;
42
+
43
+ BadReader . take ( 10 ) . read_buf ( & mut buf) . await . unwrap ( ) ;
44
+ }
You can’t perform that action at this time.
0 commit comments