Fix repeated MDNS use on Pico W
This commit is contained in:
parent
5c517b7e5a
commit
ee2fe993dd
@ -36,21 +36,28 @@
|
||||
#include "lwip/apps/mdns.h"
|
||||
#include "lwip/prot/dns.h"
|
||||
|
||||
// Track if we've inited the LWIP MDNS at all. It expects to only init once.
|
||||
// Subsequent times, we restart it.
|
||||
STATIC bool inited = false;
|
||||
// Track if we are globally inited. This essentially forces one inited MDNS
|
||||
// object at a time. (But ignores MDNS objects that are deinited.)
|
||||
STATIC bool inited = false;
|
||||
STATIC bool object_inited = false;
|
||||
|
||||
#define NETIF_STA (&cyw43_state.netif[CYW43_ITF_STA])
|
||||
#define NETIF_AP (&cyw43_state.netif[CYW43_ITF_AP])
|
||||
|
||||
void mdns_server_construct(mdns_server_obj_t *self, bool workflow) {
|
||||
if (inited) {
|
||||
if (object_inited) {
|
||||
self->inited = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!inited) {
|
||||
mdns_resp_init();
|
||||
inited = true;
|
||||
} else {
|
||||
mdns_resp_restart(NETIF_STA);
|
||||
}
|
||||
self->inited = true;
|
||||
|
||||
uint8_t mac[6];
|
||||
@ -72,7 +79,7 @@ void common_hal_mdns_server_construct(mdns_server_obj_t *self, mp_obj_t network_
|
||||
mp_raise_ValueError(translate("mDNS only works with built-in WiFi"));
|
||||
return;
|
||||
}
|
||||
if (inited) {
|
||||
if (object_inited) {
|
||||
mp_raise_RuntimeError(translate("mDNS already initialized"));
|
||||
}
|
||||
mdns_server_construct(self, false);
|
||||
@ -83,7 +90,7 @@ void common_hal_mdns_server_deinit(mdns_server_obj_t *self) {
|
||||
return;
|
||||
}
|
||||
self->inited = false;
|
||||
inited = false;
|
||||
object_inited = false;
|
||||
mdns_resp_remove_netif(NETIF_STA);
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ STATIC mp_obj_t mdns_server_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
}
|
||||
#endif
|
||||
|
||||
mdns_server_obj_t *self = m_new_obj(mdns_server_obj_t);
|
||||
mdns_server_obj_t *self = m_new_obj_with_finaliser(mdns_server_obj_t);
|
||||
self->base.type = &mdns_server_type;
|
||||
common_hal_mdns_server_construct(self, args[ARG_network_interface].u_obj);
|
||||
|
||||
@ -205,6 +205,7 @@ STATIC const mp_rom_map_elem_t mdns_server_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_find), MP_ROM_PTR(&mdns_server_find_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_advertise_service), MP_ROM_PTR(&mdns_server_advertise_service_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mdns_server_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&mdns_server_deinit_obj) },
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user