From e3a6a6e1f80ec27f5f96a0333ada9f71f55ac987 Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 14 Apr 2020 01:05:40 +0200 Subject: [PATCH] libasync: don't let TcpStream::read() call back for empty buffers --- 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 {