From a4f8d82ef51b7c0c775168472829ecd18d8f84d8 Mon Sep 17 00:00:00 2001 From: JuliDi <20155974+JuliDi@users.noreply.github.com> Date: Fri, 8 Sep 2023 15:58:47 +0200 Subject: [PATCH] wait_config_up first steps --- embassy-net/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index c2575267c..8289ecddf 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -226,6 +226,7 @@ struct Inner { static_v6: Option, #[cfg(feature = "dhcpv4")] dhcp_socket: Option, + config_waker: WakerRegistration, #[cfg(feature = "dns")] dns_socket: SocketHandle, #[cfg(feature = "dns")] @@ -297,6 +298,7 @@ impl Stack { static_v6: None, #[cfg(feature = "dhcpv4")] dhcp_socket: None, + config_waker: WakerRegistration::new(), #[cfg(feature = "dns")] dns_socket: socket.sockets.add(dns::Socket::new( &[], @@ -363,6 +365,28 @@ impl Stack { v4_up || v6_up } + /// Get for the network stack to obtainer a valid IP configuration. + pub async fn wait_config_up(&self) { + if self.is_config_up() { + return; + } + + poll_fn(|cx| { + self.with_mut(|_, i| { + debug!("poll_fn called"); + if self.is_config_up() { + debug!("poll_fn ready"); + Poll::Ready(()) + } else { + debug!("poll_fn pending"); + i.config_waker.register(cx.waker()); + Poll::Pending + } + }) + }) + .await; + } + /// Get the current IPv4 configuration. /// /// If using DHCP, this will be None if DHCP hasn't been able to @@ -706,6 +730,8 @@ impl Inner { s.sockets .get_mut::(self.dns_socket) .update_servers(&dns_servers[..]); + + s.waker.wake(); } fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {