zeroconf: pass global port to init function

This commit is contained in:
Max Kellermann 2021-02-24 06:36:14 +01:00
parent d527d4b530
commit a312629aad
6 changed files with 9 additions and 13 deletions

View File

@ -24,7 +24,6 @@
#include "avahi/Publisher.hxx" #include "avahi/Publisher.hxx"
#include "avahi/Service.hxx" #include "avahi/Service.hxx"
#include "ZeroconfInternal.hxx" #include "ZeroconfInternal.hxx"
#include "Listen.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -55,7 +54,7 @@ public:
static AvahiGlue *avahi_glue; static AvahiGlue *avahi_glue;
void void
AvahiInit(EventLoop &loop, const char *serviceName) AvahiInit(EventLoop &loop, const char *serviceName, unsigned port)
{ {
LogDebug(avahi_domain, "Initializing interface"); LogDebug(avahi_domain, "Initializing interface");
@ -65,7 +64,7 @@ AvahiInit(EventLoop &loop, const char *serviceName)
std::forward_list<Avahi::Service> services; std::forward_list<Avahi::Service> services;
services.emplace_front(AVAHI_IF_UNSPEC, services.emplace_front(AVAHI_IF_UNSPEC,
AVAHI_PROTO_UNSPEC, AVAHI_PROTO_UNSPEC,
SERVICE_TYPE, listen_port); SERVICE_TYPE, port);
avahi_glue = new AvahiGlue(loop, serviceName, std::move(services)); avahi_glue = new AvahiGlue(loop, serviceName, std::move(services));
} }

View File

@ -23,7 +23,7 @@
class EventLoop; class EventLoop;
void void
AvahiInit(EventLoop &loop, const char *service_name); AvahiInit(EventLoop &loop, const char *service_name, unsigned port);
void void
AvahiDeinit(); AvahiDeinit();

View File

@ -19,7 +19,6 @@
#include "ZeroconfBonjour.hxx" #include "ZeroconfBonjour.hxx"
#include "ZeroconfInternal.hxx" #include "ZeroconfInternal.hxx"
#include "Listen.hxx"
#include "event/SocketEvent.hxx" #include "event/SocketEvent.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -84,13 +83,13 @@ dnsRegisterCallback([[maybe_unused]] DNSServiceRef sdRef,
} }
void void
BonjourInit(EventLoop &loop, const char *service_name) BonjourInit(EventLoop &loop, const char *service_name, unsigned port)
{ {
DNSServiceRef dnsReference; DNSServiceRef dnsReference;
DNSServiceErrorType error = DNSServiceRegister(&dnsReference, DNSServiceErrorType error = DNSServiceRegister(&dnsReference,
0, 0, service_name, 0, 0, service_name,
SERVICE_TYPE, nullptr, nullptr, SERVICE_TYPE, nullptr, nullptr,
htons(listen_port), 0, htons(port), 0,
nullptr, nullptr,
dnsRegisterCallback, dnsRegisterCallback,
nullptr); nullptr);

View File

@ -23,7 +23,7 @@
class EventLoop; class EventLoop;
void void
BonjourInit(EventLoop &loop, const char *service_name); BonjourInit(EventLoop &loop, const char *service_name, unsigned port);
void void
BonjourDeinit(); BonjourDeinit();

View File

@ -82,11 +82,11 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
} }
#ifdef HAVE_AVAHI #ifdef HAVE_AVAHI
AvahiInit(loop, serviceName); AvahiInit(loop, serviceName, listen_port);
#endif #endif
#ifdef HAVE_BONJOUR #ifdef HAVE_BONJOUR
BonjourInit(loop, serviceName); BonjourInit(loop, serviceName, listen_port);
#endif #endif
} }

View File

@ -23,15 +23,13 @@
#include <stdlib.h> #include <stdlib.h>
unsigned listen_port = 1234;
int int
main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{ {
EventLoop event_loop; EventLoop event_loop;
const ShutdownHandler shutdown_handler(event_loop); const ShutdownHandler shutdown_handler(event_loop);
AvahiInit(event_loop, "test"); AvahiInit(event_loop, "test", 1234);
event_loop.Run(); event_loop.Run();