1#![warn(rust_2018_idioms)]
2#![cfg(feature = "full")]
3
4use std::io::IoSlice;
5use tokio::io::{AsyncReadExt, AsyncWriteExt};
6
7const HELLO: &[u8] = b"hello world...";
8
9#[tokio::test]
10async fn write_vectored() {
11 let (mut client, mut server) = tokio::io::duplex(64);
12
13 let ret = client
14 .write_vectored(&[IoSlice::new(HELLO), IoSlice::new(HELLO)])
15 .await
16 .unwrap();
17 assert_eq!(ret, HELLO.len() * 2);
18
19 client.flush().await.unwrap();
20 drop(client);
21
22 let mut buf = Vec::with_capacity(HELLO.len() * 2);
23 let bytes_read = server.read_to_end(&mut buf).await.unwrap();
24
25 assert_eq!(bytes_read, HELLO.len() * 2);
26 assert_eq!(buf, [HELLO, HELLO].concat());
27}
28
29#[tokio::test]
30async fn write_vectored_and_shutdown() {
31 let (mut client, mut server) = tokio::io::duplex(64);
32
33 let ret = client
34 .write_vectored(&[IoSlice::new(HELLO), IoSlice::new(HELLO)])
35 .await
36 .unwrap();
37 assert_eq!(ret, HELLO.len() * 2);
38
39 client.shutdown().await.unwrap();
40 drop(client);
41
42 let mut buf = Vec::with_capacity(HELLO.len() * 2);
43 let bytes_read = server.read_to_end(&mut buf).await.unwrap();
44
45 assert_eq!(bytes_read, HELLO.len() * 2);
46 assert_eq!(buf, [HELLO, HELLO].concat());
47}
48