From ec15cf2814116fa0dee1c0712fc754820e2bfb42 Mon Sep 17 00:00:00 2001 From: Mathieu Amiot Date: Tue, 10 Jul 2018 13:49:39 +0200 Subject: [PATCH] Fixed empty buffer being sent while there's still some inside Could occur if bytes.len() was strictly double the size of buf.len() --- src/server/h2.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/server/h2.rs b/src/server/h2.rs index d812f6f53..4c1c8a640 100644 --- a/src/server/h2.rs +++ b/src/server/h2.rs @@ -405,9 +405,8 @@ impl Read for IoWrapper { fn read(&mut self, buf: &mut [u8]) -> io::Result { if let Some(mut bytes) = self.unread.take() { let size = cmp::min(buf.len(), bytes.len()); - buf[..size].copy_from_slice(&bytes[..size]); - if bytes.len() > size { - bytes.split_to(size); + buf[..size].copy_from_slice(&bytes.split_to(size)); + if bytes.len() > 0 { self.unread = Some(bytes); } Ok(size)