[wpinet] Add callback for mDNS service resolver (#7986)

This commit is contained in:
Thad House
2025-05-23 13:22:59 -07:00
committed by GitHub
parent 0cb4df7e05
commit 22d12d2345
4 changed files with 94 additions and 10 deletions

View File

@@ -4,6 +4,8 @@
#include "wpinet/MulticastServiceResolver.h"
#include <arpa/inet.h>
#include <memory>
#include <string>
#include <utility>
@@ -44,6 +46,26 @@ bool MulticastServiceResolver::HasImplementation() const {
return pImpl->table.IsValid();
}
bool MulticastServiceResolver::SetCopyCallback(
std::function<bool(const ServiceData&)> callback) {
std::scoped_lock lock{*pImpl->thread};
if (pImpl->client) {
return false;
}
copyCallback = std::move(callback);
return true;
}
bool MulticastServiceResolver::SetMoveCallback(
std::function<void(ServiceData&&)> callback) {
std::scoped_lock lock{*pImpl->thread};
if (pImpl->client) {
return false;
}
moveCallback = std::move(callback);
return true;
}
static void ResolveCallback(AvahiServiceResolver* r, AvahiIfIndex interface,
AvahiProtocol protocol, AvahiResolverEvent event,
const char* name, const char* type,
@@ -83,8 +105,8 @@ static void ResolveCallback(AvahiServiceResolver* r, AvahiIfIndex interface,
outputHostName.append(".");
} while (true);
data.ipv4Address = address->data.ipv4.address;
data.port = port;
data.ipv4Address = ntohl(address->data.ipv4.address);
data.port = ntohs(port);
data.serviceName = name;
data.hostName = std::string{outputHostName};