Don't drop the TcpListener after closing the proxy
This commit is contained in:
parent
7ab36f8ac3
commit
74a359061c
13
src/main.rs
13
src/main.rs
|
@ -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>(())
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue