diff options
| author | chrysn <[email protected]> | 2024-02-02 15:16:54 +0100 |
|---|---|---|
| committer | chrysn <[email protected]> | 2024-04-08 11:59:21 +0200 |
| commit | 7f1bedcee037839c77312d5ce667f2c199b473be (patch) | |
| tree | 5ab205d176b1a5ee353542e24672e27fa49e4968 | |
| parent | 029636e6fc06b484898c5935957b33b60a9c88b2 (diff) | |
net/udp: Relay full UdpMetadata instead of only remote endpoint in poll_ functions
This is a breaking change for users of the poll_ functions. (Some might
not notice if they already pass in an IpEndpoint into poll_send_to, or
discard that item in poll_recv_from).
| -rw-r--r-- | embassy-net/src/udp.rs | 16 |
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}; | |||
| 8 | use embassy_net_driver::Driver; | 8 | use embassy_net_driver::Driver; |
| 9 | use smoltcp::iface::{Interface, SocketHandle}; | 9 | use smoltcp::iface::{Interface, SocketHandle}; |
| 10 | use smoltcp::socket::udp; | 10 | use smoltcp::socket::udp; |
| 11 | pub use smoltcp::socket::udp::PacketMetadata; | 11 | pub use smoltcp::socket::udp::{PacketMetadata, UdpMetadata}; |
| 12 | use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; | 12 | use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; |
| 13 | 13 | ||
| 14 | use crate::{SocketStack, Stack}; | 14 | use 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 |
