Skip to content

Commit

Permalink
Fix ZMQ Notification initialization and shutdown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
João Barbosa committed Nov 4, 2015
1 parent 02a95be commit de0499d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ void Shutdown()
#if ENABLE_ZMQ
if (pzmqNotificationInterface) {
UnregisterValidationInterface(pzmqNotificationInterface);
pzmqNotificationInterface->Shutdown();
delete pzmqNotificationInterface;
pzmqNotificationInterface = NULL;
}
Expand Down Expand Up @@ -1176,7 +1175,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs);

if (pzmqNotificationInterface) {
pzmqNotificationInterface->Initialize();
RegisterValidationInterface(pzmqNotificationInterface);
}
#endif
Expand Down
11 changes: 8 additions & 3 deletions src/zmq/zmqnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(NULL)

CZMQNotificationInterface::~CZMQNotificationInterface()
{
// ensure Shutdown if Initialize is called
assert(!pcontext);
Shutdown();

for (std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin(); i!=notifiers.end(); ++i)
{
Expand Down Expand Up @@ -59,6 +58,12 @@ CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const
{
notificationInterface = new CZMQNotificationInterface();
notificationInterface->notifiers = notifiers;

if (!notificationInterface->Initialize())
{
delete notificationInterface;
notificationInterface = NULL;
}
}

return notificationInterface;
Expand Down Expand Up @@ -99,7 +104,7 @@ bool CZMQNotificationInterface::Initialize()
return false;
}

return false;
return true;
}

// Called during shutdown sequence
Expand Down
3 changes: 2 additions & 1 deletion src/zmq/zmqnotificationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class CZMQNotificationInterface : public CValidationInterface

static CZMQNotificationInterface* CreateWithArguments(const std::map<std::string, std::string> &args);

protected:
bool Initialize();
void Shutdown();

protected: // CValidationInterface
// CValidationInterface
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
void UpdatedBlockTip(const CBlockIndex *pindex);

Expand Down

0 comments on commit de0499d

Please sign in to comment.