meant to add this earlier

This commit is contained in:
michael-bailey 2022-02-25 21:17:56 +00:00
parent d904e83f14
commit ccd0cb1c5e
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,22 @@
use std::io::{Error};
use std::net::SocketAddr;
use tokio::join;
use tokio::net::{TcpStream,TcpListener};
use crate::connection::Connection;
pub async fn create_connection_pair()
-> Result<(Connection, (Connection, SocketAddr )), Error> {
let listener: TcpListener = TcpListener::bind("localhost:0000").await?;
let port = listener.local_addr()?.port();
let (server_res,client_res) = join!(
async { TcpStream::connect(format!("localhost:{}", port)).await },
async { listener.accept().await }
);
let (client,addr) = client_res?;
let server = Connection::from(server_res?);
let client = Connection::from(client);
Ok((server,(client,addr)))
}

View File

@ -0,0 +1,3 @@
mod connection_pair;
pub use connection_pair::create_connection_pair;