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:
Alexey Rybalchenko
2015-01-25 21:40:00 +01:00
committed by Mohammad Al-Turany
parent a9b7e8866c
commit 6518b7cd41
5 changed files with 103 additions and 5 deletions

View File

@@ -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;