File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,22 @@ impl AsyncWrite for Sink {
6262 Poll :: Ready ( Ok ( buf. len ( ) ) )
6363 }
6464
65+ #[ inline]
66+ fn is_write_vectored ( & self ) -> bool {
67+ true
68+ }
69+
70+ #[ inline]
71+ fn poll_write_vectored (
72+ self : Pin < & mut Self > ,
73+ cx : & mut Context < ' _ > ,
74+ bufs : & [ io:: IoSlice < ' _ > ] ,
75+ ) -> Poll < Result < usize , io:: Error > > {
76+ ready ! ( crate :: trace:: trace_leaf( cx) ) ;
77+ ready ! ( poll_proceed_and_make_progress( cx) ) ;
78+ Poll :: Ready ( Ok ( bufs. iter ( ) . map ( |b| b. len ( ) ) . sum ( ) ) )
79+ }
80+
6581 #[ inline]
6682 fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
6783 ready ! ( crate :: trace:: trace_leaf( cx) ) ;
Original file line number Diff line number Diff line change 99 )
1010) ) ]
1111
12- use tokio:: io:: AsyncWriteExt ;
12+ use std:: io:: IoSlice ;
13+ use tokio:: io:: { AsyncWrite , AsyncWriteExt } ;
1314
1415#[ tokio:: test]
1516async fn sink_poll_write_is_cooperative ( ) {
@@ -25,6 +26,34 @@ async fn sink_poll_write_is_cooperative() {
2526 }
2627}
2728
29+ #[ tokio:: test]
30+ async fn sink_write_vectored_consumes_all_buffers ( ) {
31+ let mut sink = tokio:: io:: sink ( ) ;
32+ assert ! ( sink. is_write_vectored( ) ) ;
33+
34+ let bufs = [
35+ IoSlice :: new ( b"" ) ,
36+ IoSlice :: new ( b"hello" ) ,
37+ IoSlice :: new ( b"" ) ,
38+ IoSlice :: new ( b"world" ) ,
39+ ] ;
40+ assert_eq ! ( sink. write_vectored( & bufs) . await . unwrap( ) , 10 ) ;
41+ }
42+
43+ #[ tokio:: test]
44+ async fn sink_poll_write_vectored_is_cooperative ( ) {
45+ tokio:: select! {
46+ biased;
47+ _ = async {
48+ let bufs = [ IoSlice :: new( b"hello" ) , IoSlice :: new( b"world" ) ] ;
49+ loop {
50+ assert_eq!( tokio:: io:: sink( ) . write_vectored( & bufs) . await . unwrap( ) , 10 ) ;
51+ }
52+ } => { } ,
53+ _ = tokio:: task:: yield_now( ) => { }
54+ }
55+ }
56+
2857#[ tokio:: test]
2958async fn sink_poll_flush_is_cooperative ( ) {
3059 tokio:: select! {
You can’t perform that action at this time.
0 commit comments