ZMQReader: keep trying to connect on startup

pull/71/head
SChernykh 2021-10-21 00:22:53 +02:00
parent 9885f82e9e
commit 966b499e5c
2 changed files with 9 additions and 8 deletions

View File

@ -76,20 +76,22 @@ ZMQReader::~ZMQReader()
} }
} }
void ZMQReader::run_wrapper(void* arg)
{
reinterpret_cast<ZMQReader*>(arg)->run();
LOGINFO(1, "worker thread stopped");
}
void ZMQReader::run() void ZMQReader::run()
{ {
try { try {
char addr[32]; char addr[32];
snprintf(addr, sizeof(addr), "tcp://%s:%u", m_address, m_zmqPort); snprintf(addr, sizeof(addr), "tcp://%s:%u", m_address, m_zmqPort);
if (!connect(addr, m_zmqPort)) { while (!connect(addr, m_zmqPort)) { if (m_finished.load()) return; }
throw zmq::error_t();
}
snprintf(addr, sizeof(addr), "tcp://127.0.0.1:%u", m_publisherPort); snprintf(addr, sizeof(addr), "tcp://127.0.0.1:%u", m_publisherPort);
if (!connect(addr, m_publisherPort)) { while (!connect(addr, m_publisherPort)) { if (m_finished.load()) return; }
throw zmq::error_t();
}
m_subscriber.set(zmq::sockopt::subscribe, "json-full-chain_main"); m_subscriber.set(zmq::sockopt::subscribe, "json-full-chain_main");
m_subscriber.set(zmq::sockopt::subscribe, "json-full-miner_data"); m_subscriber.set(zmq::sockopt::subscribe, "json-full-miner_data");
@ -122,7 +124,6 @@ void ZMQReader::run()
LOGERR(1, "exception " << e.what() << ", aborting"); LOGERR(1, "exception " << e.what() << ", aborting");
panic(); panic();
} }
LOGINFO(1, "worker thread stopped");
} }
bool ZMQReader::connect(const char* address, uint32_t id) bool ZMQReader::connect(const char* address, uint32_t id)

View File

@ -28,7 +28,7 @@ public:
~ZMQReader(); ~ZMQReader();
private: private:
static void run_wrapper(void* arg) { reinterpret_cast<ZMQReader*>(arg)->run(); } static void run_wrapper(void* arg);
void run(); void run();
bool connect(const char* address, uint32_t id); bool connect(const char* address, uint32_t id);