Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mdns-mdnssd] simplify service and host registrations
This commit updates and enhances the `Mdns::PublisherMDnsSd` class, which implements the `Mdns::Publisher` interface using MDNSResponder as its underlying DNS-SD provider. The following changes are made related to service registration: - Registration simplified: The `PublishServiceImpl()` method is updated to allocate a `DnssdServiceRegistration` object first and add it to the list of registrations before asking it to register itself. This simplifies the code path for invoking the `ResultCallback` on success or failure (one path to handle all cases) and also makes it clear that the `DNSServiceRef` object is owned and managed by the `DnssdServiceRegistration` instance. - The `HandleRegisterResult` callback passed to the MDNSResponder `DNSServiceRegister()` function is now defined and handled by the `DnssdServiceRegistration` class instead of by the `PublisherMDnsSd` class. This simplifies the code, as we no longer need to iterate through the full list of `Registration` objects to find the one corresponding to a related `mServiceRef`. It also fits well with the notion of the `mServiceRef` being owned by a corresponding `DnssdServiceRegistration` object (the destructor will call the `DNSServiceRefDeallocate()` function to deallocate the `mServiceRef`, which will stop the MDNSResponder from invoking the callback). This commit also makes similar changes to the `PublishHostImpl()` and `DnssdHostRegistration` methods, but there are some additional changes specific to host registration: - The `DnssdHostRegistration` class now tracks whether each host IPv6 address is registered or not. - The `DnssdHostRegistration` destructor is also changed so that it will always remove all outstanding `DNSRecordRef` objects for all host IPv6 addresses. This updates and fixes the existing behavior where the records were removed only if `IsCompleted()` returned `true`, which requires all addresses to be registered, and could lead to some of the address records not being removed if the host registration was replaced or deleted quickly after its registration.
- Loading branch information