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/apps/mdns.h"
|
||||||
#include "lwip/prot/dns.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
|
// Track if we are globally inited. This essentially forces one inited MDNS
|
||||||
// object at a time. (But ignores MDNS objects that are deinited.)
|
// 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_STA (&cyw43_state.netif[CYW43_ITF_STA])
|
||||||
#define NETIF_AP (&cyw43_state.netif[CYW43_ITF_AP])
|
#define NETIF_AP (&cyw43_state.netif[CYW43_ITF_AP])
|
||||||
|
|
||||||
void mdns_server_construct(mdns_server_obj_t *self, bool workflow) {
|
void mdns_server_construct(mdns_server_obj_t *self, bool workflow) {
|
||||||
if (inited) {
|
if (object_inited) {
|
||||||
self->inited = false;
|
self->inited = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mdns_resp_init();
|
if (!inited) {
|
||||||
inited = true;
|
mdns_resp_init();
|
||||||
|
inited = true;
|
||||||
|
} else {
|
||||||
|
mdns_resp_restart(NETIF_STA);
|
||||||
|
}
|
||||||
self->inited = true;
|
self->inited = true;
|
||||||
|
|
||||||
uint8_t mac[6];
|
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"));
|
mp_raise_ValueError(translate("mDNS only works with built-in WiFi"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (inited) {
|
if (object_inited) {
|
||||||
mp_raise_RuntimeError(translate("mDNS already initialized"));
|
mp_raise_RuntimeError(translate("mDNS already initialized"));
|
||||||
}
|
}
|
||||||
mdns_server_construct(self, false);
|
mdns_server_construct(self, false);
|
||||||
@ -83,7 +90,7 @@ void common_hal_mdns_server_deinit(mdns_server_obj_t *self) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self->inited = false;
|
self->inited = false;
|
||||||
inited = false;
|
object_inited = false;
|
||||||
mdns_resp_remove_netif(NETIF_STA);
|
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
|
#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;
|
self->base.type = &mdns_server_type;
|
||||||
common_hal_mdns_server_construct(self, args[ARG_network_interface].u_obj);
|
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_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_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) },
|
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&mdns_server_deinit_obj) },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user