Skip to content

Commit

Permalink
Improve error messages in Darwin DNS-SD implementation. (project-chip…
Browse files Browse the repository at this point in the history
…#33930)

We shouldn't claim a canceled browse that found things is a failure.
  • Loading branch information
bzbarsky-apple committed Jun 15, 2024
1 parent 48f6bc1 commit 667cae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/platform/Darwin/DnssdContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,17 @@ BrowseContext::BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServ

void BrowseContext::DispatchFailure(const char * errorStr, CHIP_ERROR err)
{
ChipLogError(Discovery, "Mdns: Browse failure (%s)", errorStr);
if (err == CHIP_ERROR_CANCELLED && dispatchedSuccessOnce)
{
// We've been canceled after finding some devices. Treat this as a
// success, because maybe (common case, in fact) those were the devices
// our consumer was looking for.
ChipLogProgress(Discovery, "Mdns: Browse canceled");
}
else
{
ChipLogError(Discovery, "Mdns: Browse failure (%s)", errorStr);
}
callback(context, nullptr, 0, true, err);
MdnsContexts::GetInstance().Remove(this);
}
Expand All @@ -376,6 +386,8 @@ void BrowseContext::DispatchPartialSuccess()
sDispatchedServices = nullptr;
sContextDispatchingSuccess = nullptr;
services.clear();

dispatchedSuccessOnce = true;
}

void BrowseContext::OnBrowse(DNSServiceFlags flags, const char * name, const char * type, const char * domain, uint32_t interfaceId)
Expand Down
1 change: 1 addition & 0 deletions src/platform/Darwin/DnssdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct BrowseContext : public BrowseHandler
{
DnssdBrowseCallback callback;
std::vector<std::pair<DnssdService, std::string>> services;
bool dispatchedSuccessOnce = false;

BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol);

Expand Down

0 comments on commit 667cae8

Please sign in to comment.