Don't drop the TcpListener after closing the proxy

This commit is contained in:
Yash Karandikar 2022-06-24 18:58:12 +05:30
parent 7ab36f8ac3
commit 74a359061c

View file

@ -16,11 +16,18 @@ async fn main() -> anyhow::Result<()> {
for (&saddr, &port) in &ports {
tokio::spawn(async move {
let listener = TcpListener::bind(SocketAddr::new("0.0.0.0".parse()?, port)).await?;
let (stream, _) = listener.accept().await?;
let to_stream = TcpStream::connect(saddr).await?;
loop {
let (stream, _) = listener.accept().await?;
let to_stream = TcpStream::connect(saddr).await?;
proxy(stream, to_stream).await?;
tokio::spawn(async move {
proxy(stream, to_stream).await?;
Ok::<(), anyhow::Error>(())
});
}
// We still need this statement in order to specify the return type
#[allow(unreachable_code)]
Ok::<(), anyhow::Error>(())
});
}