@@ -7,6 +7,10 @@ use crate::io::{self, BufRead, BufReader, Read, Write};
7
7
use crate :: task:: { Context , Poll } ;
8
8
use crate :: utils:: Context as _;
9
9
10
+ // Note: There are two otherwise-identical implementations of this
11
+ // function because unstable has removed the ?Sized bound for the
12
+ // reader and writer
13
+
10
14
/// Copies the entire contents of a reader into a writer.
11
15
///
12
16
/// This function will continuously read data from `reader` and then
57
61
#[ pin]
58
62
writer: W ,
59
63
amt: u64 ,
64
+ reader_eof: bool
60
65
}
61
66
}
62
67
@@ -69,13 +74,20 @@ where
69
74
70
75
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
71
76
let mut this = self . project ( ) ;
77
+
72
78
loop {
73
- let buffer = futures_core:: ready!( this. reader. as_mut( ) . poll_fill_buf( cx) ) ?;
74
- if buffer. is_empty ( ) {
79
+ if * this. reader_eof {
75
80
futures_core:: ready!( this. writer. as_mut( ) . poll_flush( cx) ) ?;
76
81
return Poll :: Ready ( Ok ( * this. amt ) ) ;
77
82
}
78
83
84
+ let buffer = futures_core:: ready!( this. reader. as_mut( ) . poll_fill_buf( cx) ) ?;
85
+
86
+ if buffer. is_empty ( ) {
87
+ * this. reader_eof = true ;
88
+ continue ;
89
+ }
90
+
79
91
let i = futures_core:: ready!( this. writer. as_mut( ) . poll_write( cx, buffer) ) ?;
80
92
if i == 0 {
81
93
return Poll :: Ready ( Err ( io:: ErrorKind :: WriteZero . into ( ) ) ) ;
89
101
let future = CopyFuture {
90
102
reader : BufReader :: new ( reader) ,
91
103
writer,
104
+ reader_eof : false ,
92
105
amt : 0 ,
93
106
} ;
94
107
future. await . context ( || String :: from ( "io::copy failed" ) )
@@ -144,6 +157,7 @@ where
144
157
#[ pin]
145
158
writer: W ,
146
159
amt: u64 ,
160
+ reader_eof: bool
147
161
}
148
162
}
149
163
@@ -156,13 +170,20 @@ where
156
170
157
171
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
158
172
let mut this = self . project ( ) ;
173
+
159
174
loop {
160
- let buffer = futures_core:: ready!( this. reader. as_mut( ) . poll_fill_buf( cx) ) ?;
161
- if buffer. is_empty ( ) {
175
+ if * this. reader_eof {
162
176
futures_core:: ready!( this. writer. as_mut( ) . poll_flush( cx) ) ?;
163
177
return Poll :: Ready ( Ok ( * this. amt ) ) ;
164
178
}
165
179
180
+ let buffer = futures_core:: ready!( this. reader. as_mut( ) . poll_fill_buf( cx) ) ?;
181
+
182
+ if buffer. is_empty ( ) {
183
+ * this. reader_eof = true ;
184
+ continue ;
185
+ }
186
+
166
187
let i = futures_core:: ready!( this. writer. as_mut( ) . poll_write( cx, buffer) ) ?;
167
188
if i == 0 {
168
189
return Poll :: Ready ( Err ( io:: ErrorKind :: WriteZero . into ( ) ) ) ;
@@ -176,6 +197,7 @@ where
176
197
let future = CopyFuture {
177
198
reader : BufReader :: new ( reader) ,
178
199
writer,
200
+ reader_eof : false ,
179
201
amt : 0 ,
180
202
} ;
181
203
future. await . context ( || String :: from ( "io::copy failed" ) )
0 commit comments