aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Grondin <[email protected]>2024-10-31 16:20:01 -0400
committerAnthony Grondin <[email protected]>2024-10-31 22:25:48 -0400
commit70214fc2c23aded1f5a1b8a62425ac3aa581102f (patch)
tree47689630fc492662c92c909e9ec987e7f005ae47
parentf319f1bc1b36cd6c7860391e49083ee64c079547 (diff)
feat(embassy-net): Implement `TcpReader::wait_read_ready()` + `TcpWriter::wait_send_ready()`
-rw-r--r--embassy-net/src/tcp.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index a00ced8f4..150b4b36b 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -73,6 +73,16 @@ pub struct TcpWriter<'a> {
73} 73}
74 74
75impl<'a> TcpReader<'a> { 75impl<'a> TcpReader<'a> {
76 /// Wait until the socket becomes readable.
77 ///
78 /// A socket becomes readable when the receive half of the full-duplex connection is open
79 /// (see [`may_recv()`](TcpSocket::may_recv)), and there is some pending data in the receive buffer.
80 ///
81 /// This is the equivalent of [read](#method.read), without buffering any data.
82 pub async fn wait_read_ready(&self) {
83 poll_fn(move |cx| self.io.poll_read_ready(cx)).await
84 }
85
76 /// Read data from the socket. 86 /// Read data from the socket.
77 /// 87 ///
78 /// Returns how many bytes were read, or an error. If no data is available, it waits 88 /// Returns how many bytes were read, or an error. If no data is available, it waits
@@ -115,6 +125,16 @@ impl<'a> TcpReader<'a> {
115} 125}
116 126
117impl<'a> TcpWriter<'a> { 127impl<'a> TcpWriter<'a> {
128 /// Wait until the socket becomes writable.
129 ///
130 /// A socket becomes writable when the transmit half of the full-duplex connection is open
131 /// (see [`may_send()`](TcpSocket::may_send)), and the transmit buffer is not full.
132 ///
133 /// This is the equivalent of [write](#method.write), without sending any data.
134 pub async fn wait_write_ready(&self) {
135 poll_fn(move |cx| self.io.poll_write_ready(cx)).await
136 }
137
118 /// Write data to the socket. 138 /// Write data to the socket.
119 /// 139 ///
120 /// Returns how many bytes were written, or an error. If the socket is not ready to 140 /// Returns how many bytes were written, or an error. If the socket is not ready to