protohack

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit e77b4bc6e5a705ef31d0de6f00dee739efdde8ce
parent 2f2f87b4c56ca646e525621e562567fc72547362
Author: minerva-jupiter <ryouturn@gmail.com>
Date:   Sun, 29 Mar 2026 15:25:41 +0900

feat(smoke): Implement concurrent echo server

Diffstat:
Msrc/bin/smoke.rs | 20++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/bin/smoke.rs b/src/bin/smoke.rs @@ -1,22 +1,14 @@ -use tokio::{ - self, - io::{AsyncReadExt, AsyncWriteExt}, -}; #[tokio::main] async fn main() -> std::io::Result<()> { println!("Smoketest server has started"); let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?; loop { - match listener.accept().await { - Ok((mut socket, _)) => { - let mut buf = Vec::with_capacity(4096); - socket.read_buf(&mut buf).await?; - println!("{:?}", buf); - socket.write_all(&buf).await?; + let (mut socket, _) = listener.accept().await?; + tokio::spawn(async move { + let (mut rd, mut wr) = socket.split(); + if let Err(e) = tokio::io::copy(&mut rd, &mut wr).await { + println!("echo error: {}", e); } - Err(e) => { - return Err(e.into()); - } - } + }); } }