feat: impl ReadReady and WriteReady for tcp

This commit is contained in:
swanandx 2024-01-03 18:17:04 +05:30
parent ffdc1807ca
commit 4a59fbdedc

View File

@ -547,6 +547,12 @@ mod embedded_io_impls {
}
}
impl<'d> embedded_io_async::ReadReady for TcpSocket<'d> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
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<usize, Self::Error> {
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<bool, Self::Error> {
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<bool, Self::Error> {
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<bool, Self::Error> {
Ok(self.io.with(|s, _| s.may_send()))
}
}
}
/// TCP client compatible with `embedded-nal-async` traits.