From da237611cb429da5fb42ab9d6be52837d1de3dda Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Jun 2018 13:14:53 +0200 Subject: [PATCH] remove unnecessary use of unsafe in read_from_io --- src/server/utils.rs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/server/utils.rs b/src/server/utils.rs index e0e7e7f62..b0470d76b 100644 --- a/src/server/utils.rs +++ b/src/server/utils.rs @@ -1,5 +1,5 @@ use bytes::{BufMut, BytesMut}; -use futures::{Async, Poll}; +use futures::Poll; use std::io; use super::IoStream; @@ -10,22 +10,8 @@ const HW_BUFFER_SIZE: usize = 32_768; pub fn read_from_io( io: &mut T, buf: &mut BytesMut, ) -> Poll { - unsafe { - if buf.remaining_mut() < LW_BUFFER_SIZE { - buf.reserve(HW_BUFFER_SIZE); - } - match io.read(buf.bytes_mut()) { - Ok(n) => { - buf.advance_mut(n); - Ok(Async::Ready(n)) - } - Err(e) => { - if e.kind() == io::ErrorKind::WouldBlock { - Ok(Async::NotReady) - } else { - Err(e) - } - } - } + if buf.remaining_mut() < LW_BUFFER_SIZE { + buf.reserve(HW_BUFFER_SIZE); } + io.read_buf(buf) }