summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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();