Skip to content

Commit de0499d

Browse files
author
João Barbosa
committed
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.
1 parent 02a95be commit de0499d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/init.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ void Shutdown()
222222
#if ENABLE_ZMQ
223223
if (pzmqNotificationInterface) {
224224
UnregisterValidationInterface(pzmqNotificationInterface);
225-
pzmqNotificationInterface->Shutdown();
226225
delete pzmqNotificationInterface;
227226
pzmqNotificationInterface = NULL;
228227
}
@@ -1176,7 +1175,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
11761175
pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs);
11771176

11781177
if (pzmqNotificationInterface) {
1179-
pzmqNotificationInterface->Initialize();
11801178
RegisterValidationInterface(pzmqNotificationInterface);
11811179
}
11821180
#endif

src/zmq/zmqnotificationinterface.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(NULL)
2121

2222
CZMQNotificationInterface::~CZMQNotificationInterface()
2323
{
24-
// ensure Shutdown if Initialize is called
25-
assert(!pcontext);
24+
Shutdown();
2625

2726
for (std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin(); i!=notifiers.end(); ++i)
2827
{
@@ -59,6 +58,12 @@ CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const
5958
{
6059
notificationInterface = new CZMQNotificationInterface();
6160
notificationInterface->notifiers = notifiers;
61+
62+
if (!notificationInterface->Initialize())
63+
{
64+
delete notificationInterface;
65+
notificationInterface = NULL;
66+
}
6267
}
6368

6469
return notificationInterface;
@@ -99,7 +104,7 @@ bool CZMQNotificationInterface::Initialize()
99104
return false;
100105
}
101106

102-
return false;
107+
return true;
103108
}
104109

105110
// Called during shutdown sequence

src/zmq/zmqnotificationinterface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class CZMQNotificationInterface : public CValidationInterface
1919

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

22+
protected:
2223
bool Initialize();
2324
void Shutdown();
2425

25-
protected: // CValidationInterface
26+
// CValidationInterface
2627
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
2728
void UpdatedBlockTip(const CBlockIndex *pindex);
2829

0 commit comments

Comments
 (0)