From a3ffbd2a9b77aad0e08d93e795e7c51be07b0474 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 2 Mar 2020 09:11:44 -0800 Subject: [PATCH] client fix Channel reconnect --- src/client.cpp | 11 +++++++++++ src/clientconn.cpp | 19 ++++++++++++++----- src/clientimpl.h | 7 ++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 4b22858..6f3112c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -94,6 +94,17 @@ void Channel::createOperations() } } +void Channel::disconnect(const std::shared_ptr& self) +{ + self->state = Channel::Searching; + self->sid = 0xdeadbeef; // spoil + context->searchBuckets[context->currentBucket].push_back(self); + + log_debug_printf(io, "Server %s detach channel '%s' to re-search\n", + conn ? conn->peerName.c_str() : "", + self->name.c_str()); + +} OperationBase::OperationBase(operation_t op, const std::shared_ptr& chan) :Operation(op) diff --git a/src/clientconn.cpp b/src/clientconn.cpp index 8ad224a..a588b9e 100644 --- a/src/clientconn.cpp +++ b/src/clientconn.cpp @@ -128,12 +128,21 @@ void Connection::cleanup() if(!chan) continue; - chan->state = Channel::Searching; - chan->sid = 0xdeadbeef; // spoil - self = std::move(chan->conn); - context->searchBuckets[context->currentBucket].push_back(chan); + chan->disconnect(chan); + } + for(auto& pair : chanBySID) { + auto chan = pair.second.lock(); + if(!chan) + continue; - log_debug_printf(io, "Server %s detach channel '%s' to re-search\n", peerName.c_str(), chan->name.c_str()); + chan->disconnect(chan); + } + for(auto& pair : creatingByCID) { + auto chan = pair.second.lock(); + if(!chan) + continue; + + chan->disconnect(chan); } auto ops = std::move(opByIOID); diff --git a/src/clientimpl.h b/src/clientimpl.h index 6bb0e1a..36fe437 100644 --- a/src/clientimpl.h +++ b/src/clientimpl.h @@ -53,11 +53,11 @@ struct Connection : public ConnBase, public std::enable_shared_from_this> pending; - std::map> creatingByCID, - chanBySID; + std::map> creatingByCID, // in state==Creating + chanBySID; // in state==Active // entries always have matching entry in a Channel::opByIOID std::map opByIOID; @@ -130,6 +130,7 @@ struct Channel { ~Channel(); void createOperations(); + void disconnect(const std::shared_ptr& self); static std::shared_ptr build(const std::shared_ptr& context, const std::string &name);