Main: move Zeroconf to the I/O thread

This will allow using Zeroconf in output plugins (preparing for
Snapcast with Zeroconf).
This commit is contained in:
Max Kellermann 2021-02-24 16:21:35 +01:00
parent 2efa142ec9
commit e4fccc85c8

View File

@ -40,6 +40,7 @@
#include "input/cache/Config.hxx" #include "input/cache/Config.hxx"
#include "input/cache/Manager.hxx" #include "input/cache/Manager.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "event/Call.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "fs/Config.hxx" #include "fs/Config.hxx"
#include "playlist/PlaylistRegistry.hxx" #include "playlist/PlaylistRegistry.hxx"
@ -480,7 +481,10 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
#ifdef HAVE_ZEROCONF #ifdef HAVE_ZEROCONF
std::unique_ptr<ZeroconfHelper> zeroconf; std::unique_ptr<ZeroconfHelper> zeroconf;
try { try {
zeroconf = ZeroconfInit(raw_config, instance.event_loop); auto &event_loop = instance.io_thread.GetEventLoop();
BlockingCall(event_loop, [&](){
zeroconf = ZeroconfInit(raw_config, event_loop);
});
} catch (...) { } catch (...) {
LogError(std::current_exception(), LogError(std::current_exception(),
"Zeroconf initialization failed"); "Zeroconf initialization failed");
@ -548,7 +552,12 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
instance.BeginShutdownUpdate(); instance.BeginShutdownUpdate();
#ifdef HAVE_ZEROCONF #ifdef HAVE_ZEROCONF
if (zeroconf) {
auto &event_loop = instance.io_thread.GetEventLoop();
BlockingCall(event_loop, [&](){
zeroconf.reset(); zeroconf.reset();
});
}
#endif #endif
instance.BeginShutdownPartitions(); instance.BeginShutdownPartitions();