mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
Revert "remove unnecessary use of unsafe in read_from_io"
This reverts commit da237611cb
.
This commit is contained in:
parent
3afdf3fa7e
commit
17c033030b
@ -1,5 +1,5 @@
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use futures::Poll;
|
||||
use futures::{Async, Poll};
|
||||
use std::io;
|
||||
|
||||
use super::IoStream;
|
||||
@ -10,8 +10,22 @@ const HW_BUFFER_SIZE: usize = 32_768;
|
||||
pub fn read_from_io<T: IoStream>(
|
||||
io: &mut T, buf: &mut BytesMut,
|
||||
) -> Poll<usize, io::Error> {
|
||||
if buf.remaining_mut() < LW_BUFFER_SIZE {
|
||||
buf.reserve(HW_BUFFER_SIZE);
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
io.read_buf(buf)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user