aboutsummaryrefslogtreecommitdiff
path: root/embassy-net/src
diff options
context:
space:
mode:
authorFan Jiang <[email protected]>2024-10-20 12:29:38 -0400
committerDario Nieuwenhuis <[email protected]>2024-10-21 01:59:31 +0200
commitb4ee17fb4f1a77c26fc08e9fe9e0d343d1c059b4 (patch)
tree885de668949d20ea7f2d5471103f154108b4a223 /embassy-net/src
parentc9358e1f1e5d88aa0ad998c44eb2da6be73cf477 (diff)
net: Add flush for UDP and Raw sockets.
Diffstat (limited to 'embassy-net/src')
-rw-r--r--embassy-net/src/raw.rs17
-rw-r--r--embassy-net/src/udp.rs17
2 files changed, 34 insertions, 0 deletions
diff --git a/embassy-net/src/raw.rs b/embassy-net/src/raw.rs
index 1098dc208..ace325a46 100644
--- a/embassy-net/src/raw.rs
+++ b/embassy-net/src/raw.rs
@@ -108,6 +108,23 @@ impl<'a> RawSocket<'a> {
108 } 108 }
109 }) 109 })
110 } 110 }
111
112 /// Flush the socket.
113 ///
114 /// This method will wait until the socket is flushed.
115 pub async fn flush(&mut self) {
116 poll_fn(move |cx| {
117 self.with_mut(|s, _| {
118 if s.send_queue() == 0 {
119 Poll::Ready(())
120 } else {
121 s.register_send_waker(cx.waker());
122 Poll::Pending
123 }
124 })
125 })
126 .await
127 }
111} 128}
112 129
113impl Drop for RawSocket<'_> { 130impl Drop for RawSocket<'_> {
diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
index 3eb6e2f83..ac650364e 100644
--- a/embassy-net/src/udp.rs
+++ b/embassy-net/src/udp.rs
@@ -241,6 +241,23 @@ impl<'a> UdpSocket<'a> {
241 .await 241 .await
242 } 242 }
243 243
244 /// Flush the socket.
245 ///
246 /// This method will wait until the socket is flushed.
247 pub async fn flush(&mut self) {
248 poll_fn(move |cx| {
249 self.with_mut(|s, _| {
250 if s.send_queue() == 0 {
251 Poll::Ready(())
252 } else {
253 s.register_send_waker(cx.waker());
254 Poll::Pending
255 }
256 })
257 })
258 .await
259 }
260
244 /// Returns the local endpoint of the socket. 261 /// Returns the local endpoint of the socket.
245 pub fn endpoint(&self) -> IpListenEndpoint { 262 pub fn endpoint(&self) -> IpListenEndpoint {
246 self.with(|s, _| s.endpoint()) 263 self.with(|s, _| s.endpoint())