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.
This commit is contained in:
Carl Lerche
2019-08-27 12:08:28 -07:00
committed by GitHub
parent 807d536846
commit 08099bb2d3
2 changed files with 21 additions and 108 deletions
+5 -3
View File
@@ -3,7 +3,8 @@ 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 stream = TcpStream::connect(&listener.local_addr()?).await?;
let addr = listener.local_addr()?;
let stream = TcpStream::connect(&addr).await?;
let (r, w) = stream.split();
assert!(r.reunite(w).is_ok());
@@ -13,8 +14,9 @@ async fn split_reunite() -> std::io::Result<()> {
#[tokio::test]
async fn split_reunite_error() -> std::io::Result<()> {
let listener = TcpListener::bind(&"127.0.0.1:0".parse().unwrap())?;
let stream = TcpStream::connect(&listener.local_addr()?).await?;
let stream1 = TcpStream::connect(&listener.local_addr()?).await?;
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();