Skip to content

Commit 009055c

Browse files
committed
Add the domain names to the services vector
1 parent 0fda155 commit 009055c

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/platform/Darwin/DnssdContexts.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,14 @@ void BrowseContext::DispatchSuccess()
368368
void BrowseContext::DispatchPartialSuccess()
369369
{
370370
sContextDispatchingSuccess = this;
371-
callback(context, services.data(), services.size(), false, CHIP_NO_ERROR);
371+
std::vector<DnssdService> dnsServices;
372+
for (auto iter : services)
373+
{
374+
dnsServices.push_back(std::move(iter.first));
375+
}
376+
callback(context, dnsServices.data(), dnsServices.size(), false, CHIP_NO_ERROR);
372377
sContextDispatchingSuccess = nullptr;
373378
services.clear();
374-
domainNames.clear();
375379
}
376380

377381
void BrowseContext::OnBrowse(DNSServiceFlags flags, const char * name, const char * type, const char * domain, uint32_t interfaceId)
@@ -391,8 +395,7 @@ void BrowseContext::OnBrowseAdd(const char * name, const char * type, const char
391395

392396
VerifyOrReturn(IsLocalDomain(domain));
393397
auto service = GetService(name, type, protocol, interfaceId);
394-
services.push_back(service);
395-
domainNames.push_back(std::make_pair(service, std::string(domain)));
398+
services.push_back(std::make_pair(std::move(service), std::string(domain)));
396399
}
397400

398401
void BrowseContext::OnBrowseRemove(const char * name, const char * type, const char * domain, uint32_t interfaceId)
@@ -403,17 +406,10 @@ void BrowseContext::OnBrowseRemove(const char * name, const char * type, const c
403406
VerifyOrReturn(name != nullptr);
404407
VerifyOrReturn(IsLocalDomain(domain));
405408

406-
domainNames.erase(std::remove_if(domainNames.begin(), domainNames.end(),
407-
[name, type, interfaceId](const auto & domainName) {
408-
return strcmp(domainName.first.mName, name) == 0 && domainName.first.mType == type &&
409-
domainName.first.mInterface == chip::Inet::InterfaceId(interfaceId);
410-
}),
411-
domainNames.end());
412-
413409
services.erase(std::remove_if(services.begin(), services.end(),
414-
[name, type, interfaceId](const DnssdService & service) {
415-
return strcmp(name, service.mName) == 0 && type == GetFullType(&service) &&
416-
service.mInterface == chip::Inet::InterfaceId(interfaceId);
410+
[name, type, interfaceId, domain](const auto & service) {
411+
return strcmp(name, service.first.mName) == 0 && type == GetFullType(&service.first) &&
412+
service.first.mInterface == chip::Inet::InterfaceId(interfaceId) && strcmp(domain, service.second.c_str()) == 0;
417413
}),
418414
services.end());
419415
}

src/platform/Darwin/DnssdImpl.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ struct BrowseHandler : public GenericContext
167167
struct BrowseContext : public BrowseHandler
168168
{
169169
DnssdBrowseCallback callback;
170-
std::vector<DnssdService> services;
171-
std::vector<std::pair<DnssdService, std::string>> domainNames;
170+
std::vector<std::pair<DnssdService, std::string>> services;
172171

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

0 commit comments

Comments
 (0)