aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorswanandx <[email protected]>2024-01-03 18:17:04 +0530
committerswanandx <[email protected]>2024-01-03 18:17:04 +0530
commit4a59fbdedc63999add80d6f9c2404dbfe2566e74 (patch)
tree199656817d9c5fd4c52fea6fc45bc2212f27fda2
parentffdc1807ca3876edee63af0464f3dcf223779e61 (diff)
feat: impl ReadReady and WriteReady for tcp
-rw-r--r--embassy-net/src/tcp.rs24
1 files changed, 24 insertions, 0 deletions
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 {
547 } 547 }
548 } 548 }
549 549
550 impl<'d> embedded_io_async::ReadReady for TcpSocket<'d> {
551 fn read_ready(&mut self) -> Result<bool, Self::Error> {
552 Ok(self.io.with(|s, _| s.may_recv()))
553 }
554 }
555
550 impl<'d> embedded_io_async::Write for TcpSocket<'d> { 556 impl<'d> embedded_io_async::Write for TcpSocket<'d> {
551 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { 557 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
552 self.io.write(buf).await 558 self.io.write(buf).await
@@ -557,6 +563,12 @@ mod embedded_io_impls {
557 } 563 }
558 } 564 }
559 565
566 impl<'d> embedded_io_async::WriteReady for TcpSocket<'d> {
567 fn write_ready(&mut self) -> Result<bool, Self::Error> {
568 Ok(self.io.with(|s, _| s.may_send()))
569 }
570 }
571
560 impl<'d> embedded_io_async::ErrorType for TcpReader<'d> { 572 impl<'d> embedded_io_async::ErrorType for TcpReader<'d> {
561 type Error = Error; 573 type Error = Error;
562 } 574 }
@@ -567,6 +579,12 @@ mod embedded_io_impls {
567 } 579 }
568 } 580 }
569 581
582 impl<'d> embedded_io_async::ReadReady for TcpReader<'d> {
583 fn read_ready(&mut self) -> Result<bool, Self::Error> {
584 Ok(self.io.with(|s, _| s.may_recv()))
585 }
586 }
587
570 impl<'d> embedded_io_async::ErrorType for TcpWriter<'d> { 588 impl<'d> embedded_io_async::ErrorType for TcpWriter<'d> {
571 type Error = Error; 589 type Error = Error;
572 } 590 }
@@ -580,6 +598,12 @@ mod embedded_io_impls {
580 self.io.flush().await 598 self.io.flush().await
581 } 599 }
582 } 600 }
601
602 impl<'d> embedded_io_async::WriteReady for TcpWriter<'d> {
603 fn write_ready(&mut self) -> Result<bool, Self::Error> {
604 Ok(self.io.with(|s, _| s.may_send()))
605 }
606 }
583} 607}
584 608
585/// TCP client compatible with `embedded-nal-async` traits. 609/// TCP client compatible with `embedded-nal-async` traits.