From 58dbe88ca932b4c998d8d012e88b3b5bd575edc5 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 28 Mar 2020 21:23:05 +0100 Subject: controller/utils: Properly handle short reads on socket --- controller/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/src/lib.rs b/controller/src/lib.rs index ee02b3b..b53502f 100644 --- a/controller/src/lib.rs +++ b/controller/src/lib.rs @@ -35,7 +35,7 @@ async fn send_vectored( async fn receive_message(reader: &mut (impl AsyncReadExt + Unpin)) -> io::Result> { let mut header = [0u8; 17]; - if let Err(e) = reader.read(&mut header).await { + if let Err(e) = reader.read_exact(&mut header).await { if e.kind() == ErrorKind::UnexpectedEof { return Ok(None); } else { return Err(e); } } @@ -46,7 +46,7 @@ async fn receive_message(reader: &mut (impl AsyncReadExt + Unpin)) let mut payload = Vec::new(); payload.resize(length, 0u8); - if let Err(e) = reader.read(&mut payload).await { + if let Err(e) = reader.read_exact(&mut payload).await { if e.kind() == ErrorKind::UnexpectedEof { return Ok(None); } else { return Err(e); } } -- cgit v1.2.3-70-g09d2