From 0d57ae3db73d94ab2e7ac0a799a9165c8a221c80 Mon Sep 17 00:00:00 2001 From: ABeltramo Date: Sat, 19 Oct 2024 11:24:45 +0200 Subject: [PATCH] fix: allow control over running it in a separate thread --- include/mdns_cpp/mdns.hpp | 2 +- src/mdns.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/mdns_cpp/mdns.hpp b/include/mdns_cpp/mdns.hpp index 552b17a..fdff992 100644 --- a/include/mdns_cpp/mdns.hpp +++ b/include/mdns_cpp/mdns.hpp @@ -14,7 +14,7 @@ class mDNS { public: ~mDNS(); - void startService(); + void startService(bool start_thread=true); void stopService(); bool isServiceRunning(); diff --git a/src/mdns.cpp b/src/mdns.cpp index 4a908a1..1978772 100644 --- a/src/mdns.cpp +++ b/src/mdns.cpp @@ -377,13 +377,17 @@ int service_callback(int sock, const struct sockaddr *from, size_t addrlen, mdns mDNS::~mDNS() { stopService(); } -void mDNS::startService() { +void mDNS::startService(bool start_thread) { if (running_) { stopService(); } running_ = true; - worker_thread_ = std::thread([this]() { this->runMainLoop(); }); + if(start_thread){ + worker_thread_ = std::thread([this]() { this->runMainLoop(); }); + } else { + this->runMainLoop(); + } } void mDNS::stopService() {