Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comments for MDNS code #7461

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions ports/espressif/common-hal/mdns/Server.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@

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

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

void mdns_server_construct(mdns_server_obj_t *self, bool workflow) {
if (inited) {
if (mdns_started) {
// Mark this object as deinited because another is already using MDNS.
self->inited = false;
return;
}
mdns_init();
mdns_started = true;

uint8_t mac[6];
esp_netif_get_mac(common_hal_wifi_radio_obj.netif, mac);
Expand Down Expand Up @@ -81,7 +86,7 @@ void common_hal_mdns_server_deinit(mdns_server_obj_t *self) {
return;
}
self->inited = false;
inited = false;
mdns_started = false;
mdns_free();
}

Expand Down
4 changes: 2 additions & 2 deletions ports/espressif/common-hal/mdns/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct {
mp_obj_base_t base;
const char *hostname;
const char *instance_name;
// "cpy-" "XXXXXX" "\0"
char default_hostname[4 + 6 + 1];
char default_hostname[sizeof("cpy-XXXXXX")];
// Track if this object owns access to the underlying MDNS service.
bool inited;
} mdns_server_obj_t;
1 change: 1 addition & 0 deletions ports/raspberrypi/common-hal/mdns/Server.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ STATIC bool object_inited = false;

void mdns_server_construct(mdns_server_obj_t *self, bool workflow) {
if (object_inited) {
// Mark the object as deinit since another is already using MDNS.
self->inited = false;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions ports/raspberrypi/common-hal/mdns/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ typedef struct {
mp_obj_base_t base;
const char *hostname;
const char *instance_name;
// "cpy-" "XXXXXX" "\0"
char default_hostname[4 + 6 + 1];
char default_hostname[sizeof("cpy-XXXXXX")];
const char *service_type[MDNS_MAX_SERVICES];
// Track if this object owns access to the underlying MDNS service.
bool inited;
} mdns_server_obj_t;