From be35be8d381449149040938f24c124861da9860e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 15 Apr 2020 09:16:25 +0800 Subject: [PATCH] Revert "Revert "libasync: don't let TcpStream::read() call back for empty buffers"" Zero-length buffer is really a special case, as one must return Poll::Pending in this case. This reverts commit 1ac10ba0d4bb625c67fd897c22462608a4c24fba. --- libasync/src/smoltcp/tcp_stream.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libasync/src/smoltcp/tcp_stream.rs b/libasync/src/smoltcp/tcp_stream.rs index 4fed9ef..7fa176f 100644 --- a/libasync/src/smoltcp/tcp_stream.rs +++ b/libasync/src/smoltcp/tcp_stream.rs @@ -141,12 +141,18 @@ impl TcpStream { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let result = self.stream.with_socket(|mut socket| { - socket.recv(|buf| match (self.f)(buf) { - Poll::Ready((amount, result)) => - (amount, Poll::Ready(Ok(result))), - Poll::Pending => - // 0 bytes consumed - (0, Poll::Pending), + socket.recv(|buf| { + if buf.len() > 0 { + match (self.f)(buf) { + Poll::Ready((amount, result)) => + (amount, Poll::Ready(Ok(result))), + Poll::Pending => + // 0 bytes consumed + (0, Poll::Pending), + } + } else { + (0, Poll::Pending) + } }) }); match result {