From 1aaaa962e100b4bce62a91af137110dceddfe733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Thu, 26 Sep 2024 12:41:58 -0400 Subject: [PATCH] ConnectionManager: check if connexion is running before use Change-Id: I4f344be3c820b744f442286f8e226f9185fa9cfd --- include/multiplexed_socket.h | 1 + src/connectionmanager.cpp | 18 ++++++++++-------- src/multiplexed_socket.cpp | 10 ++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/multiplexed_socket.h b/include/multiplexed_socket.h index 480932c..e57d1d4 100644 --- a/include/multiplexed_socket.h +++ b/include/multiplexed_socket.h @@ -123,6 +123,7 @@ public: * This will close all channels and send a TLS EOF on the main socket. */ void shutdown(); + bool isRunning() const; /** * This will wait that eventLoop is stopped and stop it if necessary diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp index 138afc5..831762b 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp @@ -883,14 +883,16 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif if (auto info = di->getConnectedInfo()) { std::unique_lock lkc(info->mutex_); if (auto sock = info->socket_) { - info->cbIds_.emplace(vid); - diw.requested = true; - lkc.unlock(); - lk.unlock(); - if (sthis->config_->logger) - sthis->config_->logger->debug("[device {}] Peer already connected. Add a new channel", deviceId); - sthis->sendChannelRequest(di, info, sock, name, vid); - return; + if (sock->isRunning()) { + info->cbIds_.emplace(vid); + diw.requested = true; + lkc.unlock(); + lk.unlock(); + if (sthis->config_->logger) + sthis->config_->logger->debug("[device {}] Peer already connected. Add a new channel", deviceId); + sthis->sendChannelRequest(di, info, sock, name, vid); + return; + } } } diff --git a/src/multiplexed_socket.cpp b/src/multiplexed_socket.cpp index 8386d2b..910e31e 100644 --- a/src/multiplexed_socket.cpp +++ b/src/multiplexed_socket.cpp @@ -127,6 +127,10 @@ public: clearSockets(); } + bool isRunning() const { + return !isShutdown_ && !stop; + } + std::shared_ptr<ChannelSocket> makeSocket(const std::string& name, uint16_t channel, bool isInitiator) @@ -678,6 +682,12 @@ MultiplexedSocket::shutdown() pimpl_->shutdown(); } +bool +MultiplexedSocket::isRunning() const +{ + return pimpl_->isRunning(); +} + void MultiplexedSocket::join() { -- GitLab