mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-11-03 14:02:47 +00:00
A sealed `net::ToSocketAddrs` trait is added. This trait is not intended to be used by users. Instead, it is an argument to `connect` and `bind` functions. The operating system's DNS lookup functionality is used. Blocking operations are performed on a thread pool in order to avoid blocking the runtime.
26 lines
735 B
Rust
26 lines
735 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").await?;
|
|
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").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();
|
|
assert!(r.reunite(w).is_err());
|
|
Ok(())
|
|
}
|