mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
ZMQ: use random port for internal use
This commit is contained in:
parent
9d6f232dd1
commit
b96dfa602b
2 changed files with 5 additions and 6 deletions
|
@ -38,14 +38,13 @@ ZMQReader::ZMQReader(const std::string& address, uint32_t zmq_port, const std::s
|
|||
m_proxy.clear();
|
||||
}
|
||||
|
||||
for (uint32_t i = m_publisherPort; i < std::numeric_limits<uint16_t>::max(); ++i) {
|
||||
std::random_device rd;
|
||||
for (uint32_t port = 49152 + (rd() % 16384), i = 0; i < 100; ++i, port = (port < 65535) ? (port + 1) : 49152) {
|
||||
try {
|
||||
m_publisherPort = 0;
|
||||
|
||||
char addr[32];
|
||||
snprintf(addr, sizeof(addr), "tcp://127.0.0.1:%u", i);
|
||||
snprintf(addr, sizeof(addr), "tcp://127.0.0.1:%u", port);
|
||||
m_publisher.bind(addr);
|
||||
m_publisherPort = static_cast<uint16_t>(i);
|
||||
m_publisherPort = static_cast<uint16_t>(port);
|
||||
break;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
|
|
|
@ -45,7 +45,7 @@ private:
|
|||
zmq::context_t m_context{ 1 };
|
||||
zmq::socket_t m_publisher{ m_context, ZMQ_PUB };
|
||||
zmq::socket_t m_subscriber{ m_context, ZMQ_SUB };
|
||||
uint16_t m_publisherPort = 37891;
|
||||
uint16_t m_publisherPort = 0;
|
||||
std::atomic<bool> m_finished{ false };
|
||||
std::atomic<bool> m_threadRunning{ false };
|
||||
|
||||
|
|
Loading…
Reference in a new issue