Skip to content

Commit 1c1cf1c

Browse files
authored
Merge pull request #7461 from tannewt/add_mdns_comments
Add comments for MDNS code
2 parents 79b76f7 + 683e393 commit 1c1cf1c

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

ports/espressif/common-hal/mdns/Server.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@
3333

3434
#include "components/mdns/include/mdns.h"
3535

36-
STATIC bool inited = false;
36+
// Track whether the underlying IDF mdns has been started so that we only
37+
// create a single inited MDNS object to CircuitPython. (After deinit, another
38+
// could be created.)
39+
STATIC bool mdns_started = false;
3740

3841
void mdns_server_construct(mdns_server_obj_t *self, bool workflow) {
39-
if (inited) {
42+
if (mdns_started) {
43+
// Mark this object as deinited because another is already using MDNS.
4044
self->inited = false;
4145
return;
4246
}
4347
mdns_init();
48+
mdns_started = true;
4449

4550
uint8_t mac[6];
4651
esp_netif_get_mac(common_hal_wifi_radio_obj.netif, mac);
@@ -81,7 +86,7 @@ void common_hal_mdns_server_deinit(mdns_server_obj_t *self) {
8186
return;
8287
}
8388
self->inited = false;
84-
inited = false;
89+
mdns_started = false;
8590
mdns_free();
8691
}
8792

ports/espressif/common-hal/mdns/Server.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ typedef struct {
3232
mp_obj_base_t base;
3333
const char *hostname;
3434
const char *instance_name;
35-
// "cpy-" "XXXXXX" "\0"
36-
char default_hostname[4 + 6 + 1];
35+
char default_hostname[sizeof("cpy-XXXXXX")];
36+
// Track if this object owns access to the underlying MDNS service.
3737
bool inited;
3838
} mdns_server_obj_t;

ports/raspberrypi/common-hal/mdns/Server.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ STATIC bool object_inited = false;
4848

4949
void mdns_server_construct(mdns_server_obj_t *self, bool workflow) {
5050
if (object_inited) {
51+
// Mark the object as deinit since another is already using MDNS.
5152
self->inited = false;
5253
return;
5354
}

ports/raspberrypi/common-hal/mdns/Server.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ typedef struct {
3434
mp_obj_base_t base;
3535
const char *hostname;
3636
const char *instance_name;
37-
// "cpy-" "XXXXXX" "\0"
38-
char default_hostname[4 + 6 + 1];
37+
char default_hostname[sizeof("cpy-XXXXXX")];
3938
const char *service_type[MDNS_MAX_SERVICES];
39+
// Track if this object owns access to the underlying MDNS service.
4040
bool inited;
4141
} mdns_server_obj_t;

0 commit comments

Comments
 (0)