diff options
| author | Dániel Buga <[email protected]> | 2023-11-06 08:52:11 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2023-11-06 09:12:16 +0100 |
| commit | 15660cfc68f88b18f4e2fa7a2d776da4ec8b422a (patch) | |
| tree | d395b84ae27ad65caf51382008dec3bd5306cbf2 /embassy-net/src | |
| parent | 74f70dc7b4db7ea9e10800384602bed48efe96b2 (diff) | |
Ensure TcpIo not blocking when reading into empty slice
Diffstat (limited to 'embassy-net/src')
| -rw-r--r-- | embassy-net/src/tcp.rs | 7 |
1 files changed, 7 insertions, 0 deletions
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> { | |||
| 390 | // CAUTION: smoltcp semantics around EOF are different to what you'd expect | 390 | // CAUTION: smoltcp semantics around EOF are different to what you'd expect |
| 391 | // from posix-like IO, so we have to tweak things here. | 391 | // from posix-like IO, so we have to tweak things here. |
| 392 | self.with_mut(|s, _| match s.recv_slice(buf) { | 392 | self.with_mut(|s, _| match s.recv_slice(buf) { |
| 393 | // Reading into empty buffer | ||
| 394 | Ok(0) if buf.is_empty() => { | ||
| 395 | // embedded_io_async::Read's contract is to not block if buf is empty. While | ||
| 396 | // this function is not a direct implementor of the trait method, we still don't | ||
| 397 | // want our future to never resolve. | ||
| 398 | Poll::Ready(Ok(0)) | ||
| 399 | } | ||
| 393 | // No data ready | 400 | // No data ready |
| 394 | Ok(0) => { | 401 | Ok(0) => { |
| 395 | s.register_recv_waker(cx.waker()); | 402 | s.register_recv_waker(cx.waker()); |
