From de0499d3b8352334357c8d60931cd5d2be5ab61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Sun, 1 Nov 2015 18:09:17 +0000 Subject: [PATCH] Fix ZMQ Notification initialization and shutdown Moves the call Initialize() from init.cpp to CreateWithArguments() and handles the return value. Moves the call Shutdown() from init.cpp to destructor. Changes Initialize() and Shutdown() to protected members. --- src/init.cpp | 2 -- src/zmq/zmqnotificationinterface.cpp | 11 ++++++++--- src/zmq/zmqnotificationinterface.h | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 76adca769..3e7381b82 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -222,7 +222,6 @@ void Shutdown() #if ENABLE_ZMQ if (pzmqNotificationInterface) { UnregisterValidationInterface(pzmqNotificationInterface); - pzmqNotificationInterface->Shutdown(); delete pzmqNotificationInterface; pzmqNotificationInterface = NULL; } @@ -1176,7 +1175,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs); if (pzmqNotificationInterface) { - pzmqNotificationInterface->Initialize(); RegisterValidationInterface(pzmqNotificationInterface); } #endif diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 388b86707..09fe3aeb4 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -21,8 +21,7 @@ CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(NULL) CZMQNotificationInterface::~CZMQNotificationInterface() { - // ensure Shutdown if Initialize is called - assert(!pcontext); + Shutdown(); for (std::list::iterator i=notifiers.begin(); i!=notifiers.end(); ++i) { @@ -59,6 +58,12 @@ CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const { notificationInterface = new CZMQNotificationInterface(); notificationInterface->notifiers = notifiers; + + if (!notificationInterface->Initialize()) + { + delete notificationInterface; + notificationInterface = NULL; + } } return notificationInterface; @@ -99,7 +104,7 @@ bool CZMQNotificationInterface::Initialize() return false; } - return false; + return true; } // Called during shutdown sequence diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index 8eea15c06..3ccfaf341 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -19,10 +19,11 @@ public: static CZMQNotificationInterface* CreateWithArguments(const std::map &args); +protected: bool Initialize(); void Shutdown(); -protected: // CValidationInterface + // CValidationInterface void SyncTransaction(const CTransaction &tx, const CBlock *pblock); void UpdatedBlockTip(const CBlockIndex *pindex);