Skip to content

Commit

Permalink
ESP32: check whether the mdns service exists before deleting it (#35397)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored and pull[bot] committed Sep 28, 2024
1 parent ad7d751 commit 6a6d247
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/platform/ESP32/ESP32DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ CHIP_ERROR EspDnssdPublishService(const DnssdService * service, DnssdPublishCall
}
}

// Remove service before adding it
if (mdns_service_exists(service->mType, GetProtocolString(service->mProtocol), nullptr))
{
mdns_service_remove_for_host(service->mName, service->mType, GetProtocolString(service->mProtocol), nullptr);
}

espError = mdns_service_add(service->mName, service->mType, GetProtocolString(service->mProtocol), service->mPort, items,
service->mTextEntrySize);
// The mdns_service_add will return error if we try to add an existing service
Expand Down Expand Up @@ -205,9 +211,18 @@ CHIP_ERROR EspDnssdPublishService(const DnssdService * service, DnssdPublishCall

CHIP_ERROR EspDnssdRemoveServices()
{
mdns_service_remove("_matter", "_tcp");
mdns_service_remove("_matterc", "_udp");
mdns_service_remove("_matterd", "_udp");
if (mdns_service_exists("_matter", "_tcp", nullptr))
{
mdns_service_remove("_matter", "_tcp");
}
if (mdns_service_exists("_matterc", "_udp", nullptr))
{
mdns_service_remove("_matterc", "_udp");
}
if (mdns_service_exists("_matterd", "_udp", nullptr))
{
mdns_service_remove("_matterd", "_udp");
}
return CHIP_NO_ERROR;
}

Expand Down

0 comments on commit 6a6d247

Please sign in to comment.