1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Update ZMQ.hpp

This commit is contained in:
Sandu Liviu Catalin 2021-02-02 21:56:40 +02:00
parent 266e06e870
commit 3fb6005c3f

View File

@ -472,14 +472,14 @@ struct ZSkt : SqChainedInstances< ZSkt >
while (mStatus > 0) while (mStatus > 0)
{ {
using namespace std::chrono_literals; using namespace std::chrono_literals;
// Wait a bit before each iteration to not exhaust resources
std::this_thread::sleep_for(50ms);
// Acquire exclusive access to the socket // Acquire exclusive access to the socket
std::lock_guard< std::mutex > guard(mMtx); std::lock_guard< std::mutex > guard(mMtx);
// Perform tasks // Perform tasks until there's none left
Recv(); if (!Recv() && !Send() && !SendMore())
Send(); {
SendMore(); // Don't exhaust resources pointlessly
std::this_thread::sleep_for(50ms);
}
} }
} }
@ -557,7 +557,7 @@ protected:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Receive one message from the socket. * Receive one message from the socket.
*/ */
void Recv() bool Recv()
{ {
// Need someone to receive the message // Need someone to receive the message
ZMsg msg; ZMsg msg;
@ -566,8 +566,13 @@ protected:
// Did we have a message? // Did we have a message?
if (r >= 0) if (r >= 0)
{ {
mOutputQueue.enqueue(std::move(msg)); // Put it in the queue // Put it in the queue
mOutputQueue.enqueue(std::move(msg));
// We received a message
return true;
} }
// No message was retrieved
return false;
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------