Skip to content

Commit

Permalink
ConnectionManager: check if connexion is running before use
Browse files Browse the repository at this point in the history
Change-Id: I4f344be3c820b744f442286f8e226f9185fa9cfd
  • Loading branch information
aberaud committed Sep 26, 2024
1 parent aca437e commit 1aaaa96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/multiplexed_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class MultiplexedSocket : public std::enable_shared_from_this<MultiplexedSocket>
* 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
Expand Down
18 changes: 10 additions & 8 deletions src/connectionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/multiplexed_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class MultiplexedSocket::Impl
clearSockets();
}

bool isRunning() const {
return !isShutdown_ && !stop;
}

std::shared_ptr<ChannelSocket> makeSocket(const std::string& name,
uint16_t channel,
bool isInitiator)
Expand Down Expand Up @@ -678,6 +682,12 @@ MultiplexedSocket::shutdown()
pimpl_->shutdown();
}

bool
MultiplexedSocket::isRunning() const
{
return pimpl_->isRunning();
}

void
MultiplexedSocket::join()
{
Expand Down

0 comments on commit 1aaaa96

Please sign in to comment.