1 | #![warn (rust_2018_idioms)] |
2 | #![cfg (all(feature = "full" , not(target_os = "wasi" )))] // Wasi doesn't support bind |
3 | |
4 | use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; |
5 | use tokio::net::{TcpListener, TcpStream}; |
6 | use tokio_test::assert_ok; |
7 | |
8 | #[tokio::test ] |
9 | async fn shutdown() { |
10 | let srv = assert_ok!(TcpListener::bind("127.0.0.1:0" ).await); |
11 | let addr = assert_ok!(srv.local_addr()); |
12 | |
13 | tokio::spawn(async move { |
14 | let mut stream = assert_ok!(TcpStream::connect(&addr).await); |
15 | |
16 | assert_ok!(AsyncWriteExt::shutdown(&mut stream).await); |
17 | |
18 | let mut buf = [0u8; 1]; |
19 | let n = assert_ok!(stream.read(&mut buf).await); |
20 | assert_eq!(n, 0); |
21 | }); |
22 | |
23 | let (mut stream, _) = assert_ok!(srv.accept().await); |
24 | let (mut rd, mut wr) = stream.split(); |
25 | |
26 | let n = assert_ok!(io::copy(&mut rd, &mut wr).await); |
27 | assert_eq!(n, 0); |
28 | } |
29 | |