Move TCP connection to inside the task

This commit is contained in:
Yash Karandikar 2022-06-24 20:40:17 +05:30
parent d9037a590f
commit f66a77dc62
2 changed files with 2 additions and 2 deletions

View file

@ -25,6 +25,6 @@ If no path is provided, `atp` will fall back to looking for `config.toml` in the
TODO: TODO:
- [ ] more descriptive error messages - [ ] more descriptive error messages
- [ ] use spawing + channels instead of `select!` - [ ] use spawning + channels instead of `select!`
- [ ] on-the-fly config reload? - [ ] on-the-fly config reload?
- [ ] UDP proxying? - [ ] UDP proxying?

View file

@ -20,9 +20,9 @@ async fn main() -> anyhow::Result<()> {
let listener = TcpListener::bind(SocketAddr::new("0.0.0.0".parse()?, port)).await?; let listener = TcpListener::bind(SocketAddr::new("0.0.0.0".parse()?, port)).await?;
loop { loop {
let (stream, _) = listener.accept().await?; let (stream, _) = listener.accept().await?;
let to_stream = TcpStream::connect(saddr).await?;
tokio::spawn(async move { tokio::spawn(async move {
let to_stream = TcpStream::connect(saddr).await?;
proxy(stream, to_stream).await?; proxy(stream, to_stream).await?;
Ok::<(), anyhow::Error>(()) Ok::<(), anyhow::Error>(())
}); });