diff --git a/include/multiplexed_socket.h b/include/multiplexed_socket.h index 480932cd701ffd9b3d3d36681d3b2b722b054d41..e57d1d420e4751117b3e858d6e96b97ccf7c6d25 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 138afc5fbd98f34f68f143513d24280523a5e7de..831762ba71da447d28031773e97954b58fd75407 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 8386d2b9fea09277abe1b4fd4b2ae87563b23c1c..910e31e87bcf9dfa043bfb710f3b6c291b004558 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() {