mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
FairMQSocket: add versions of Send/Receive methods with int flags instead of string, which is more flexible and performant.
Int flags are mapped to their ZeroMQ/nanomsg versions behind the transport interface. Methods with string flags are kept for backwards compatibility.
This commit is contained in:
committed by
Mohammad Al-Turany
parent
a9b7e8866c
commit
6518b7cd41
@@ -19,7 +19,8 @@
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
||||
: fSocket()
|
||||
: FairMQSocket(0, 0, NN_DONTWAIT)
|
||||
, fSocket()
|
||||
, fId()
|
||||
, fBytesTx(0)
|
||||
, fBytesRx(0)
|
||||
@@ -100,6 +101,24 @@ int FairMQSocketNN::Send(FairMQMessage* msg, const string& flag)
|
||||
return rc;
|
||||
}
|
||||
|
||||
int FairMQSocketNN::Send(FairMQMessage* msg, const int flags)
|
||||
{
|
||||
void* ptr = msg->GetMessage();
|
||||
int rc = nn_send(fSocket, &ptr, NN_MSG, flags);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
fBytesTx += rc;
|
||||
++fMessagesTx;
|
||||
static_cast<FairMQMessageNN*>(msg)->fReceiving = false;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int FairMQSocketNN::Receive(FairMQMessage* msg, const string& flag)
|
||||
{
|
||||
void* ptr = NULL;
|
||||
@@ -119,6 +138,25 @@ int FairMQSocketNN::Receive(FairMQMessage* msg, const string& flag)
|
||||
return rc;
|
||||
}
|
||||
|
||||
int FairMQSocketNN::Receive(FairMQMessage* msg, const int flags)
|
||||
{
|
||||
void* ptr = NULL;
|
||||
int rc = nn_recv(fSocket, &ptr, NN_MSG, flags);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
fBytesRx += rc;
|
||||
++fMessagesRx;
|
||||
msg->SetMessage(ptr, rc);
|
||||
static_cast<FairMQMessageNN*>(msg)->fReceiving = true;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void FairMQSocketNN::Close()
|
||||
{
|
||||
nn_close(fSocket);
|
||||
@@ -196,12 +234,10 @@ int FairMQSocketNN::GetConstant(const string& constant)
|
||||
return NN_REQ;
|
||||
if (constant == "rep")
|
||||
return NN_REP;
|
||||
|
||||
if (constant == "dealer")
|
||||
return NN_REQ;
|
||||
if (constant == "router")
|
||||
return NN_REP;
|
||||
|
||||
if (constant == "pair")
|
||||
return NN_PAIR;
|
||||
|
||||
@@ -209,7 +245,6 @@ int FairMQSocketNN::GetConstant(const string& constant)
|
||||
return NN_SNDBUF;
|
||||
if (constant == "rcv-hwm")
|
||||
return NN_RCVBUF;
|
||||
|
||||
if (constant == "snd-more") {
|
||||
LOG(ERROR) << "Multipart messages functionality currently not supported by nanomsg!";
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user