Merge pull request #251 from embassy-rs/net-fix

net/tcp: Fix panic when consuming 0 bytes at EOF
This commit is contained in:
Dario Nieuwenhuis 2021-06-18 02:06:41 +02:00 committed by GitHub
commit 06d69a8028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,6 +151,11 @@ impl<'a> AsyncBufRead for TcpSocket<'a> {
}
fn consume(self: Pin<&mut Self>, amt: usize) {
if amt == 0 {
// smoltcp's recv returns Finished if we're at EOF,
// even if we're "reading" 0 bytes.
return;
}
self.with(|s| s.recv(|_| (amt, ()))).unwrap()
}
}