tokio-rs / tokio-core

I/O primitives and event loop for async I/O in Rust
Apache License 2.0
640 stars 115 forks source link

Proxy example - is reconnecting to the server every loop necessary? #329

Open timClicks opened 6 years ago

timClicks commented 6 years ago

Apologies if this is the incorrect place to ask for help! I'm attempting to grok some of the examples and just wondering if I'm reading something correctly..

In the proxy example, the code appears to connect to the remote server at every message?

    let done = socket.incoming().for_each(move |(client, client_addr)| {
        let server = TcpStream::connect(&server_addr, &handle);  // ??
        let amounts = server.and_then(move |server| {
            // ...
        });
        // ...
        Ok(())
});

Perhaps I'm making a mistake regard what socket is iterating over in the call to socket.incoming().for_each()? How many iterations per connection would one expect on a long lived connection?