diff options
| author | JuliDi <[email protected]> | 2023-09-08 15:58:47 +0200 |
|---|---|---|
| committer | JuliDi <[email protected]> | 2023-09-08 15:58:47 +0200 |
| commit | a4f8d82ef51b7c0c775168472829ecd18d8f84d8 (patch) | |
| tree | e9e586615aa7626225b436539b93630ff21f5403 /embassy-net/src | |
| parent | 26740bb3ef01b4965d3be92622f0f4220b6cb931 (diff) | |
wait_config_up first steps
Diffstat (limited to 'embassy-net/src')
| -rw-r--r-- | embassy-net/src/lib.rs | 26 |
1 files changed, 26 insertions, 0 deletions
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<D: Driver> { | |||
| 226 | static_v6: Option<StaticConfigV6>, | 226 | static_v6: Option<StaticConfigV6>, |
| 227 | #[cfg(feature = "dhcpv4")] | 227 | #[cfg(feature = "dhcpv4")] |
| 228 | dhcp_socket: Option<SocketHandle>, | 228 | dhcp_socket: Option<SocketHandle>, |
| 229 | config_waker: WakerRegistration, | ||
| 229 | #[cfg(feature = "dns")] | 230 | #[cfg(feature = "dns")] |
| 230 | dns_socket: SocketHandle, | 231 | dns_socket: SocketHandle, |
| 231 | #[cfg(feature = "dns")] | 232 | #[cfg(feature = "dns")] |
| @@ -297,6 +298,7 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 297 | static_v6: None, | 298 | static_v6: None, |
| 298 | #[cfg(feature = "dhcpv4")] | 299 | #[cfg(feature = "dhcpv4")] |
| 299 | dhcp_socket: None, | 300 | dhcp_socket: None, |
| 301 | config_waker: WakerRegistration::new(), | ||
| 300 | #[cfg(feature = "dns")] | 302 | #[cfg(feature = "dns")] |
| 301 | dns_socket: socket.sockets.add(dns::Socket::new( | 303 | dns_socket: socket.sockets.add(dns::Socket::new( |
| 302 | &[], | 304 | &[], |
| @@ -363,6 +365,28 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 363 | v4_up || v6_up | 365 | v4_up || v6_up |
| 364 | } | 366 | } |
| 365 | 367 | ||
| 368 | /// Get for the network stack to obtainer a valid IP configuration. | ||
| 369 | pub async fn wait_config_up(&self) { | ||
| 370 | if self.is_config_up() { | ||
| 371 | return; | ||
| 372 | } | ||
| 373 | |||
| 374 | poll_fn(|cx| { | ||
| 375 | self.with_mut(|_, i| { | ||
| 376 | debug!("poll_fn called"); | ||
| 377 | if self.is_config_up() { | ||
| 378 | debug!("poll_fn ready"); | ||
| 379 | Poll::Ready(()) | ||
| 380 | } else { | ||
| 381 | debug!("poll_fn pending"); | ||
| 382 | i.config_waker.register(cx.waker()); | ||
| 383 | Poll::Pending | ||
| 384 | } | ||
| 385 | }) | ||
| 386 | }) | ||
| 387 | .await; | ||
| 388 | } | ||
| 389 | |||
| 366 | /// Get the current IPv4 configuration. | 390 | /// Get the current IPv4 configuration. |
| 367 | /// | 391 | /// |
| 368 | /// If using DHCP, this will be None if DHCP hasn't been able to | 392 | /// If using DHCP, this will be None if DHCP hasn't been able to |
| @@ -706,6 +730,8 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 706 | s.sockets | 730 | s.sockets |
| 707 | .get_mut::<smoltcp::socket::dns::Socket>(self.dns_socket) | 731 | .get_mut::<smoltcp::socket::dns::Socket>(self.dns_socket) |
| 708 | .update_servers(&dns_servers[..]); | 732 | .update_servers(&dns_servers[..]); |
| 733 | |||
| 734 | s.waker.wake(); | ||
| 709 | } | 735 | } |
| 710 | 736 | ||
| 711 | fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) { | 737 | fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) { |
