diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp index fc104ed1b24ad0de4c0cd75c48b462cfddf185e0..03e4c6573771429f57fcb11c1b3062d44f22d365 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp @@ -329,7 +329,7 @@ public: std::map<DeviceId, PendingOperations> pendingOperations_ {}; - void executePendingOperations(const DeviceId& deviceId, const dht::Value::Id& vid, const std::shared_ptr<ChannelSocket>& sock) + void executePendingOperations(const DeviceId& deviceId, const dht::Value::Id& vid, const std::shared_ptr<ChannelSocket>& sock, bool accepted = true) { std::vector<PendingCb> ret; std::unique_lock<std::mutex> lk(connectCbsMtx_); @@ -351,7 +351,8 @@ public: } else if (auto n = pendingOperations.connecting.extract(vid)) { ret.emplace_back(std::move(n.mapped())); // If sock is nullptr, execute if it's the last connecting operation - if (!sock && pendingOperations.connecting.empty()) { + // If accepted is false, it means that underlying socket is ok, but channel is declined + if (!sock && pendingOperations.connecting.empty() && accepted) { for (auto& [vid, cb] : pendingOperations.waiting) ret.emplace_back(std::move(cb)); pendingOperations.waiting.clear(); @@ -799,11 +800,11 @@ ConnectionManager::Impl::sendChannelRequest(std::shared_ptr<MultiplexedSocket>& shared->executePendingOperations(deviceId, vid, nullptr); }); channelSock->onReady( - [wSock = std::weak_ptr<ChannelSocket>(channelSock), name, deviceId, vid, w = weak()]() { + [wSock = std::weak_ptr<ChannelSocket>(channelSock), name, deviceId, vid, w = weak()](bool accepted) { auto shared = w.lock(); auto channelSock = wSock.lock(); if (shared) - shared->executePendingOperations(deviceId, vid, channelSock); + shared->executePendingOperations(deviceId, vid, accepted ? channelSock : nullptr, accepted); }); ChannelRequest val;