Skip to content

Concurrency in the tcp_echo_server example #25

@Heap-Hop

Description

@Heap-Hop
use wstd::io;
use wstd::iter::AsyncIterator;
use wstd::net::TcpListener;

#[wstd::main]
async fn main() -> io::Result<()> {
    let listener = TcpListener::bind("127.0.0.1:8080").await?;
    println!("Listening on {}", listener.local_addr()?);
    println!("type `nc localhost 8080` to create a TCP client");

    let mut incoming = listener.incoming();
    while let Some(stream) = incoming.next().await {
        let stream = stream?;
        println!("Accepted from: {}", stream.peer_addr()?);
        io::copy(&stream, &stream).await?;
    }
    Ok(())
}

Currently, the main example in this project is non-concurrent.
io::copy(&stream, &stream).await blocks new incoming streams.
It doesn’t make much sense to use an async runtime if streams are processed sequentially.

It would be great to see this example become concurrent.

Related:
#17
yoshuawuyts/wasm-http-tools#7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions