aboutsummaryrefslogtreecommitdiff
path: root/embassy-net/src/udp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-net/src/udp.rs')
-rw-r--r--embassy-net/src/udp.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
index 76602edc2..64a22d45b 100644
--- a/embassy-net/src/udp.rs
+++ b/embassy-net/src/udp.rs
@@ -1,6 +1,6 @@
1//! UDP sockets. 1//! UDP sockets.
2 2
3use core::future::poll_fn; 3use core::future::{poll_fn, Future};
4use core::mem; 4use core::mem;
5use core::task::{Context, Poll}; 5use core::task::{Context, Poll};
6 6
@@ -107,8 +107,8 @@ impl<'a> UdpSocket<'a> {
107 /// 107 ///
108 /// A socket is readable when a packet has been received, or when there are queued packets in 108 /// A socket is readable when a packet has been received, or when there are queued packets in
109 /// the buffer. 109 /// the buffer.
110 pub async fn wait_recv_ready(&self) { 110 pub fn wait_recv_ready(&self) -> impl Future<Output = ()> + '_ {
111 poll_fn(move |cx| self.poll_recv_ready(cx)).await 111 poll_fn(move |cx| self.poll_recv_ready(cx))
112 } 112 }
113 113
114 /// Wait until a datagram can be read. 114 /// Wait until a datagram can be read.
@@ -134,8 +134,11 @@ impl<'a> UdpSocket<'a> {
134 /// This method will wait until a datagram is received. 134 /// This method will wait until a datagram is received.
135 /// 135 ///
136 /// Returns the number of bytes received and the remote endpoint. 136 /// Returns the number of bytes received and the remote endpoint.
137 pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, UdpMetadata), RecvError> { 137 pub fn recv_from<'s>(
138 poll_fn(move |cx| self.poll_recv_from(buf, cx)).await 138 &'s self,
139 buf: &'s mut [u8],
140 ) -> impl Future<Output = Result<(usize, UdpMetadata), RecvError>> + 's {
141 poll_fn(|cx| self.poll_recv_from(buf, cx))
139 } 142 }
140 143
141 /// Receive a datagram. 144 /// Receive a datagram.
@@ -194,8 +197,8 @@ impl<'a> UdpSocket<'a> {
194 /// 197 ///
195 /// A socket becomes writable when there is space in the buffer, from initial memory or after 198 /// A socket becomes writable when there is space in the buffer, from initial memory or after
196 /// dispatching datagrams on a full buffer. 199 /// dispatching datagrams on a full buffer.
197 pub async fn wait_send_ready(&self) { 200 pub fn wait_send_ready(&self) -> impl Future<Output = ()> + '_ {
198 poll_fn(move |cx| self.poll_send_ready(cx)).await 201 poll_fn(|cx| self.poll_send_ready(cx))
199 } 202 }
200 203
201 /// Wait until a datagram can be sent. 204 /// Wait until a datagram can be sent.
@@ -297,8 +300,8 @@ impl<'a> UdpSocket<'a> {
297 /// Flush the socket. 300 /// Flush the socket.
298 /// 301 ///
299 /// This method will wait until the socket is flushed. 302 /// This method will wait until the socket is flushed.
300 pub async fn flush(&mut self) { 303 pub fn flush(&mut self) -> impl Future<Output = ()> + '_ {
301 poll_fn(move |cx| { 304 poll_fn(|cx| {
302 self.with_mut(|s, _| { 305 self.with_mut(|s, _| {
303 if s.send_queue() == 0 { 306 if s.send_queue() == 0 {
304 Poll::Ready(()) 307 Poll::Ready(())
@@ -308,7 +311,6 @@ impl<'a> UdpSocket<'a> {
308 } 311 }
309 }) 312 })
310 }) 313 })
311 .await
312 } 314 }
313 315
314 /// Returns the local endpoint of the socket. 316 /// Returns the local endpoint of the socket.