Merge pull request #1883 from JuliDi/net-socket-bind-error

embassy-net: Improve error when socket is not bound
This commit is contained in:
Dario Nieuwenhuis 2023-09-10 20:33:29 +00:00 committed by GitHub
commit ceca8b4336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,8 @@ pub enum BindError {
pub enum Error { pub enum Error {
/// No route to host. /// No route to host.
NoRoute, NoRoute,
/// Socket not bound to an outgoing port.
SocketNotBound,
} }
/// An UDP socket. /// An UDP socket.
@ -155,7 +157,14 @@ impl<'a> UdpSocket<'a> {
s.register_send_waker(cx.waker()); s.register_send_waker(cx.waker());
Poll::Pending Poll::Pending
} }
Err(udp::SendError::Unaddressable) => Poll::Ready(Err(Error::NoRoute)), Err(udp::SendError::Unaddressable) => {
// If no sender/outgoing port is specified, there is not really "no route"
if s.endpoint().port == 0 {
Poll::Ready(Err(Error::SocketNotBound))
} else {
Poll::Ready(Err(Error::NoRoute))
}
}
}) })
} }