Merge pull request #2394 from swanandx/ready-impl-tcp

impl ReadReady and WriteReady for tcp
This commit is contained in:
Ulf Lilleengen 2024-01-03 13:10:02 +00:00 committed by GitHub
commit 3b6eaf414a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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.