1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-23 16:40:37 +00:00

Fixed empty buffer being sent while there's still some inside

Could occur if bytes.len() was strictly double the size of buf.len()
This commit is contained in:
Mathieu Amiot 2018-07-10 13:49:39 +02:00
parent 82920e1ac1
commit ec15cf2814

View file

@ -405,9 +405,8 @@ impl<T: Read> Read for IoWrapper<T> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if let Some(mut bytes) = self.unread.take() { if let Some(mut bytes) = self.unread.take() {
let size = cmp::min(buf.len(), bytes.len()); let size = cmp::min(buf.len(), bytes.len());
buf[..size].copy_from_slice(&bytes[..size]); buf[..size].copy_from_slice(&bytes.split_to(size));
if bytes.len() > size { if bytes.len() > 0 {
bytes.split_to(size);
self.unread = Some(bytes); self.unread = Some(bytes);
} }
Ok(size) Ok(size)