From e4fccc85c88f202d31c086f8d86ee315e59bf8e6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 24 Feb 2021 16:21:35 +0100 Subject: [PATCH] Main: move Zeroconf to the I/O thread This will allow using Zeroconf in output plugins (preparing for Snapcast with Zeroconf). --- src/Main.cxx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Main.cxx b/src/Main.cxx index ca4abfbc1..76ecff3a2 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -40,6 +40,7 @@ #include "input/cache/Config.hxx" #include "input/cache/Manager.hxx" #include "event/Loop.hxx" +#include "event/Call.hxx" #include "fs/AllocatedPath.hxx" #include "fs/Config.hxx" #include "playlist/PlaylistRegistry.hxx" @@ -480,7 +481,10 @@ MainConfigured(const struct options &options, const ConfigData &raw_config) #ifdef HAVE_ZEROCONF std::unique_ptr zeroconf; 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 (...) { LogError(std::current_exception(), "Zeroconf initialization failed"); @@ -548,7 +552,12 @@ MainConfigured(const struct options &options, const ConfigData &raw_config) instance.BeginShutdownUpdate(); #ifdef HAVE_ZEROCONF - zeroconf.reset(); + if (zeroconf) { + auto &event_loop = instance.io_thread.GetEventLoop(); + BlockingCall(event_loop, [&](){ + zeroconf.reset(); + }); + } #endif instance.BeginShutdownPartitions();