From: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com> Date: Thu, 16 May 2024 08:14:46 +0000 (+0200) Subject: Fix: configure and read from socket correctly in 08/05 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=5d68add5ad6cc8911fc340c55b3d06800edd88c8;p=rust_exercises.git Fix: configure and read from socket correctly in 08/05 --- diff --git a/Cargo.lock b/Cargo.lock index e725be7..c572c57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,9 +519,9 @@ checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -678,9 +678,9 @@ version = "0.1.0" [[package]] name = "syn" -version = "2.0.60" +version = "2.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" dependencies = [ "proc-macro2", "quote", diff --git a/exercises/08_futures/05_blocking/src/lib.rs b/exercises/08_futures/05_blocking/src/lib.rs index ced01ab..e9b4354 100644 --- a/exercises/08_futures/05_blocking/src/lib.rs +++ b/exercises/08_futures/05_blocking/src/lib.rs @@ -9,8 +9,9 @@ pub async fn echo(listener: TcpListener) -> Result<(), anyhow::Error> { loop { let (socket, _) = listener.accept().await?; let mut socket = socket.into_std()?; + socket.set_nonblocking(false)?; let mut buffer = Vec::new(); - while let Ok(_) = socket.read(&mut buffer) {} + socket.read_to_end(&mut buffer)?; socket.write_all(&buffer)?; } }