mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Deprecate Send-/ReceiveAsync, use timeout variant instead
This commit is contained in:
parent
c40bd7d6a9
commit
0cfa9192d7
|
@ -689,77 +689,52 @@ void FairMQChannel::ResetChannel()
|
||||||
// TODO: implement channel resetting
|
// TODO: implement channel resetting
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::Send(unique_ptr<FairMQMessage>& msg) const
|
|
||||||
{
|
|
||||||
CheckSendCompatibility(msg);
|
|
||||||
return fSocket->Send(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Receive(unique_ptr<FairMQMessage>& msg) const
|
|
||||||
{
|
|
||||||
CheckReceiveCompatibility(msg);
|
|
||||||
return fSocket->Receive(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Send(unique_ptr<FairMQMessage>& msg, int sndTimeoutInMs) const
|
int FairMQChannel::Send(unique_ptr<FairMQMessage>& msg, int sndTimeoutInMs) const
|
||||||
{
|
{
|
||||||
|
CheckSendCompatibility(msg);
|
||||||
return fSocket->Send(msg, sndTimeoutInMs);
|
return fSocket->Send(msg, sndTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::Receive(unique_ptr<FairMQMessage>& msg, int rcvTimeoutInMs) const
|
int FairMQChannel::Receive(unique_ptr<FairMQMessage>& msg, int rcvTimeoutInMs) const
|
||||||
{
|
{
|
||||||
|
CheckReceiveCompatibility(msg);
|
||||||
return fSocket->Receive(msg, rcvTimeoutInMs);
|
return fSocket->Receive(msg, rcvTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::SendAsync(unique_ptr<FairMQMessage>& msg) const
|
int FairMQChannel::SendAsync(unique_ptr<FairMQMessage>& msg) const
|
||||||
{
|
{
|
||||||
CheckSendCompatibility(msg);
|
CheckSendCompatibility(msg);
|
||||||
return fSocket->TrySend(msg);
|
return fSocket->Send(msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::ReceiveAsync(unique_ptr<FairMQMessage>& msg) const
|
int FairMQChannel::ReceiveAsync(unique_ptr<FairMQMessage>& msg) const
|
||||||
{
|
{
|
||||||
CheckReceiveCompatibility(msg);
|
CheckReceiveCompatibility(msg);
|
||||||
return fSocket->TryReceive(msg);
|
return fSocket->Receive(msg, 0);
|
||||||
}
|
|
||||||
|
|
||||||
int64_t FairMQChannel::Send(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
|
||||||
{
|
|
||||||
CheckSendCompatibility(msgVec);
|
|
||||||
return fSocket->Send(msgVec);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t FairMQChannel::Receive(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
|
||||||
{
|
|
||||||
CheckReceiveCompatibility(msgVec);
|
|
||||||
return fSocket->Receive(msgVec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQChannel::Send(vector<unique_ptr<FairMQMessage>>& msgVec, int sndTimeoutInMs) const
|
int64_t FairMQChannel::Send(vector<unique_ptr<FairMQMessage>>& msgVec, int sndTimeoutInMs) const
|
||||||
{
|
{
|
||||||
|
CheckSendCompatibility(msgVec);
|
||||||
return fSocket->Send(msgVec, sndTimeoutInMs);
|
return fSocket->Send(msgVec, sndTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQChannel::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, int rcvTimeoutInMs) const
|
int64_t FairMQChannel::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, int rcvTimeoutInMs) const
|
||||||
{
|
{
|
||||||
|
CheckReceiveCompatibility(msgVec);
|
||||||
return fSocket->Receive(msgVec, rcvTimeoutInMs);
|
return fSocket->Receive(msgVec, rcvTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQChannel::SendAsync(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
int64_t FairMQChannel::SendAsync(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
||||||
{
|
{
|
||||||
CheckSendCompatibility(msgVec);
|
CheckSendCompatibility(msgVec);
|
||||||
return fSocket->TrySend(msgVec);
|
return fSocket->Send(msgVec, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receives a vector of messages in non-blocking mode.
|
|
||||||
///
|
|
||||||
/// @param msgVec message vector reference
|
|
||||||
/// @return Number of bytes that have been received. If queue is empty, returns -2.
|
|
||||||
/// In case of errors, returns -1.
|
|
||||||
int64_t FairMQChannel::ReceiveAsync(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
int64_t FairMQChannel::ReceiveAsync(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
||||||
{
|
{
|
||||||
CheckReceiveCompatibility(msgVec);
|
CheckReceiveCompatibility(msgVec);
|
||||||
return fSocket->TryReceive(msgVec);
|
return fSocket->Receive(msgVec, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FairMQChannel::~FairMQChannel()
|
FairMQChannel::~FairMQChannel()
|
||||||
|
|
|
@ -174,106 +174,62 @@ class FairMQChannel
|
||||||
/// Resets the channel (requires validation to be used again).
|
/// Resets the channel (requires validation to be used again).
|
||||||
void ResetChannel();
|
void ResetChannel();
|
||||||
|
|
||||||
int Send(FairMQMessagePtr& msg) const;
|
|
||||||
int Receive(FairMQMessagePtr& msg) const;
|
|
||||||
|
|
||||||
/// Sends a message to the socket queue.
|
/// Sends a message to the socket queue.
|
||||||
/// @details Send method attempts to send a message by
|
|
||||||
/// putting it in the output queue. If the queue is full or queueing is not possible
|
|
||||||
/// for some other reason (e.g. no peers connected for a binding socket), the method blocks.
|
|
||||||
///
|
|
||||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||||
int Send(FairMQMessagePtr& msg, int sndTimeoutInMs) const;
|
int Send(FairMQMessagePtr& msg, int sndTimeoutInMs = -1) const;
|
||||||
|
|
||||||
/// Receives a message from the socket queue.
|
/// Receives a message from the socket queue.
|
||||||
/// @details Receive method attempts to receive a message from the input queue.
|
|
||||||
/// If the queue is empty the method blocks.
|
|
||||||
///
|
|
||||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||||
int Receive(FairMQMessagePtr& msg, int rcvTimeoutInMs) const;
|
int Receive(FairMQMessagePtr& msg, int rcvTimeoutInMs = -1) const;
|
||||||
|
|
||||||
/// Sends a message in non-blocking mode.
|
int SendAsync(FairMQMessagePtr& msg) const __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msg, timeout);")));
|
||||||
/// @details SendAsync method attempts to send a message without blocking by
|
int ReceiveAsync(FairMQMessagePtr& msg) const __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msg, timeout);")));
|
||||||
/// putting it in the queue.
|
|
||||||
///
|
|
||||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
|
||||||
/// @return Number of bytes that have been queued. If queueing failed due to
|
|
||||||
/// full queue or no connected peers (when binding), returns -2.
|
|
||||||
/// In case of errors, returns -1.
|
|
||||||
int SendAsync(FairMQMessagePtr& msg) const;
|
|
||||||
|
|
||||||
/// Receives a message in non-blocking mode.
|
|
||||||
///
|
|
||||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
|
||||||
/// @return Number of bytes that have been received. If queue is empty, returns -2.
|
|
||||||
/// In case of errors, returns -1.
|
|
||||||
int ReceiveAsync(FairMQMessagePtr& msg) const;
|
|
||||||
|
|
||||||
int64_t Send(std::vector<FairMQMessagePtr>& msgVec) const;
|
|
||||||
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec) const;
|
|
||||||
|
|
||||||
/// Send a vector of messages
|
/// Send a vector of messages
|
||||||
///
|
|
||||||
/// @param msgVec message vector reference
|
/// @param msgVec message vector reference
|
||||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||||
int64_t Send(std::vector<FairMQMessagePtr>& msgVec, int sndTimeoutInMs) const;
|
int64_t Send(std::vector<FairMQMessagePtr>& msgVec, int sndTimeoutInMs = -1) const;
|
||||||
|
|
||||||
/// Receive a vector of messages
|
/// Receive a vector of messages
|
||||||
///
|
|
||||||
/// @param msgVec message vector reference
|
/// @param msgVec message vector reference
|
||||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||||
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec, int rcvTimeoutInMs) const;
|
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec, int rcvTimeoutInMs = -1) const;
|
||||||
|
|
||||||
/// Sends a vector of message in non-blocking mode.
|
int64_t SendAsync(std::vector<FairMQMessagePtr>& msgVec) const __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msgVec, timeout);")));
|
||||||
/// @details SendAsync method attempts to send a vector of messages without blocking by
|
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) const __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msgVec, timeout);")));
|
||||||
/// putting it them the queue.
|
|
||||||
///
|
|
||||||
/// @param msgVec message vector reference
|
|
||||||
/// @return Number of bytes that have been queued. If queueing failed due to
|
|
||||||
/// full queue or no connected peers (when binding), returns -2. In case of errors, returns -1.
|
|
||||||
int64_t SendAsync(std::vector<FairMQMessagePtr>& msgVec) const;
|
|
||||||
|
|
||||||
/// Receives a vector of messages in non-blocking mode.
|
/// Send FairMQParts
|
||||||
///
|
/// @param parts FairMQParts reference
|
||||||
/// @param msgVec message vector reference
|
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||||
/// @return Number of bytes that have been received. If queue is empty, returns -2.
|
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||||
/// In case of errors, returns -1.
|
int64_t Send(FairMQParts& parts, int sndTimeoutInMs = -1) const
|
||||||
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) const;
|
|
||||||
|
|
||||||
int64_t Send(FairMQParts& parts) const
|
|
||||||
{
|
|
||||||
return Send(parts.fParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Receive(FairMQParts& parts) const
|
|
||||||
{
|
|
||||||
return Receive(parts.fParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Send(FairMQParts& parts, int sndTimeoutInMs) const
|
|
||||||
{
|
{
|
||||||
return Send(parts.fParts, sndTimeoutInMs);
|
return Send(parts.fParts, sndTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Receive(FairMQParts& parts, int rcvTimeoutInMs) const
|
/// Receive FairMQParts
|
||||||
|
/// @param parts FairMQParts reference
|
||||||
|
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||||
|
/// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||||
|
int64_t Receive(FairMQParts& parts, int rcvTimeoutInMs = -1) const
|
||||||
{
|
{
|
||||||
return Receive(parts.fParts, rcvTimeoutInMs);
|
return Receive(parts.fParts, rcvTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SendAsync(FairMQParts& parts) const
|
int64_t SendAsync(FairMQParts& parts) const __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(parts, timeout);")))
|
||||||
{
|
{
|
||||||
return SendAsync(parts.fParts);
|
return Send(parts.fParts, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t ReceiveAsync(FairMQParts& parts) const
|
int64_t ReceiveAsync(FairMQParts& parts) const __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(parts, timeout);")))
|
||||||
{
|
{
|
||||||
return ReceiveAsync(parts.fParts);
|
return Receive(parts.fParts, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long GetBytesTx() const;
|
unsigned long GetBytesTx() const;
|
||||||
|
|
|
@ -96,23 +96,13 @@ class FairMQDevice : public FairMQStateMachine
|
||||||
Deserializer().Deserialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
|
Deserializer().Deserialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Send(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
|
||||||
return fChannels.at(chan).at(i).Send(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Receive(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
|
||||||
return fChannels.at(chan).at(i).Receive(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Shorthand method to send `msg` on `chan` at index `i`
|
/// Shorthand method to send `msg` on `chan` at index `i`
|
||||||
/// @param msg message reference
|
/// @param msg message reference
|
||||||
/// @param chan channel name
|
/// @param chan channel name
|
||||||
/// @param i channel index
|
/// @param i channel index
|
||||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
/// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||||
int Send(FairMQMessagePtr& msg, const std::string& chan, const int i, int sndTimeoutInMs) const
|
int Send(FairMQMessagePtr& msg, const std::string& chan, const int i = 0, int sndTimeoutInMs = -1) const
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).Send(msg, sndTimeoutInMs);
|
return fChannels.at(chan).at(i).Send(msg, sndTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
@ -121,52 +111,29 @@ class FairMQDevice : public FairMQStateMachine
|
||||||
/// @param msg message reference
|
/// @param msg message reference
|
||||||
/// @param chan channel name
|
/// @param chan channel name
|
||||||
/// @param i channel index
|
/// @param i channel index
|
||||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
/// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||||
int Receive(FairMQMessagePtr& msg, const std::string& chan, const int i, int rcvTimeoutInMs) const
|
int Receive(FairMQMessagePtr& msg, const std::string& chan, const int i = 0, int rcvTimeoutInMs = -1) const
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).Receive(msg, rcvTimeoutInMs);
|
return fChannels.at(chan).at(i).Receive(msg, rcvTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shorthand method to send `msg` on `chan` at index `i` without blocking
|
int SendAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msg, \"channelA\", subchannelIndex, timeout);")))
|
||||||
/// @param msg message reference
|
|
||||||
/// @param chan channel name
|
|
||||||
/// @param i channel index
|
|
||||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
|
||||||
/// In case of errors, returns -1.
|
|
||||||
int SendAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).SendAsync(msg);
|
return fChannels.at(chan).at(i).Send(msg, 0);
|
||||||
}
|
}
|
||||||
|
int ReceiveAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msg, \"channelA\", subchannelIndex, timeout);")))
|
||||||
/// Shorthand method to receive `msg` on `chan` at index `i` without blocking
|
|
||||||
/// @param msg message reference
|
|
||||||
/// @param chan channel name
|
|
||||||
/// @param i channel index
|
|
||||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
|
||||||
/// In case of errors, returns -1.
|
|
||||||
int ReceiveAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).ReceiveAsync(msg);
|
return fChannels.at(chan).at(i).Receive(msg, 0);
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Send(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
|
||||||
return fChannels.at(chan).at(i).Send(parts.fParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Receive(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
|
||||||
return fChannels.at(chan).at(i).Receive(parts.fParts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shorthand method to send FairMQParts on `chan` at index `i`
|
/// Shorthand method to send FairMQParts on `chan` at index `i`
|
||||||
/// @param parts parts reference
|
/// @param parts parts reference
|
||||||
/// @param chan channel name
|
/// @param chan channel name
|
||||||
/// @param i channel index
|
/// @param i channel index
|
||||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
/// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||||
int64_t Send(FairMQParts& parts, const std::string& chan, const int i, int sndTimeoutInMs) const
|
int64_t Send(FairMQParts& parts, const std::string& chan, const int i = 0, int sndTimeoutInMs = -1) const
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).Send(parts.fParts, sndTimeoutInMs);
|
return fChannels.at(chan).at(i).Send(parts.fParts, sndTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
@ -175,33 +142,20 @@ class FairMQDevice : public FairMQStateMachine
|
||||||
/// @param parts parts reference
|
/// @param parts parts reference
|
||||||
/// @param chan channel name
|
/// @param chan channel name
|
||||||
/// @param i channel index
|
/// @param i channel index
|
||||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
/// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||||
/// In case of errors, returns -1.
|
/// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||||
int64_t Receive(FairMQParts& parts, const std::string& chan, const int i, int rcvTimeoutInMs) const
|
int64_t Receive(FairMQParts& parts, const std::string& chan, const int i = 0, int rcvTimeoutInMs = -1) const
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).Receive(parts.fParts, rcvTimeoutInMs);
|
return fChannels.at(chan).at(i).Receive(parts.fParts, rcvTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shorthand method to send FairMQParts on `chan` at index `i` without blocking
|
int64_t SendAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(parts, \"channelA\", subchannelIndex, timeout);")))
|
||||||
/// @param parts parts reference
|
|
||||||
/// @param chan channel name
|
|
||||||
/// @param i channel index
|
|
||||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
|
||||||
/// In case of errors, returns -1.
|
|
||||||
int64_t SendAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).SendAsync(parts.fParts);
|
return fChannels.at(chan).at(i).Send(parts.fParts, 0);
|
||||||
}
|
}
|
||||||
|
int64_t ReceiveAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(parts, \"channelA\", subchannelIndex, timeout);")))
|
||||||
/// Shorthand method to receive FairMQParts on `chan` at index `i` without blocking
|
|
||||||
/// @param parts parts reference
|
|
||||||
/// @param chan channel name
|
|
||||||
/// @param i channel index
|
|
||||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
|
||||||
/// In case of errors, returns -1.
|
|
||||||
int64_t ReceiveAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
|
||||||
{
|
{
|
||||||
return fChannels.at(chan).at(i).ReceiveAsync(parts.fParts);
|
return fChannels.at(chan).at(i).Receive(parts.fParts, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Getter for default transport factory
|
/// @brief Getter for default transport factory
|
||||||
|
|
|
@ -25,15 +25,10 @@ class FairMQSocket
|
||||||
virtual bool Bind(const std::string& address) = 0;
|
virtual bool Bind(const std::string& address) = 0;
|
||||||
virtual void Connect(const std::string& address) = 0;
|
virtual void Connect(const std::string& address) = 0;
|
||||||
|
|
||||||
virtual int Send(FairMQMessagePtr& msg, int timeout = 0) = 0;
|
virtual int Send(FairMQMessagePtr& msg, int timeout = -1) = 0;
|
||||||
virtual int Receive(FairMQMessagePtr& msg, int timeout = 0) = 0;
|
virtual int Receive(FairMQMessagePtr& msg, int timeout = -1) = 0;
|
||||||
virtual int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = 0) = 0;
|
virtual int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = -1) = 0;
|
||||||
virtual int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = 0) = 0;
|
virtual int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = -1) = 0;
|
||||||
|
|
||||||
virtual int TrySend(FairMQMessagePtr& msg) = 0;
|
|
||||||
virtual int TryReceive(FairMQMessagePtr& msg) = 0;
|
|
||||||
virtual int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) = 0;
|
|
||||||
virtual int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) = 0;
|
|
||||||
|
|
||||||
virtual void Close() = 0;
|
virtual void Close() = 0;
|
||||||
|
|
||||||
|
|
|
@ -119,18 +119,13 @@ void FairMQSocketNN::Connect(const string& address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQSocketNN::Send(FairMQMessagePtr& msg, const int timeout) { return SendImpl(msg, 0, timeout); }
|
int FairMQSocketNN::Send(FairMQMessagePtr& msg, const int timeout)
|
||||||
int FairMQSocketNN::Receive(FairMQMessagePtr& msg, const int timeout) { return ReceiveImpl(msg, 0, timeout); }
|
|
||||||
int64_t FairMQSocketNN::Send(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return SendImpl(msgVec, 0, timeout); }
|
|
||||||
int64_t FairMQSocketNN::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return ReceiveImpl(msgVec, 0, timeout); }
|
|
||||||
|
|
||||||
int FairMQSocketNN::TrySend(FairMQMessagePtr& msg) { return SendImpl(msg, NN_DONTWAIT, 0); }
|
|
||||||
int FairMQSocketNN::TryReceive(FairMQMessagePtr& msg) { return ReceiveImpl(msg, NN_DONTWAIT, 0); }
|
|
||||||
int64_t FairMQSocketNN::TrySend(vector<unique_ptr<FairMQMessage>>& msgVec) { return SendImpl(msgVec, NN_DONTWAIT, 0); }
|
|
||||||
int64_t FairMQSocketNN::TryReceive(vector<unique_ptr<FairMQMessage>>& msgVec) { return ReceiveImpl(msgVec, NN_DONTWAIT, 0); }
|
|
||||||
|
|
||||||
int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = NN_DONTWAIT;
|
||||||
|
}
|
||||||
int nbytes = -1;
|
int nbytes = -1;
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
|
@ -162,7 +157,7 @@ int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int t
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fSndTimeout;
|
elapsed += fSndTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -194,8 +189,13 @@ int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
int FairMQSocketNN::Receive(FairMQMessagePtr& msg, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = NN_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
FairMQMessageNN* msgPtr = static_cast<FairMQMessageNN*>(msg.get());
|
FairMQMessageNN* msgPtr = static_cast<FairMQMessageNN*>(msg.get());
|
||||||
|
@ -216,7 +216,7 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fRcvTimeout;
|
elapsed += fRcvTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -248,8 +248,13 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
int64_t FairMQSocketNN::Send(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = NN_DONTWAIT;
|
||||||
|
}
|
||||||
const unsigned int vecSize = msgVec.size();
|
const unsigned int vecSize = msgVec.size();
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
|
@ -286,7 +291,7 @@ int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fla
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fSndTimeout;
|
elapsed += fSndTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -318,8 +323,13 @@ int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fla
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQSocketNN::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
int64_t FairMQSocketNN::Receive(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = NN_DONTWAIT;
|
||||||
|
}
|
||||||
// Warn if the vector is filled before Receive() and empty it.
|
// Warn if the vector is filled before Receive() and empty it.
|
||||||
// if (msgVec.size() > 0)
|
// if (msgVec.size() > 0)
|
||||||
// {
|
// {
|
||||||
|
@ -369,7 +379,7 @@ int64_t FairMQSocketNN::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fRcvTimeout;
|
elapsed += fRcvTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
|
|
@ -27,15 +27,10 @@ class FairMQSocketNN final : public FairMQSocket
|
||||||
bool Bind(const std::string& address) override;
|
bool Bind(const std::string& address) override;
|
||||||
void Connect(const std::string& address) override;
|
void Connect(const std::string& address) override;
|
||||||
|
|
||||||
int Send(FairMQMessagePtr& msg, const int timeout = 0) override;
|
int Send(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||||
int Receive(FairMQMessagePtr& msg, const int timeout = 0) override;
|
int Receive(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||||
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||||
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||||
|
|
||||||
int TrySend(FairMQMessagePtr& msg) override;
|
|
||||||
int TryReceive(FairMQMessagePtr& msg) override;
|
|
||||||
int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
|
||||||
int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
|
||||||
|
|
||||||
int GetSocket() const;
|
int GetSocket() const;
|
||||||
|
|
||||||
|
@ -80,11 +75,6 @@ class FairMQSocketNN final : public FairMQSocket
|
||||||
int fSndTimeout;
|
int fSndTimeout;
|
||||||
int fRcvTimeout;
|
int fRcvTimeout;
|
||||||
int fLinger;
|
int fLinger;
|
||||||
|
|
||||||
int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
|
||||||
int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
|
||||||
int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
|
||||||
int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FAIRMQSOCKETNN_H_ */
|
#endif /* FAIRMQSOCKETNN_H_ */
|
||||||
|
|
|
@ -111,18 +111,13 @@ void FairMQSocketSHM::Connect(const string& address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQSocketSHM::Send(FairMQMessagePtr& msg, const int timeout) { return SendImpl(msg, 0, timeout); }
|
int FairMQSocketSHM::Send(FairMQMessagePtr& msg, const int timeout)
|
||||||
int FairMQSocketSHM::Receive(FairMQMessagePtr& msg, const int timeout) { return ReceiveImpl(msg, 0, timeout); }
|
|
||||||
int64_t FairMQSocketSHM::Send(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return SendImpl(msgVec, 0, timeout); }
|
|
||||||
int64_t FairMQSocketSHM::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return ReceiveImpl(msgVec, 0, timeout); }
|
|
||||||
|
|
||||||
int FairMQSocketSHM::TrySend(FairMQMessagePtr& msg) { return SendImpl(msg, ZMQ_DONTWAIT, 0); }
|
|
||||||
int FairMQSocketSHM::TryReceive(FairMQMessagePtr& msg) { return ReceiveImpl(msg, ZMQ_DONTWAIT, 0); }
|
|
||||||
int64_t FairMQSocketSHM::TrySend(vector<unique_ptr<FairMQMessage>>& msgVec) { return SendImpl(msgVec, ZMQ_DONTWAIT, 0); }
|
|
||||||
int64_t FairMQSocketSHM::TryReceive(vector<unique_ptr<FairMQMessage>>& msgVec) { return ReceiveImpl(msgVec, ZMQ_DONTWAIT, 0); }
|
|
||||||
|
|
||||||
int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
while (true && !fInterrupted)
|
while (true && !fInterrupted)
|
||||||
|
@ -146,7 +141,7 @@ int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fSndTimeout;
|
elapsed += fSndTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -176,8 +171,13 @@ int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
int FairMQSocketSHM::Receive(FairMQMessagePtr& msg, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
zmq_msg_t* msgPtr = static_cast<FairMQMessageSHM*>(msg.get())->GetMessage();
|
zmq_msg_t* msgPtr = static_cast<FairMQMessageSHM*>(msg.get())->GetMessage();
|
||||||
|
@ -218,7 +218,7 @@ int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fRcvTimeout;
|
elapsed += fRcvTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -246,13 +246,18 @@ int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
int64_t FairMQSocketSHM::Send(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
const unsigned int vecSize = msgVec.size();
|
const unsigned int vecSize = msgVec.size();
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
if (vecSize == 1) {
|
if (vecSize == 1) {
|
||||||
return SendImpl(msgVec.back(), flags, timeout);
|
return Send(msgVec.back(), timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// put it into zmq message
|
// put it into zmq message
|
||||||
|
@ -299,7 +304,7 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fSndTimeout;
|
elapsed += fSndTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -334,8 +339,13 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQSocketSHM::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
int64_t FairMQSocketSHM::Receive(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
zmq_msg_t zmqMsg;
|
zmq_msg_t zmqMsg;
|
||||||
|
@ -392,7 +402,7 @@ int64_t FairMQSocketSHM::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fRcvTimeout;
|
elapsed += fRcvTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
|
|
@ -28,15 +28,10 @@ class FairMQSocketSHM final : public FairMQSocket
|
||||||
bool Bind(const std::string& address) override;
|
bool Bind(const std::string& address) override;
|
||||||
void Connect(const std::string& address) override;
|
void Connect(const std::string& address) override;
|
||||||
|
|
||||||
int Send(FairMQMessagePtr& msg, const int timeout = 0) override;
|
int Send(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||||
int Receive(FairMQMessagePtr& msg, const int timeout = 0) override;
|
int Receive(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||||
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||||
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||||
|
|
||||||
int TrySend(FairMQMessagePtr& msg) override;
|
|
||||||
int TryReceive(FairMQMessagePtr& msg) override;
|
|
||||||
int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
|
||||||
int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
|
||||||
|
|
||||||
void* GetSocket() const;
|
void* GetSocket() const;
|
||||||
|
|
||||||
|
@ -81,12 +76,6 @@ class FairMQSocketSHM final : public FairMQSocket
|
||||||
|
|
||||||
int fSndTimeout;
|
int fSndTimeout;
|
||||||
int fRcvTimeout;
|
int fRcvTimeout;
|
||||||
|
|
||||||
int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
|
||||||
int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
|
||||||
|
|
||||||
int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
|
||||||
int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FAIRMQSOCKETSHM_H_ */
|
#endif /* FAIRMQSOCKETSHM_H_ */
|
||||||
|
|
|
@ -106,18 +106,13 @@ void FairMQSocketZMQ::Connect(const string& address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQSocketZMQ::Send(FairMQMessagePtr& msg, const int timeout) { return SendImpl(msg, 0, timeout); }
|
int FairMQSocketZMQ::Send(FairMQMessagePtr& msg, const int timeout)
|
||||||
int FairMQSocketZMQ::Receive(FairMQMessagePtr& msg, const int timeout) { return ReceiveImpl(msg, 0, timeout); }
|
|
||||||
int64_t FairMQSocketZMQ::Send(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return SendImpl(msgVec, 0, timeout); }
|
|
||||||
int64_t FairMQSocketZMQ::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return ReceiveImpl(msgVec, 0, timeout); }
|
|
||||||
|
|
||||||
int FairMQSocketZMQ::TrySend(FairMQMessagePtr& msg) { return SendImpl(msg, ZMQ_DONTWAIT, 0); }
|
|
||||||
int FairMQSocketZMQ::TryReceive(FairMQMessagePtr& msg) { return ReceiveImpl(msg, ZMQ_DONTWAIT, 0); }
|
|
||||||
int64_t FairMQSocketZMQ::TrySend(vector<unique_ptr<FairMQMessage>>& msgVec) { return SendImpl(msgVec, ZMQ_DONTWAIT, 0); }
|
|
||||||
int64_t FairMQSocketZMQ::TryReceive(vector<unique_ptr<FairMQMessage>>& msgVec) { return ReceiveImpl(msgVec, ZMQ_DONTWAIT, 0); }
|
|
||||||
|
|
||||||
int FairMQSocketZMQ::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
static_cast<FairMQMessageZMQ*>(msg.get())->ApplyUsedSize();
|
static_cast<FairMQMessageZMQ*>(msg.get())->ApplyUsedSize();
|
||||||
|
@ -136,7 +131,7 @@ int FairMQSocketZMQ::SendImpl(FairMQMessagePtr& msg, const int flags, const int
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fSndTimeout;
|
elapsed += fSndTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -164,8 +159,13 @@ int FairMQSocketZMQ::SendImpl(FairMQMessagePtr& msg, const int flags, const int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQSocketZMQ::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
int FairMQSocketZMQ::Receive(FairMQMessagePtr& msg, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -181,7 +181,7 @@ int FairMQSocketZMQ::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fRcvTimeout;
|
elapsed += fRcvTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -209,14 +209,21 @@ int FairMQSocketZMQ::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
int64_t FairMQSocketZMQ::Send(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
|
|
||||||
const unsigned int vecSize = msgVec.size();
|
const unsigned int vecSize = msgVec.size();
|
||||||
|
|
||||||
// Sending vector typicaly handles more then one part
|
// Sending vector typicaly handles more then one part
|
||||||
if (vecSize > 1)
|
if (vecSize > 1)
|
||||||
{
|
{
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int64_t totalSize = 0;
|
int64_t totalSize = 0;
|
||||||
|
@ -240,7 +247,7 @@ int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fSndTimeout;
|
elapsed += fSndTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
@ -279,7 +286,7 @@ int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
||||||
} // If there's only one part, send it as a regular message
|
} // If there's only one part, send it as a regular message
|
||||||
else if (vecSize == 1)
|
else if (vecSize == 1)
|
||||||
{
|
{
|
||||||
return SendImpl(msgVec.back(), flags, timeout);
|
return Send(msgVec.back(), timeout);
|
||||||
}
|
}
|
||||||
else // if the vector is empty, something might be wrong
|
else // if the vector is empty, something might be wrong
|
||||||
{
|
{
|
||||||
|
@ -288,8 +295,13 @@ int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQSocketZMQ::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
int64_t FairMQSocketZMQ::Receive(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||||
{
|
{
|
||||||
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -312,7 +324,7 @@ int64_t FairMQSocketZMQ::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
|
||||||
{
|
{
|
||||||
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
|
||||||
{
|
{
|
||||||
if (timeout)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
elapsed += fRcvTimeout;
|
elapsed += fRcvTimeout;
|
||||||
if (elapsed >= timeout)
|
if (elapsed >= timeout)
|
||||||
|
|
|
@ -28,15 +28,10 @@ class FairMQSocketZMQ final : public FairMQSocket
|
||||||
bool Bind(const std::string& address) override;
|
bool Bind(const std::string& address) override;
|
||||||
void Connect(const std::string& address) override;
|
void Connect(const std::string& address) override;
|
||||||
|
|
||||||
int Send(FairMQMessagePtr& msg, const int timeout = 0) override;
|
int Send(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||||
int Receive(FairMQMessagePtr& msg, const int timeout = 0) override;
|
int Receive(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||||
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||||
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||||
|
|
||||||
int TrySend(FairMQMessagePtr& msg) override;
|
|
||||||
int TryReceive(FairMQMessagePtr& msg) override;
|
|
||||||
int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
|
||||||
int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
|
||||||
|
|
||||||
void* GetSocket() const;
|
void* GetSocket() const;
|
||||||
|
|
||||||
|
@ -80,12 +75,6 @@ class FairMQSocketZMQ final : public FairMQSocket
|
||||||
|
|
||||||
int fSndTimeout;
|
int fSndTimeout;
|
||||||
int fRcvTimeout;
|
int fRcvTimeout;
|
||||||
|
|
||||||
int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
|
||||||
int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
|
||||||
|
|
||||||
int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
|
||||||
int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FAIRMQSOCKETZMQ_H_ */
|
#endif /* FAIRMQSOCKETZMQ_H_ */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user