fix: mDNS-Init nur einmal, Teilfehler wiederholbar
This commit is contained in:
+22
-10
@@ -13,7 +13,9 @@
|
||||
|
||||
#define NL_MDNS_TTL 120
|
||||
|
||||
static bool s_started;
|
||||
static bool s_inited;
|
||||
static bool s_netif_added;
|
||||
static bool s_service_added;
|
||||
static char s_name[NL_NAME_LEN];
|
||||
static char s_mac[18];
|
||||
|
||||
@@ -45,20 +47,30 @@ static void txt_cb(struct mdns_service *service, void *data)
|
||||
static void announce(void *arg)
|
||||
{
|
||||
struct netif *nif = tls_get_netif();
|
||||
bool attempted = false;
|
||||
|
||||
(void)arg;
|
||||
if (!nif)
|
||||
return;
|
||||
if (!s_started) {
|
||||
|
||||
if (!s_inited) {
|
||||
mdns_resp_init();
|
||||
if (mdns_resp_add_netif(nif, nl_wifi_hostname(), NL_MDNS_TTL) == ERR_OK &&
|
||||
mdns_resp_add_service(nif, nl_wifi_hostname(), "_ninlight", DNSSD_PROTO_TCP, NL_HTTP_PORT, NL_MDNS_TTL,
|
||||
txt_cb, NULL) == ERR_OK)
|
||||
s_started = true;
|
||||
printf("mdns: %s.local _ninlight._tcp %s\r\n", nl_wifi_hostname(), s_started ? "up" : "failed");
|
||||
} else {
|
||||
mdns_resp_netif_settings_changed(nif); /* re-announce: new IP or TXT */
|
||||
s_inited = true;
|
||||
}
|
||||
if (!s_netif_added) {
|
||||
attempted = true;
|
||||
s_netif_added = mdns_resp_add_netif(nif, nl_wifi_hostname(), NL_MDNS_TTL) == ERR_OK;
|
||||
}
|
||||
if (s_netif_added && !s_service_added) {
|
||||
attempted = true;
|
||||
s_service_added = mdns_resp_add_service(nif, nl_wifi_hostname(), "_ninlight", DNSSD_PROTO_TCP, NL_HTTP_PORT,
|
||||
NL_MDNS_TTL, txt_cb, NULL) == ERR_OK;
|
||||
}
|
||||
|
||||
if (attempted)
|
||||
printf("mdns: %s.local _ninlight._tcp %s\r\n", nl_wifi_hostname(), s_service_added ? "up" : "failed");
|
||||
else
|
||||
mdns_resp_netif_settings_changed(nif); /* re-announce: new IP or TXT */
|
||||
}
|
||||
|
||||
void nl_mdns_on_ip_up(void)
|
||||
@@ -75,6 +87,6 @@ void nl_mdns_set_name(const char *name)
|
||||
strncpy(s_name, name, sizeof s_name - 1);
|
||||
s_name[sizeof s_name - 1] = '\0';
|
||||
tls_os_release_critical(sr);
|
||||
if (s_started)
|
||||
if (s_service_added)
|
||||
tcpip_callback(announce, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user