From cf490ed34618782cef591a41438a62e1437d7d5c Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 7 Jul 2025 12:32:29 +1000 Subject: [PATCH] extmod/network_lwip: Add sys_untimeout_all_with_arg helper function. Really lwIP should provide this, to deregister all callbacks on the given netif. Signed-off-by: Damien George --- extmod/lwip-include/lwipopts_common.h | 3 +++ extmod/modnetwork.h | 3 +++ extmod/network_lwip.c | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/extmod/lwip-include/lwipopts_common.h b/extmod/lwip-include/lwipopts_common.h index 3e42309094..8cb1acfe2c 100644 --- a/extmod/lwip-include/lwipopts_common.h +++ b/extmod/lwip-include/lwipopts_common.h @@ -28,6 +28,9 @@ #include "py/mpconfig.h" +// This is needed to access `next_timeout` via `sys_timeouts_get_next_timeout()`. +#define LWIP_TESTMODE 1 + // This sys-arch protection is not needed. // Ports either protect lwIP code with flags, or run it at PendSV priority. #define SYS_ARCH_DECL_PROTECT(lev) do { } while (0) diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index d16329f07d..754f6e1243 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -82,6 +82,9 @@ extern const struct _mp_obj_type_t mp_network_ppp_lwip_type; #endif struct netif; + +void sys_untimeout_all_with_arg(void *arg); + void mod_network_lwip_init(void); void mod_network_lwip_poll_wrapper(uint32_t ticks_ms); mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args); diff --git a/extmod/network_lwip.c b/extmod/network_lwip.c index 71dc295e18..9cfab6ef4c 100644 --- a/extmod/network_lwip.c +++ b/extmod/network_lwip.c @@ -52,6 +52,19 @@ int mp_mod_network_prefer_dns_use_ip_version = 4; // Implementations of network methods that can be used by any interface. +// This follows sys_untimeout but removes all timeouts with the given argument. +void sys_untimeout_all_with_arg(void *arg) { + for (struct sys_timeo **t = sys_timeouts_get_next_timeout(); *t != NULL;) { + if ((*t)->arg == arg) { + struct sys_timeo *next = (*t)->next; + memp_free(MEMP_SYS_TIMEOUT, *t); + *t = next; + } else { + t = &(*t)->next; + } + } +} + // This function provides the implementation of nic.ifconfig, is deprecated and will be removed. // Use network.ipconfig and nic.ipconfig instead. mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args) {