From 29fec1466eb185e7e2dcff8418e0126b2a7d0d0c Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Tue, 24 May 2022 12:48:29 +0100 Subject: [PATCH] http input reading correction --- examples/tls/http.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/tls/http.rs b/examples/tls/http.rs index 3eb1294..d785d25 100644 --- a/examples/tls/http.rs +++ b/examples/tls/http.rs @@ -7,11 +7,15 @@ pub(super) fn handler(mut stream: UnixStream) -> i32 { println!("entered http handler"); let mut buf = Vec::new(); - loop { - let buf_len = buf.len(); - buf.resize_with(buf_len + 1024, Default::default); + let mut buf_len = 0; - if stream.read(&mut buf[buf_len..]).unwrap() == 0 { + loop { + buf.resize_with(buf_len + 4096, Default::default); + + let read_bytes = stream.read(&mut buf[buf_len..]).unwrap(); + buf_len += read_bytes; + + if read_bytes == 0 { break; }