connectionmanager: do not cancel all waiting channel if first is declined
backport of 22d5417da3023095695d3b9655403b5632f528db in jami-daemon
Change-Id: I865617ff71d1a5fc96fd075b23cd8f85dc7e6599
diff --git a/include/multiplexed_socket.h b/include/multiplexed_socket.h
index d8e6e16..9e254bb 100644
--- a/include/multiplexed_socket.h
+++ b/include/multiplexed_socket.h
@@ -48,7 +48,7 @@
const std::string& /* name */)>;
using OnConnectionReadyCb
= std::function<void(const DeviceId& /* deviceId */, const std::shared_ptr<ChannelSocket>&)>;
-using ChannelReadyCb = std::function<void(void)>;
+using ChannelReadyCb = std::function<void(bool)>;
using OnShutdownCb = std::function<void(void)>;
static constexpr auto SEND_BEACON_TIMEOUT = std::chrono::milliseconds(3000);
@@ -298,7 +298,7 @@
*/
void shutdown() override;
- void ready();
+ void ready(bool accepted);
/**
* Triggered when a specific channel is ready
* Used by ConnectionManager::connectDevice()
diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp
index 03e4c65..17206d3 100644
--- a/src/connectionmanager.cpp
+++ b/src/connectionmanager.cpp
@@ -642,7 +642,7 @@
const auto& pendings = pendingsIt->second;
while (pendings.connecting.find(vid) != pendings.connecting.end()
&& pendings.waiting.find(vid) != pendings.waiting.end()) {
- vid = ValueIdDist(1, JAMI_ID_MAX_VAL)(sthis->account.rand);
+ vid = ValueIdDist(1, ID_MAX_VAL)(sthis->rand);
}
}
// Check if already connecting
diff --git a/src/multiplexed_socket.cpp b/src/multiplexed_socket.cpp
index 5abf742..dd6c298 100644
--- a/src/multiplexed_socket.cpp
+++ b/src/multiplexed_socket.cpp
@@ -283,7 +283,7 @@
}
onChannelReady_(deviceId, socket);
- socket->ready();
+ socket->ready(true);
// Due to the callbacks that can take some time, onAccept can arrive after
// receiving all the data. In this case, the socket should be removed here
// as handle by onChannelReady_
@@ -420,7 +420,7 @@
if (accept) {
onChannelReady_(deviceId, channelSocket);
- channelSocket->ready();
+ channelSocket->ready(true);
}
}
@@ -448,6 +448,7 @@
std::lock_guard<std::mutex> lkSockets(pimpl.socketsMutex);
auto channel = pimpl.sockets.find(req.channel);
if (channel != pimpl.sockets.end()) {
+ channel->second->ready(false);
channel->second->stop();
pimpl.sockets.erase(channel);
}
@@ -1074,10 +1075,10 @@
}
void
-ChannelSocket::ready()
+ChannelSocket::ready(bool accepted)
{
if (pimpl_->readyCb_)
- pimpl_->readyCb_();
+ pimpl_->readyCb_(accepted);
}
void