From 4a59fbdedc63999add80d6f9c2404dbfe2566e74 Mon Sep 17 00:00:00 2001 From: swanandx <73115739+swanandx@users.noreply.github.com> Date: Wed, 3 Jan 2024 18:17:04 +0530 Subject: [PATCH] feat: impl ReadReady and WriteReady for tcp --- embassy-net/src/tcp.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index dcfb5c96e..72b0677b4 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -547,6 +547,12 @@ mod embedded_io_impls { } } + impl<'d> embedded_io_async::ReadReady for TcpSocket<'d> { + fn read_ready(&mut self) -> Result { + Ok(self.io.with(|s, _| s.may_recv())) + } + } + impl<'d> embedded_io_async::Write for TcpSocket<'d> { async fn write(&mut self, buf: &[u8]) -> Result { self.io.write(buf).await @@ -557,6 +563,12 @@ mod embedded_io_impls { } } + impl<'d> embedded_io_async::WriteReady for TcpSocket<'d> { + fn write_ready(&mut self) -> Result { + Ok(self.io.with(|s, _| s.may_send())) + } + } + impl<'d> embedded_io_async::ErrorType for TcpReader<'d> { type Error = Error; } @@ -567,6 +579,12 @@ mod embedded_io_impls { } } + impl<'d> embedded_io_async::ReadReady for TcpReader<'d> { + fn read_ready(&mut self) -> Result { + Ok(self.io.with(|s, _| s.may_recv())) + } + } + impl<'d> embedded_io_async::ErrorType for TcpWriter<'d> { type Error = Error; } @@ -580,6 +598,12 @@ mod embedded_io_impls { self.io.flush().await } } + + impl<'d> embedded_io_async::WriteReady for TcpWriter<'d> { + fn write_ready(&mut self) -> Result { + Ok(self.io.with(|s, _| s.may_send())) + } + } } /// TCP client compatible with `embedded-nal-async` traits.