From 617e40a7e9bd8daaa792a9e7fb360529997ae9eb Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 19 Nov 2019 11:06:55 +0600 Subject: [PATCH] fix framed_read --- actix-codec/src/framed_read.rs | 13 +++++++------ actix-testing/src/rt.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/actix-codec/src/framed_read.rs b/actix-codec/src/framed_read.rs index e4dc206e..5d8d5ee8 100644 --- a/actix-codec/src/framed_read.rs +++ b/actix-codec/src/framed_read.rs @@ -231,15 +231,16 @@ where // got room for at least one byte to read to ensure that we don't // get a spurious 0 that looks like EOF this.buffer.reserve(1); - unsafe { - match Pin::new_unchecked(&mut this.inner).poll_read(cx, &mut this.buffer) { + let cnt = unsafe { + match Pin::new_unchecked(&mut this.inner).poll_read_buf(cx, &mut this.buffer) { Poll::Pending => return Poll::Pending, Poll::Ready(Err(e)) => return Poll::Ready(Some(Err(e.into()))), - Poll::Ready(Ok(0)) => { - this.eof = true; - } - Poll::Ready(Ok(_cnt)) => {} + Poll::Ready(Ok(cnt)) => cnt, } + }; + + if cnt == 0 { + this.eof = true; } this.is_readable = true; } diff --git a/actix-testing/src/rt.rs b/actix-testing/src/rt.rs index 8a135a66..163a8c34 100644 --- a/actix-testing/src/rt.rs +++ b/actix-testing/src/rt.rs @@ -54,12 +54,16 @@ where /// /// Note that this function is intended to be used only for testing purpose. /// This function panics on nested call. -pub fn block_fn(f: F) -> F::Output +pub fn block_fn(f: F) -> R::Output where F: FnOnce() -> R, 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.