1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-02-20 06:30:32 +01:00

fix framed_read

This commit is contained in:
Nikolay Kim 2019-11-19 11:06:55 +06:00
parent 3105cde168
commit 617e40a7e9
2 changed files with 13 additions and 8 deletions

View File

@ -231,15 +231,16 @@ where
// got room for at least one byte to read to ensure that we don't // got room for at least one byte to read to ensure that we don't
// get a spurious 0 that looks like EOF // get a spurious 0 that looks like EOF
this.buffer.reserve(1); this.buffer.reserve(1);
unsafe { let cnt = unsafe {
match Pin::new_unchecked(&mut this.inner).poll_read(cx, &mut this.buffer) { match Pin::new_unchecked(&mut this.inner).poll_read_buf(cx, &mut this.buffer) {
Poll::Pending => return Poll::Pending, Poll::Pending => return Poll::Pending,
Poll::Ready(Err(e)) => return Poll::Ready(Some(Err(e.into()))), Poll::Ready(Err(e)) => return Poll::Ready(Some(Err(e.into()))),
Poll::Ready(Ok(0)) => { Poll::Ready(Ok(cnt)) => cnt,
this.eof = true;
}
Poll::Ready(Ok(_cnt)) => {}
} }
};
if cnt == 0 {
this.eof = true;
} }
this.is_readable = true; this.is_readable = true;
} }

View File

@ -54,12 +54,16 @@ where
/// ///
/// Note that this function is intended to be used only for testing purpose. /// Note that this function is intended to be used only for testing purpose.
/// This function panics on nested call. /// This function panics on nested call.
pub fn block_fn<F, R>(f: F) -> F::Output pub fn block_fn<F, R>(f: F) -> R::Output
where where
F: FnOnce() -> R, F: FnOnce() -> R,
R: Future, R: Future,
{ {
RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(|_| f()))) RT.with(move |rt| {
let mut rt = rt.borrow_mut();
let fut = rt.get_mut().block_on(lazy(|_| f()));
rt.get_mut().block_on(fut)
})
} }
/// Spawn future to the current test runtime. /// Spawn future to the current test runtime.