@@ -122,6 +122,36 @@ impl AsyncWrite for Expected {
122
122
}
123
123
}
124
124
125
+ struct Eof ;
126
+
127
+ impl AsyncRead for Eof {
128
+ fn poll_read (
129
+ self : Pin < & mut Self > ,
130
+ _cx : & mut Context < ' _ > ,
131
+ _buf : & mut ReadBuf < ' _ > ,
132
+ ) -> Poll < io:: Result < ( ) > > {
133
+ Poll :: Ready ( Ok ( ( ) ) )
134
+ }
135
+ }
136
+
137
+ impl AsyncWrite for Eof {
138
+ fn poll_write (
139
+ self : Pin < & mut Self > ,
140
+ _cx : & mut Context < ' _ > ,
141
+ _buf : & [ u8 ] ,
142
+ ) -> Poll < io:: Result < usize > > {
143
+ Poll :: Ready ( Ok ( 0 ) )
144
+ }
145
+
146
+ fn poll_flush ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
147
+ Poll :: Ready ( Ok ( ( ) ) )
148
+ }
149
+
150
+ fn poll_shutdown ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
151
+ Poll :: Ready ( Ok ( ( ) ) )
152
+ }
153
+ }
154
+
125
155
#[ tokio:: test]
126
156
async fn stream_good ( ) -> io:: Result < ( ) > {
127
157
stream_good_impl ( false ) . await
@@ -254,6 +284,23 @@ async fn stream_handshake_eof() -> io::Result<()> {
254
284
Ok ( ( ) ) as io:: Result < ( ) >
255
285
}
256
286
287
+ #[ tokio:: test]
288
+ async fn stream_handshake_write_eof ( ) -> io:: Result < ( ) > {
289
+ let ( _, mut client) = make_pair ( ) ;
290
+
291
+ let mut io = Eof ;
292
+ let mut stream = Stream :: new ( & mut io, & mut client) ;
293
+
294
+ let mut cx = Context :: from_waker ( noop_waker_ref ( ) ) ;
295
+ let r = stream. handshake ( & mut cx) ;
296
+ assert_eq ! (
297
+ r. map_err( |err| err. kind( ) ) ,
298
+ Poll :: Ready ( Err ( io:: ErrorKind :: WriteZero ) )
299
+ ) ;
300
+
301
+ Ok ( ( ) ) as io:: Result < ( ) >
302
+ }
303
+
257
304
// see https://github.com/tokio-rs/tls/issues/77
258
305
#[ tokio:: test]
259
306
async fn stream_handshake_regression_issues_77 ( ) -> io:: Result < ( ) > {
@@ -291,6 +338,25 @@ async fn stream_eof() -> io::Result<()> {
291
338
Ok ( ( ) ) as io:: Result < ( ) >
292
339
}
293
340
341
+ #[ tokio:: test]
342
+ async fn stream_write_zero ( ) -> io:: Result < ( ) > {
343
+ let ( server, mut client) = make_pair ( ) ;
344
+ let mut server = Connection :: from ( server) ;
345
+ poll_fn ( |cx| do_handshake ( & mut client, & mut server, cx) ) . await ?;
346
+
347
+ let mut io = Eof ;
348
+ let mut stream = Stream :: new ( & mut io, & mut client) ;
349
+
350
+ stream. write ( b"1" ) . await . unwrap ( ) ;
351
+ let result = stream. flush ( ) . await ;
352
+ assert_eq ! (
353
+ result. err( ) . map( |e| e. kind( ) ) ,
354
+ Some ( io:: ErrorKind :: WriteZero )
355
+ ) ;
356
+
357
+ Ok ( ( ) ) as io:: Result < ( ) >
358
+ }
359
+
294
360
fn make_pair ( ) -> ( ServerConnection , ClientConnection ) {
295
361
let ( sconfig, cconfig) = utils:: make_configs ( ) ;
296
362
let server = ServerConnection :: new ( Arc :: new ( sconfig) ) . unwrap ( ) ;
0 commit comments