From 84b08966eb755bdb3a3c96f622aa7e5267d4334c Mon Sep 17 00:00:00 2001 From: Tor Brede Vekterli Date: Wed, 22 Dec 2021 13:41:46 +0000 Subject: Minor cleanup of CommunicationManager code, no change in semantics --- storage/src/vespa/storage/common/storagelink.cpp | 45 ++++++++++++------------ 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'storage') diff --git a/storage/src/vespa/storage/common/storagelink.cpp b/storage/src/vespa/storage/common/storagelink.cpp index b94ef03fad5..fe753d9c350 100644 --- a/storage/src/vespa/storage/common/storagelink.cpp +++ b/storage/src/vespa/storage/common/storagelink.cpp @@ -9,8 +9,6 @@ #include LOG_SETUP(".application.link"); -using std::shared_ptr; -using std::ostringstream; using namespace storage::api; namespace storage { @@ -46,14 +44,16 @@ void StorageLink::open() assert(false); } link->_state = OPENED; - if (link->_down.get() == 0) break; + if (!link->_down) { + break; + } link = link->_down.get(); } // When give all links an onOpen call, bottoms up. Do it bottoms up, as // links are more likely to send messages down in their onOpen() call // than up. Thus, chances are best that the component is ready to // receive messages sent during onOpen(). - while (link != 0) { + while (link != nullptr) { link->onOpen(); link = link->_up; } @@ -64,7 +64,9 @@ void StorageLink::doneInit() StorageLink* link = this; while (true) { link->onDoneInit(); - if (link->_down.get() == 0) break; + if (!link->_down) { + break; + } link = link->_down.get(); } } @@ -79,7 +81,7 @@ void StorageLink::close() } void StorageLink::closeNextLink() { - _down.reset(0); + _down.reset(); } void StorageLink::flush() @@ -114,7 +116,7 @@ void StorageLink::flush() void StorageLink::sendDown(const StorageMessage::SP& msg) { - // Verify acceptable state to send messages down + // Verify acceptable state to send messages down switch(getState()) { case OPENED: case CLOSING: @@ -129,20 +131,20 @@ void StorageLink::sendDown(const StorageMessage::SP& msg) LOG(spam, "Storage Link %s to handle %s", toString().c_str(), msg->toString().c_str()); if (isBottom()) { LOG(spam, "Storage link %s at bottom of chain got message %s.", toString().c_str(), msg->toString().c_str()); - ostringstream ost; + std::ostringstream ost; ost << "Unhandled message at bottom of chain " << *msg << " (message type " << msg->getType().getName() << "). " << vespalib::getStackTrace(0); if (!msg->getType().isReply()) { LOGBP(warning, "%s", ost.str().c_str()); - StorageCommand& cmd = static_cast(*msg); - shared_ptr reply(cmd.makeReply().release()); + auto& cmd = dynamic_cast(*msg); + std::shared_ptr reply(cmd.makeReply()); - if (reply.get()) { + if (reply) { reply->setResult(ReturnCode(ReturnCode::NOT_IMPLEMENTED, msg->getType().getName())); sendUp(reply); } } else { - ost << " Return code: " << static_cast(*msg).getResult(); + ost << " Return code: " << dynamic_cast(*msg).getResult(); LOGBP(warning, "%s", ost.str().c_str()); } } else if (!_down->onDown(msg)) { @@ -153,7 +155,7 @@ void StorageLink::sendDown(const StorageMessage::SP& msg) } } -void StorageLink::sendUp(const shared_ptr & msg) +void StorageLink::sendUp(const std::shared_ptr & msg) { // Verify acceptable state to send messages up switch(getState()) { @@ -169,20 +171,20 @@ void StorageLink::sendUp(const shared_ptr & msg) } assert(msg); if (isTop()) { - ostringstream ost; + std::ostringstream ost; ost << "Unhandled message at top of chain " << *msg << "."; ost << vespalib::getStackTrace(0); if (!msg->getType().isReply()) { LOGBP(warning, "%s", ost.str().c_str()); - auto& cmd = static_cast(*msg); - shared_ptr reply(cmd.makeReply().release()); + auto& cmd = dynamic_cast(*msg); + std::shared_ptr reply(cmd.makeReply()); if (reply.get()) { reply->setResult(ReturnCode(ReturnCode::NOT_IMPLEMENTED, msg->getType().getName())); sendDown(reply); } } else { - ost << " Return code: " << static_cast(*msg).getResult(); + ost << " Return code: " << dynamic_cast(*msg).getResult(); LOGBP(warning, "%s", ost.str().c_str()); } } else if (!_up->onUp(msg)) { @@ -195,7 +197,7 @@ void StorageLink::printChain(std::ostream& out, std::string indent) const { if (!isTop()) out << ", not top"; out << ")"; const StorageLink* lastlink = _up; - for (const StorageLink* link = this; link != 0; link = link->_down.get()) { + for (const StorageLink* link = this; link != nullptr; link = link->_down.get()) { out << "\n"; link->print(out, false, indent + " "); if (link->_up != lastlink) out << ", broken linkage"; @@ -203,12 +205,12 @@ void StorageLink::printChain(std::ostream& out, std::string indent) const { } } -bool StorageLink::onDown(const shared_ptr & msg) +bool StorageLink::onDown(const std::shared_ptr & msg) { return msg->callHandler(*this, msg); } -bool StorageLink::onUp(const shared_ptr & msg) +bool StorageLink::onUp(const std::shared_ptr & msg) { return msg->callHandler(*this, msg); } @@ -236,8 +238,7 @@ StorageLink::stateToString(State state) case CLOSED: return "CLOSED"; default: - assert(false); - return 0; + abort(); } } -- cgit v1.2.3