Files
tokio/tokio-net/tests/tcp_split.rs
T
Carl Lerche 08099bb2d3 net: rewrite TcpStream::connect with async fn (#1497)
This also removes `TcpStream::connect_std` as the conversion functions
from `std` need to be rethought. A note tracking this has been added
to #1209.
2019-08-27 12:08:28 -07:00

26 lines
759 B
Rust

use tokio_net::tcp::{TcpListener, TcpStream};
#[tokio::test]
async fn split_reunite() -> std::io::Result<()> {
let listener = TcpListener::bind(&"127.0.0.1:0".parse().unwrap())?;
let addr = listener.local_addr()?;
let stream = TcpStream::connect(&addr).await?;
let (r, w) = stream.split();
assert!(r.reunite(w).is_ok());
Ok(())
}
#[tokio::test]
async fn split_reunite_error() -> std::io::Result<()> {
let listener = TcpListener::bind(&"127.0.0.1:0".parse().unwrap())?;
let addr = listener.local_addr()?;
let stream = TcpStream::connect(&addr).await?;
let stream1 = TcpStream::connect(&addr).await?;
let (r, _) = stream.split();
let (_, w) = stream1.split();
assert!(r.reunite(w).is_err());
Ok(())
}