mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51:45 +00:00
Update FairMQStateMachine & introduce FairMQChannels
Organize sockets as a map of vectors of FairMQChannels. Update FairMQStateMachine by removing SETTINGINPUT, SETTINGOUTPUT, BIND and CONNECT states and by adding INITIALIZING_TASK, RESETTING_TASK and RESETTING_DEVICE states. Run states functions in their own thread.
This commit is contained in:
@@ -63,7 +63,7 @@ FairMQMessageNN::FairMQMessageNN(void* data, size_t size, fairmq_free_fn *ffn, v
|
||||
fSize = size;
|
||||
fReceiving = false;
|
||||
|
||||
if(ffn)
|
||||
if (ffn)
|
||||
{
|
||||
ffn(data, hint);
|
||||
}
|
||||
@@ -140,8 +140,7 @@ void FairMQMessageNN::Copy(FairMQMessage* msg)
|
||||
{
|
||||
if (fMessage)
|
||||
{
|
||||
int rc = nn_freemsg(fMessage);
|
||||
if (rc < 0)
|
||||
if (nn_freemsg(fMessage) < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed freeing message, reason: " << nn_strerror(errno);
|
||||
}
|
||||
@@ -160,8 +159,7 @@ void FairMQMessageNN::Copy(FairMQMessage* msg)
|
||||
|
||||
inline void FairMQMessageNN::Clear()
|
||||
{
|
||||
int rc = nn_freemsg(fMessage);
|
||||
if (rc < 0)
|
||||
if (nn_freemsg(fMessage) < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed freeing message, reason: " << nn_strerror(errno);
|
||||
}
|
||||
|
@@ -15,32 +15,38 @@
|
||||
#include <nanomsg/nn.h>
|
||||
|
||||
#include "FairMQPollerNN.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQPollerNN::FairMQPollerNN(const vector<FairMQSocket*>& inputs)
|
||||
FairMQPollerNN::FairMQPollerNN(const vector<FairMQChannel>& channels)
|
||||
: items()
|
||||
, fNumItems()
|
||||
{
|
||||
fNumItems = inputs.size();
|
||||
fNumItems = channels.size();
|
||||
items = new nn_pollfd[fNumItems];
|
||||
|
||||
for (int i = 0; i < fNumItems; i++)
|
||||
for (int i = 0; i < fNumItems; ++i)
|
||||
{
|
||||
items[i].fd = inputs.at(i)->GetSocket(1);
|
||||
items[i].fd = channels.at(i).fSocket->GetSocket(1);
|
||||
items[i].events = NN_POLLIN;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQPollerNN::Poll(int timeout)
|
||||
{
|
||||
nn_poll(items, fNumItems, timeout);
|
||||
if (nn_poll(items, fNumItems, timeout) < 0)
|
||||
{
|
||||
LOG(ERROR) << "polling failed, reason: " << nn_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQPollerNN::CheckInput(int index)
|
||||
{
|
||||
if (items[index].revents & NN_POLLIN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -48,7 +54,9 @@ bool FairMQPollerNN::CheckInput(int index)
|
||||
bool FairMQPollerNN::CheckOutput(int index)
|
||||
{
|
||||
if (items[index].revents & NN_POLLOUT)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -56,5 +64,7 @@ bool FairMQPollerNN::CheckOutput(int index)
|
||||
FairMQPollerNN::~FairMQPollerNN()
|
||||
{
|
||||
if (items != NULL)
|
||||
{
|
||||
delete[] items;
|
||||
}
|
||||
}
|
||||
|
@@ -18,12 +18,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQSocket.h"
|
||||
#include "FairMQChannel.h"
|
||||
|
||||
class FairMQPollerNN : public FairMQPoller
|
||||
{
|
||||
public:
|
||||
FairMQPollerNN(const std::vector<FairMQSocket*>& inputs);
|
||||
FairMQPollerNN(const std::vector<FairMQChannel>& channels);
|
||||
|
||||
virtual void Poll(int timeout);
|
||||
virtual bool CheckInput(int index);
|
||||
|
@@ -20,7 +20,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
||||
FairMQSocketNN::FairMQSocketNN(const string& type, const std::string& name, int numIoThreads)
|
||||
: FairMQSocket(0, 0, NN_DONTWAIT)
|
||||
, fSocket()
|
||||
, fId()
|
||||
@@ -29,9 +29,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
||||
, fMessagesTx(0)
|
||||
, fMessagesRx(0)
|
||||
{
|
||||
stringstream id;
|
||||
id << type << "." << num;
|
||||
fId = id.str();
|
||||
fId = name + "." + type;
|
||||
|
||||
if (numIoThreads > 1)
|
||||
{
|
||||
@@ -46,7 +44,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
||||
fSocket = nn_socket(AF_SP_RAW, GetConstant(type));
|
||||
if (fSocket == -1)
|
||||
{
|
||||
LOG(ERROR) << "failed creating socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed creating socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +53,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
||||
fSocket = nn_socket(AF_SP, GetConstant(type));
|
||||
if (fSocket == -1)
|
||||
{
|
||||
LOG(ERROR) << "failed creating socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed creating socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (type == "sub")
|
||||
@@ -64,7 +62,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << "created socket #" << fId;
|
||||
LOG(INFO) << "created socket " << fId;
|
||||
}
|
||||
|
||||
string FairMQSocketNN::GetId()
|
||||
@@ -74,12 +72,12 @@ string FairMQSocketNN::GetId()
|
||||
|
||||
bool FairMQSocketNN::Bind(const string& address)
|
||||
{
|
||||
LOG(INFO) << "bind socket #" << fId << " on " << address;
|
||||
LOG(INFO) << "bind socket " << fId << " on " << address;
|
||||
|
||||
int eid = nn_bind(fSocket, address.c_str());
|
||||
if (eid < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed binding socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed binding socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -87,12 +85,12 @@ bool FairMQSocketNN::Bind(const string& address)
|
||||
|
||||
void FairMQSocketNN::Connect(const string& address)
|
||||
{
|
||||
LOG(INFO) << "connect socket #" << fId << " to " << address;
|
||||
LOG(INFO) << "connect socket " << fId << " to " << address;
|
||||
|
||||
int eid = nn_connect(fSocket, address.c_str());
|
||||
if (eid < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed connecting socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed connecting socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +100,7 @@ int FairMQSocketNN::Send(FairMQMessage* msg, const string& flag)
|
||||
int rc = nn_send(fSocket, &ptr, NN_MSG, 0);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed sending on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -120,7 +118,7 @@ int FairMQSocketNN::Send(FairMQMessage* msg, const int flags)
|
||||
int rc = nn_send(fSocket, &ptr, NN_MSG, flags);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed sending on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -138,7 +136,7 @@ int FairMQSocketNN::Receive(FairMQMessage* msg, const string& flag)
|
||||
int rc = nn_recv(fSocket, &ptr, NN_MSG, 0);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed receiving on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -157,7 +155,7 @@ int FairMQSocketNN::Receive(FairMQMessage* msg, const int flags)
|
||||
int rc = nn_recv(fSocket, &ptr, NN_MSG, flags);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed receiving on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -26,17 +26,17 @@
|
||||
class FairMQSocketNN : public FairMQSocket
|
||||
{
|
||||
public:
|
||||
FairMQSocketNN(const std::string& type, int num, int numIoThreads); // numIoThreads is not used in nanomsg.
|
||||
FairMQSocketNN(const std::string& type, const std::string& name, int numIoThreads); // numIoThreads is not used in nanomsg.
|
||||
|
||||
virtual std::string GetId();
|
||||
|
||||
virtual bool Bind(const std::string& address);
|
||||
virtual void Connect(const std::string& address);
|
||||
|
||||
virtual int Send(FairMQMessage* msg, const std::string& flag="");
|
||||
virtual int Send(FairMQMessage* msg, const int flags);
|
||||
virtual int Receive(FairMQMessage* msg, const std::string& flag="");
|
||||
virtual int Receive(FairMQMessage* msg, const int flags);
|
||||
virtual int Send(FairMQMessage* msg, const std::string& flag = "");
|
||||
virtual int Send(FairMQMessage* msg, const int flags = 0);
|
||||
virtual int Receive(FairMQMessage* msg, const std::string& flag = "");
|
||||
virtual int Receive(FairMQMessage* msg, const int flags = 0);
|
||||
|
||||
virtual void* GetSocket();
|
||||
virtual int GetSocket(int nothing);
|
||||
|
@@ -36,12 +36,12 @@ FairMQMessage* FairMQTransportFactoryNN::CreateMessage(void* data, size_t size,
|
||||
return new FairMQMessageNN(data, size, ffn, hint);
|
||||
}
|
||||
|
||||
FairMQSocket* FairMQTransportFactoryNN::CreateSocket(const string& type, int num, int numIoThreads)
|
||||
FairMQSocket* FairMQTransportFactoryNN::CreateSocket(const string& type, const std::string& name, int numIoThreads)
|
||||
{
|
||||
return new FairMQSocketNN(type, num, numIoThreads);
|
||||
return new FairMQSocketNN(type, name, numIoThreads);
|
||||
}
|
||||
|
||||
FairMQPoller* FairMQTransportFactoryNN::CreatePoller(const vector<FairMQSocket*>& inputs)
|
||||
FairMQPoller* FairMQTransportFactoryNN::CreatePoller(const vector<FairMQChannel>& channels)
|
||||
{
|
||||
return new FairMQPollerNN(inputs);
|
||||
return new FairMQPollerNN(channels);
|
||||
}
|
||||
|
@@ -30,8 +30,8 @@ class FairMQTransportFactoryNN : public FairMQTransportFactory
|
||||
virtual FairMQMessage* CreateMessage();
|
||||
virtual FairMQMessage* CreateMessage(size_t size);
|
||||
virtual FairMQMessage* CreateMessage(void* data, size_t size, fairmq_free_fn *ffn = NULL, void* hint = NULL);
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, int num, int numIoThreads);
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQSocket*>& inputs);
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, const std::string& name, int numIoThreads);
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQChannel>& channels);
|
||||
|
||||
virtual ~FairMQTransportFactoryNN() {};
|
||||
};
|
||||
|
Reference in New Issue
Block a user