aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-net/src/udp.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
index a22cd8827..2fdf83e9d 100644
--- a/embassy-net/src/udp.rs
+++ b/embassy-net/src/udp.rs
@@ -8,7 +8,7 @@ use core::task::{Context, Poll};
8use embassy_net_driver::Driver; 8use embassy_net_driver::Driver;
9use smoltcp::iface::{Interface, SocketHandle}; 9use smoltcp::iface::{Interface, SocketHandle};
10use smoltcp::socket::udp; 10use smoltcp::socket::udp;
11pub use smoltcp::socket::udp::PacketMetadata; 11pub use smoltcp::socket::udp::{PacketMetadata, UdpMetadata};
12use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; 12use smoltcp::wire::{IpEndpoint, IpListenEndpoint};
13 13
14use crate::{SocketStack, Stack}; 14use crate::{SocketStack, Stack};
@@ -112,7 +112,9 @@ impl<'a> UdpSocket<'a> {
112 /// 112 ///
113 /// Returns the number of bytes received and the remote endpoint. 113 /// Returns the number of bytes received and the remote endpoint.
114 pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), RecvError> { 114 pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), RecvError> {
115 poll_fn(move |cx| self.poll_recv_from(buf, cx)).await 115 poll_fn(move |cx| self.poll_recv_from(buf, cx))
116 .await
117 .map(|(size, metadata)| (size, metadata.endpoint))
116 } 118 }
117 119
118 /// Receive a datagram. 120 /// Receive a datagram.
@@ -122,9 +124,13 @@ impl<'a> UdpSocket<'a> {
122 /// 124 ///
123 /// When a datagram is received, this method will return `Poll::Ready` with the 125 /// When a datagram is received, this method will return `Poll::Ready` with the
124 /// number of bytes received and the remote endpoint. 126 /// number of bytes received and the remote endpoint.
125 pub fn poll_recv_from(&self, buf: &mut [u8], cx: &mut Context<'_>) -> Poll<Result<(usize, IpEndpoint), RecvError>> { 127 pub fn poll_recv_from(
128 &self,
129 buf: &mut [u8],
130 cx: &mut Context<'_>,
131 ) -> Poll<Result<(usize, UdpMetadata), RecvError>> {
126 self.with_mut(|s, _| match s.recv_slice(buf) { 132 self.with_mut(|s, _| match s.recv_slice(buf) {
127 Ok((n, meta)) => Poll::Ready(Ok((n, meta.endpoint))), 133 Ok((n, meta)) => Poll::Ready(Ok((n, meta))),
128 // No data ready 134 // No data ready
129 Err(udp::RecvError::Truncated) => Poll::Ready(Err(RecvError::Truncated)), 135 Err(udp::RecvError::Truncated) => Poll::Ready(Err(RecvError::Truncated)),
130 Err(udp::RecvError::Exhausted) => { 136 Err(udp::RecvError::Exhausted) => {
@@ -157,7 +163,7 @@ impl<'a> UdpSocket<'a> {
157 /// When the remote endpoint is not reachable, this method will return `Poll::Ready(Err(Error::NoRoute))`. 163 /// When the remote endpoint is not reachable, this method will return `Poll::Ready(Err(Error::NoRoute))`.
158 pub fn poll_send_to<T>(&self, buf: &[u8], remote_endpoint: T, cx: &mut Context<'_>) -> Poll<Result<(), SendError>> 164 pub fn poll_send_to<T>(&self, buf: &[u8], remote_endpoint: T, cx: &mut Context<'_>) -> Poll<Result<(), SendError>>
159 where 165 where
160 T: Into<IpEndpoint>, 166 T: Into<UdpMetadata>,
161 { 167 {
162 self.with_mut(|s, _| match s.send_slice(buf, remote_endpoint) { 168 self.with_mut(|s, _| match s.send_slice(buf, remote_endpoint) {
163 // Entire datagram has been sent 169 // Entire datagram has been sent