From 15660cfc68f88b18f4e2fa7a2d776da4ec8b422a Mon Sep 17 00:00:00 2001 From: Dániel Buga Date: Mon, 6 Nov 2023 08:52:11 +0100 Subject: Ensure TcpIo not blocking when reading into empty slice --- embassy-net/src/tcp.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'embassy-net/src') diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index b5615cb66..bcd5bb618 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -390,6 +390,13 @@ impl<'d> TcpIo<'d> { // CAUTION: smoltcp semantics around EOF are different to what you'd expect // from posix-like IO, so we have to tweak things here. self.with_mut(|s, _| match s.recv_slice(buf) { + // Reading into empty buffer + Ok(0) if buf.is_empty() => { + // embedded_io_async::Read's contract is to not block if buf is empty. While + // this function is not a direct implementor of the trait method, we still don't + // want our future to never resolve. + Poll::Ready(Ok(0)) + } // No data ready Ok(0) => { s.register_recv_waker(cx.waker()); -- cgit