Skip to content

Commit 5bd82c0

Browse files
committed
feat(mdns): support zero item when update subtype
1 parent b4cb8f8 commit 5bd82c0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

components/mdns/include/mdns.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ esp_err_t mdns_service_subtype_add_multiple_items_for_host(const char *instance_
615615
* @param subtype the pointer of subtype array to add.
616616
* @param num_items number of items in subtype array
617617
*
618+
* @note If `num_items` is 0, then remove all subtypes.
619+
*
618620
* @return
619621
* - ESP_OK success
620622
* - ESP_ERR_INVALID_ARG Parameter error

components/mdns/mdns.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6429,8 +6429,8 @@ esp_err_t mdns_service_subtype_update_multiple_items_for_host(const char *instan
64296429
MDNS_SERVICE_LOCK();
64306430
esp_err_t ret = ESP_OK;
64316431
int cur_index = 0;
6432-
ESP_GOTO_ON_FALSE(_mdns_server && _mdns_server->services && !_str_null_or_empty(service_type) && !_str_null_or_empty(proto) &&
6433-
(num_items > 0), ESP_ERR_INVALID_ARG, err, TAG, "Invalid state or arguments");
6432+
ESP_GOTO_ON_FALSE(_mdns_server && _mdns_server->services && !_str_null_or_empty(service_type) && !_str_null_or_empty(proto),
6433+
ESP_ERR_INVALID_ARG, err, TAG, "Invalid state or arguments");
64346434

64356435
mdns_srv_item_t *s = _mdns_get_service_item_instance(instance_name, service_type, proto, hostname);
64366436
ESP_GOTO_ON_FALSE(s, ESP_ERR_NOT_FOUND, err, TAG, "Service doesn't exist");
@@ -6450,8 +6450,9 @@ esp_err_t mdns_service_subtype_update_multiple_items_for_host(const char *instan
64506450
goto exit;
64516451
}
64526452
}
6453-
6454-
_mdns_announce_all_pcbs(&s, 1, false);
6453+
if (num_items) {
6454+
_mdns_announce_all_pcbs(&s, 1, false);
6455+
}
64556456
err:
64566457
if (ret == ESP_ERR_NO_MEM) {
64576458
for (int idx = 0; idx < cur_index; idx++) {

0 commit comments

Comments
 (0)