diff --git a/src/main.rs b/src/main.rs index ab0701f..0dc445f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,10 @@ async fn main() -> anyhow::Result<()> { let ports: HashMap = toml::from_str(&contents)?; + let mut handles = Vec::with_capacity(ports.len()); + for (&saddr, &port) in &ports { - tokio::spawn(async move { + let handle = tokio::spawn(async move { let listener = TcpListener::bind(SocketAddr::new("0.0.0.0".parse()?, port)).await?; loop { let (stream, _) = listener.accept().await?; @@ -30,10 +32,15 @@ async fn main() -> anyhow::Result<()> { #[allow(unreachable_code)] Ok::<(), anyhow::Error>(()) }); + + handles.push(handle); } - #[allow(clippy::empty_loop)] - loop {} + for handle in handles { + handle.await??; + } + + Ok(()) } async fn proxy(left: TcpStream, right: TcpStream) -> anyhow::Result<()> {