diff --git a/include/multiplexed_socket.h b/include/multiplexed_socket.h index 480932cd..e57d1d42 100644 --- a/include/multiplexed_socket.h +++ b/include/multiplexed_socket.h @@ -123,6 +123,7 @@ class MultiplexedSocket : public std::enable_shared_from_this * 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 138afc5f..831762ba 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp @@ -883,14 +883,16 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptrgetConnectedInfo()) { 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 8386d2b9..910e31e8 100644 --- a/src/multiplexed_socket.cpp +++ b/src/multiplexed_socket.cpp @@ -127,6 +127,10 @@ class MultiplexedSocket::Impl clearSockets(); } + bool isRunning() const { + return !isShutdown_ && !stop; + } + std::shared_ptr 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() {