Skip to content

Commit

Permalink
Simplify old code
Browse files Browse the repository at this point in the history
  • Loading branch information
quackitsquinn committed May 19, 2024
1 parent 7ed9c74 commit b0dde40
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions lazuli_core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,16 @@ mod test_utils {
/// (client, server)
pub(super) fn make_client_server_pair() -> (Client, Client) {
use std::net::TcpListener;
let server = TcpListener::bind((Ipv4Addr::LOCALHOST, 0));

if let Err(e) = server {
// If the port is in use, try again.
if e.kind() == std::io::ErrorKind::AddrInUse {
return make_client_server_pair();
} else {
panic!("Failed to bind server: {}", e);
}
}

let server = server.unwrap();
let server = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).expect("Failed to create server!");

let client = Client::connect(server.local_addr().unwrap()).unwrap();
let server = server.accept().unwrap().0;

(client, Client::from_stream(server))
}

/// Creates a Server. Expects the OS to assign a port.
pub(super) fn make_server() -> Server {
let server = Server::new((Ipv4Addr::LOCALHOST, 0));

if let Err(e) = server {
// If the port is in use, try again.
if e.kind() == std::io::ErrorKind::AddrInUse {
return make_server();
} else {
panic!("Failed to bind server: {}", e);
}
}

server.unwrap()
Server::new((Ipv4Addr::LOCALHOST, 0)).expect("Failed to create server!")
}

/// Tests sending and receiving data. Convenience function for testing.
Expand Down

0 comments on commit b0dde40

Please sign in to comment.