Skip to content

Commit 667cae8

Browse files
Improve error messages in Darwin DNS-SD implementation. (#33930)
We shouldn't claim a canceled browse that found things is a failure.
1 parent 48f6bc1 commit 667cae8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/platform/Darwin/DnssdContexts.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,17 @@ BrowseContext::BrowseContext(void * cbContext, DnssdBrowseCallback cb, DnssdServ
350350

351351
void BrowseContext::DispatchFailure(const char * errorStr, CHIP_ERROR err)
352352
{
353-
ChipLogError(Discovery, "Mdns: Browse failure (%s)", errorStr);
353+
if (err == CHIP_ERROR_CANCELLED && dispatchedSuccessOnce)
354+
{
355+
// We've been canceled after finding some devices. Treat this as a
356+
// success, because maybe (common case, in fact) those were the devices
357+
// our consumer was looking for.
358+
ChipLogProgress(Discovery, "Mdns: Browse canceled");
359+
}
360+
else
361+
{
362+
ChipLogError(Discovery, "Mdns: Browse failure (%s)", errorStr);
363+
}
354364
callback(context, nullptr, 0, true, err);
355365
MdnsContexts::GetInstance().Remove(this);
356366
}
@@ -376,6 +386,8 @@ void BrowseContext::DispatchPartialSuccess()
376386
sDispatchedServices = nullptr;
377387
sContextDispatchingSuccess = nullptr;
378388
services.clear();
389+
390+
dispatchedSuccessOnce = true;
379391
}
380392

381393
void BrowseContext::OnBrowse(DNSServiceFlags flags, const char * name, const char * type, const char * domain, uint32_t interfaceId)

src/platform/Darwin/DnssdImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct BrowseContext : public BrowseHandler
169169
{
170170
DnssdBrowseCallback callback;
171171
std::vector<std::pair<DnssdService, std::string>> services;
172+
bool dispatchedSuccessOnce = false;
172173

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

0 commit comments

Comments
 (0)