From 104842264e0ece9b45cbfea6abad7e3a60a8e6ed Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sat, 15 Jun 2024 00:21:42 -0400 Subject: [PATCH] Improve error messages in Darwin DNS-SD implementation. (#33930) We shouldn't claim a canceled browse that found things is a failure. --- src/platform/Darwin/DnssdContexts.cpp | 14 +++++++++++++- src/platform/Darwin/DnssdImpl.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index fc68a5d779616b..4e88df40ee596d 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -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); } @@ -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) diff --git a/src/platform/Darwin/DnssdImpl.h b/src/platform/Darwin/DnssdImpl.h index 3bf78fac6cb2bd..23044070f52362 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -169,6 +169,7 @@ struct BrowseContext : public BrowseHandler { DnssdBrowseCallback callback; std::vector> services; + bool dispatchedSuccessOnce = false; BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServiceProtocol cbContextProtocol);