From df160d90ae969fa56b189e0c0d95aabf641b41f1 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Mon, 30 May 2022 21:07:30 +0200 Subject: [PATCH] Make sure all data is written to socket Using `write` means that it's possible that not all data gets written out. Rather than check the return value and write in a loop, just use `write_all`. --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6938088..4d791fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ fn read_body(length: u32, socket: &mut ProxySocket) { if let Ok(_) = handle.read_exact(&mut buffer) { if valid_length(length) { - socket.write(&buffer).unwrap(); + socket.write_all(&buffer).unwrap(); socket.flush().unwrap(); read_response(socket); } @@ -52,7 +52,7 @@ fn write_response(buf: &[u8]) { let mut out = stdout.lock(); out.write_u32::(buf.len() as u32).unwrap(); - out.write(buf).unwrap(); + out.write_all(buf).unwrap(); out.flush().unwrap(); }