ConnectionManager: check if connexion is running before use
Change-Id: I4f344be3c820b744f442286f8e226f9185fa9cfd
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 @@
* 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 @@
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 @@
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 @@
pimpl_->shutdown();
}
+bool
+MultiplexedSocket::isRunning() const
+{
+ return pimpl_->isRunning();
+}
+
void
MultiplexedSocket::join()
{