summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-01-24 21:27:32 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2024-08-13 21:29:05 +0200
commit0eb84d2c6d4657c482b3deff8d4114d676197099 (patch)
tree65f076288121bd07dd9f19691c25cbfb1aa737d6
parente7687e020f6d31a22aadb08aa73ae000796ae139 (diff)
Server: start worker threads after initialization of servicesHEADmaster
-rw-r--r--src/network.cpp13
-rw-r--r--src/network.h2
2 files changed, 11 insertions, 4 deletions
diff --git a/src/network.cpp b/src/network.cpp
index e63949f..5807381 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -34,9 +34,11 @@ Server::Server(const Head<LocalState> & head, ServerConfig && config):
p->services.reserve(config.services.size());
for (const auto & ctor : config.services)
p->services.emplace_back(ctor(*this));
+
+ p->startThreads();
}
-Server:: Server(const std::shared_ptr<Priv> & ptr):
+Server::Server(const std::shared_ptr<Priv> & ptr):
p(ptr)
{
}
@@ -366,9 +368,6 @@ Server::Priv::Priv(const Head<LocalState> & local, const Identity & self):
laddr.sin6_port = htons(discoveryPort);
if (::bind(sock, (sockaddr *) &laddr, sizeof(laddr)) < 0)
throw std::system_error(errno, std::generic_category());
-
- threadListen = thread([this] { doListen(); });
- threadAnnounce = thread([this] { doAnnounce(); });
}
Server::Priv::~Priv()
@@ -391,6 +390,12 @@ shared_ptr<Server::Priv> Server::Priv::getptr()
return shared_ptr<Priv>(this, [](Priv *){});
}
+void Server::Priv::startThreads()
+{
+ threadListen = thread([this] { doListen(); });
+ threadAnnounce = thread([this] { doAnnounce(); });
+}
+
void Server::Priv::doListen()
{
unique_lock lock(dataMutex);
diff --git a/src/network.h b/src/network.h
index 12ec4e1..4c23b47 100644
--- a/src/network.h
+++ b/src/network.h
@@ -89,6 +89,8 @@ struct Server::Priv
shared_ptr<Priv> getptr();
+ void startThreads();
+
void doListen();
void doAnnounce();