-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement write_vectored for DuplexStream
- Loading branch information
1 parent
8ea303e
commit f619420
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(feature = "full")] | ||
|
||
use std::io::IoSlice; | ||
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | ||
|
||
const HELLO: &[u8] = b"hello world..."; | ||
|
||
#[tokio::test] | ||
async fn write_vectored() { | ||
let (mut client, mut server) = tokio::io::duplex(64); | ||
|
||
let ret = client | ||
.write_vectored(&[IoSlice::new(HELLO), IoSlice::new(HELLO)]) | ||
.await | ||
.unwrap(); | ||
assert_eq!(ret, HELLO.len() * 2); | ||
|
||
client.flush().await.unwrap(); | ||
drop(client); | ||
|
||
let mut buf = Vec::with_capacity(HELLO.len() * 2); | ||
let bytes_read = server.read_to_end(&mut buf).await.unwrap(); | ||
|
||
assert_eq!(bytes_read, HELLO.len() * 2); | ||
assert_eq!(buf, [HELLO, HELLO].concat()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn write_vectored_and_shutdown() { | ||
let (mut client, mut server) = tokio::io::duplex(64); | ||
|
||
let ret = client | ||
.write_vectored(&[IoSlice::new(HELLO), IoSlice::new(HELLO)]) | ||
.await | ||
.unwrap(); | ||
assert_eq!(ret, HELLO.len() * 2); | ||
|
||
client.shutdown().await.unwrap(); | ||
drop(client); | ||
|
||
let mut buf = Vec::with_capacity(HELLO.len() * 2); | ||
let bytes_read = server.read_to_end(&mut buf).await.unwrap(); | ||
|
||
assert_eq!(bytes_read, HELLO.len() * 2); | ||
assert_eq!(buf, [HELLO, HELLO].concat()); | ||
} |