From 45f0ab234fdd82c058aef660bdb2970f9ec4daf5 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 5 Nov 2024 18:56:50 +0100 Subject: [PATCH] Refactored networking code --- runtime/src/lib.rs | 3 ++- runtime/src/main.rs | 5 ----- runtime/src/network.rs | 7 +++++++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 runtime/src/network.rs diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 7e1c3226..25001603 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1,3 +1,4 @@ pub mod encryption; pub mod log; -pub mod environment; \ No newline at end of file +pub mod environment; +pub mod network; \ No newline at end of file diff --git a/runtime/src/main.rs b/runtime/src/main.rs index 48d45d2f..59ac51aa 100644 --- a/runtime/src/main.rs +++ b/runtime/src/main.rs @@ -517,11 +517,6 @@ async fn dotnet_ready(_token: APIToken) { } } -fn get_available_port() -> Option { - TcpListener::bind(("127.0.0.1", 0)) - .map(|listener| listener.local_addr().unwrap().port()) - .ok() -} fn stop_servers() { if let Some(server_process) = DOTNET_SERVER.lock().unwrap().take() { diff --git a/runtime/src/network.rs b/runtime/src/network.rs new file mode 100644 index 00000000..e20e1a06 --- /dev/null +++ b/runtime/src/network.rs @@ -0,0 +1,7 @@ +use std::net::TcpListener; + +pub fn get_available_port() -> Option { + TcpListener::bind(("127.0.0.1", 0)) + .map(|listener| listener.local_addr().unwrap().port()) + .ok() +} \ No newline at end of file