21
21
#include < lib/support/CHIPMemString.h>
22
22
#include < platform/CHIPDeviceLayer.h>
23
23
24
+ #include < net/if.h>
25
+
24
26
using namespace chip ::Dnssd;
25
27
using namespace chip ::Dnssd::Internal;
26
28
@@ -516,32 +518,35 @@ void ResolveContext::DispatchSuccess()
516
518
// ChipDnssdResolveNoLongerNeeded don't find us and try to also remove us.
517
519
bool needDelete = MdnsContexts::GetInstance ().RemoveWithoutDeleting (this );
518
520
519
- for (auto & interface : interfaces)
520
- {
521
- auto & ips = interface.second .addresses ;
521
+ #if TARGET_OS_TV
522
+ // On tvOS, priotize results from en0, en1, ir0 in that order, if those
523
+ // interfaces are present, since those will generally have more up-to-date
524
+ // information.
525
+ static const unsigned int priorityInterfaceIndices[] = {
526
+ if_nametoindex (" en0" ),
527
+ if_nametoindex (" en1" ),
528
+ if_nametoindex (" ir0" ),
529
+ };
522
530
523
- // Some interface may not have any ips, just ignore them.
524
- if (ips.size () == 0 )
531
+ for (auto interfaceIndex : priorityInterfaceIndices)
532
+ {
533
+ if (TryReportingResultsForInterfaceIndex (static_cast <uint32_t >(interfaceIndex)))
525
534
{
526
- continue ;
535
+ if (needDelete)
536
+ {
537
+ MdnsContexts::GetInstance ().Delete (this );
538
+ }
539
+ return ;
527
540
}
541
+ }
542
+ #endif // TARGET_OS_TV
528
543
529
- ChipLogProgress (Discovery, " Mdns: Resolve success on interface %" PRIu32, interface.first );
530
-
531
- auto & service = interface.second .service ;
532
- auto addresses = Span<Inet::IPAddress>(ips.data (), ips.size ());
533
- if (nullptr == callback)
534
- {
535
- auto delegate = static_cast <CommissioningResolveDelegate *>(context);
536
- DiscoveredNodeData nodeData;
537
- service.ToDiscoveredNodeData (addresses, nodeData);
538
- delegate->OnNodeDiscovered (nodeData);
539
- }
540
- else
544
+ for (auto & interface : interfaces)
545
+ {
546
+ if (TryReportingResultsForInterfaceIndex (interface.first ))
541
547
{
542
- callback (context, &service, addresses, CHIP_NO_ERROR) ;
548
+ break ;
543
549
}
544
- break ;
545
550
}
546
551
547
552
if (needDelete)
@@ -550,6 +555,42 @@ void ResolveContext::DispatchSuccess()
550
555
}
551
556
}
552
557
558
+ bool ResolveContext::TryReportingResultsForInterfaceIndex (uint32_t interfaceIndex)
559
+ {
560
+ if (interfaceIndex == 0 )
561
+ {
562
+ // Not actually an interface we have.
563
+ return false ;
564
+ }
565
+
566
+ auto & interface = interfaces[interfaceIndex];
567
+ auto & ips = interface.addresses ;
568
+
569
+ // Some interface may not have any ips, just ignore them.
570
+ if (ips.size () == 0 )
571
+ {
572
+ return false ;
573
+ }
574
+
575
+ ChipLogProgress (Discovery, " Mdns: Resolve success on interface %" PRIu32, interfaceIndex);
576
+
577
+ auto & service = interface.service ;
578
+ auto addresses = Span<Inet::IPAddress>(ips.data (), ips.size ());
579
+ if (nullptr == callback)
580
+ {
581
+ auto delegate = static_cast <CommissioningResolveDelegate *>(context);
582
+ DiscoveredNodeData nodeData;
583
+ service.ToDiscoveredNodeData (addresses, nodeData);
584
+ delegate->OnNodeDiscovered (nodeData);
585
+ }
586
+ else
587
+ {
588
+ callback (context, &service, addresses, CHIP_NO_ERROR);
589
+ }
590
+
591
+ return true ;
592
+ }
593
+
553
594
CHIP_ERROR ResolveContext::OnNewAddress (uint32_t interfaceId, const struct sockaddr * address)
554
595
{
555
596
// If we don't have any information about this interfaceId, just ignore the
0 commit comments