Skip to content
Snippets Groups Projects
Commit 91fd4b65 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

upnp: stop asio context out of the loop

Change-Id: Iaee6527de1a599d6c79ef494637fb968a3035bbb
parent 027af2a3
Branches
No related tags found
No related merge requests found
......@@ -45,9 +45,9 @@ constexpr static uint16_t UPNP_UDP_PORT_MAX {UPNP_UDP_PORT_MIN + 5000};
UPnPContext::UPnPContext(const std::shared_ptr<asio::io_context>& ioContext, const std::shared_ptr<dht::log::Logger>& logger)
: ctx(createIoContext(ioContext, logger))
, logger_(logger)
, mappingListUpdateTimer_(*ctx)
, connectivityChangedTimer_(*ctx)
, logger_(logger)
{
if (logger_) logger_->debug("Creating UPnPContext instance [{}]", fmt::ptr(this));
......@@ -88,22 +88,13 @@ UPnPContext::shutdown(std::condition_variable& cv)
proto->terminate();
}
{
std::lock_guard<std::mutex> lock(mappingMutex_);
mappingList_->clear();
mappingListUpdateTimer_.cancel();
controllerList_.clear();
protocolList_.clear();
shutdownComplete_ = true;
cv.notify_one();
}
if (ioContextRunner_) {
if (logger_) logger_->debug("UPnPContext: stopping io_context thread");
ctx->stop();
ioContextRunner_->join();
ioContextRunner_.reset();
}
std::lock_guard<std::mutex> lock(mappingMutex_);
mappingList_->clear();
mappingListUpdateTimer_.cancel();
controllerList_.clear();
protocolList_.clear();
shutdownComplete_ = true;
cv.notify_one();
}
void
......@@ -121,6 +112,13 @@ UPnPContext::shutdown()
} else {
if (logger_) logger_->error("Shutdown timed-out");
}
if (ioContextRunner_) {
if (logger_) logger_->debug("UPnPContext: stopping io_context thread");
ctx->stop();
ioContextRunner_->join();
ioContextRunner_.reset();
}
}
UPnPContext::~UPnPContext()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment