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

ConnectionManager: shutdown on ioPool instead of main thread

Change-Id: I9c5d79c7e5e66e159990a888964aaa46065359f8
parent 3ffd819e
No related branches found
No related tags found
No related merge requests found
...@@ -488,7 +488,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif ...@@ -488,7 +488,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif
const std::string& connType) const std::string& connType)
{ {
// Avoid dht operation in a DHT callback to avoid deadlocks // Avoid dht operation in a DHT callback to avoid deadlocks
runOnMainThread([w = weak(), dht::ThreadPool::computation().run([w = weak(),
name = std::move(name), name = std::move(name),
cert = std::move(cert), cert = std::move(cert),
cb = std::move(cb), cb = std::move(cb),
...@@ -571,7 +571,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif ...@@ -571,7 +571,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif
eraseInfo](auto&& ice_config) { eraseInfo](auto&& ice_config) {
auto sthis = w.lock(); auto sthis = w.lock();
if (!sthis) { if (!sthis) {
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); }); dht::ThreadPool::io().run([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
return; return;
} }
ice_config.tcpEnable = true; ice_config.tcpEnable = true;
...@@ -583,26 +583,22 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif ...@@ -583,26 +583,22 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif
vid, vid,
connType, connType,
eraseInfo](bool ok) { eraseInfo](bool ok) {
auto sthis = w.lock();
if (!sthis || !ok) {
JAMI_ERR("Cannot initialize ICE session.");
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
return;
}
dht::ThreadPool::io().run([w = std::move(w), dht::ThreadPool::io().run([w = std::move(w),
devicePk = std::move(devicePk), devicePk = std::move(devicePk),
vid = std::move(vid), vid = std::move(vid),
eraseInfo, eraseInfo,
connType] { connType, ok] {
if (!ok) {
JAMI_ERR("Cannot initialize ICE session.");
}
auto sthis = w.lock(); auto sthis = w.lock();
if (!sthis) { if (!sthis || !ok) {
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); }); eraseInfo();
return; return;
} }
sthis->connectDeviceStartIce(devicePk, vid, connType, [=](bool ok) { sthis->connectDeviceStartIce(devicePk, vid, connType, [=](bool ok) {
if (!ok) { if (!ok) {
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); }); dht::ThreadPool::io().run([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
} }
}); });
}); });
...@@ -613,22 +609,18 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif ...@@ -613,22 +609,18 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif
cert = std::move(cert), cert = std::move(cert),
vid, vid,
eraseInfo](bool ok) { eraseInfo](bool ok) {
auto sthis = w.lock();
if (!sthis || !ok) {
JAMI_ERR("ICE negotiation failed.");
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
return;
}
dht::ThreadPool::io().run([w = std::move(w), dht::ThreadPool::io().run([w = std::move(w),
deviceId = std::move(deviceId), deviceId = std::move(deviceId),
name = std::move(name), name = std::move(name),
cert = std::move(cert), cert = std::move(cert),
vid = std::move(vid), vid = std::move(vid),
eraseInfo = std::move(eraseInfo)] { eraseInfo = std::move(eraseInfo),
ok] {
if (!ok)
JAMI_ERR("ICE negotiation failed.");
auto sthis = w.lock(); auto sthis = w.lock();
if (!sthis || !sthis->connectDeviceOnNegoDone(deviceId, name, vid, cert)) if (!sthis || !ok || !sthis->connectDeviceOnNegoDone(deviceId, name, vid, cert))
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); }); eraseInfo();
}); });
}; };
...@@ -651,7 +643,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif ...@@ -651,7 +643,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif
// We need to detect any shutdown if the ice session is destroyed before going to the // We need to detect any shutdown if the ice session is destroyed before going to the
// TLS session; // TLS session;
info->ice_->setOnShutdown([eraseInfo]() { info->ice_->setOnShutdown([eraseInfo]() {
runOnMainThread([eraseInfo = std::move(eraseInfo)] { eraseInfo(); }); dht::ThreadPool::io().run([eraseInfo = std::move(eraseInfo)] { eraseInfo(); });
}); });
info->ice_->initIceInstance(ice_config); info->ice_->initIceInstance(ice_config);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment