First version of the shared memory transport.

Use via `--transport shmem` cmd option. No pub/sub.
This commit is contained in:
Alexey Rybalchenko
2016-06-03 11:24:12 +02:00
parent 6c3b01f09c
commit a332d9fc83
39 changed files with 2121 additions and 309 deletions

View File

@@ -12,8 +12,6 @@
* @author D. Klein, A. Rybalchenko
*/
#include <sstream>
#include <zmq.h>
#include "FairMQLogger.h"
@@ -60,9 +58,12 @@ void FairMQContextZMQ::Close()
if (zmq_ctx_destroy(fContext) != 0)
{
if (errno == EINTR) {
if (errno == EINTR)
{
LOG(ERROR) << " failed closing context, reason: " << zmq_strerror(errno);
} else {
}
else
{
fContext = NULL;
return;
}

View File

@@ -20,6 +20,8 @@
using namespace std;
string FairMQMessageZMQ::fDeviceID = string();
FairMQMessageZMQ::FairMQMessageZMQ()
: fMessage()
{
@@ -94,22 +96,9 @@ void FairMQMessageZMQ::SetMessage(void*, const size_t)
// dummy method to comply with the interface. functionality not allowed in zeromq.
}
void FairMQMessageZMQ::Copy(FairMQMessage* msg)
void FairMQMessageZMQ::SetDeviceId(const string& deviceId)
{
// DEPRECATED: Use Copy(const unique_ptr<FairMQMessage>&)
// Shares the message buffer between msg and this fMessage.
if (zmq_msg_copy(&fMessage, static_cast<zmq_msg_t*>(msg->GetMessage())) != 0)
{
LOG(ERROR) << "failed copying message, reason: " << zmq_strerror(errno);
}
// Alternatively, following code does a hard copy of the message, which allows to modify the original after making a copy, without affecting the new msg.
// CloseMessage();
// size_t size = msg->GetSize();
// zmq_msg_init_size(&fMessage, size);
// memcpy(zmq_msg_data(&fMessage), msg->GetData(), size);
fDeviceID = deviceId;
}
void FairMQMessageZMQ::Copy(const unique_ptr<FairMQMessage>& msg)
@@ -128,7 +117,7 @@ void FairMQMessageZMQ::Copy(const unique_ptr<FairMQMessage>& msg)
// memcpy(zmq_msg_data(&fMessage), msg->GetData(), size);
}
inline void FairMQMessageZMQ::CloseMessage()
void FairMQMessageZMQ::CloseMessage()
{
if (zmq_msg_close(&fMessage) != 0)
{

View File

@@ -16,6 +16,7 @@
#define FAIRMQMESSAGEZMQ_H_
#include <cstddef>
#include <string>
#include <zmq.h>
@@ -26,11 +27,11 @@ class FairMQMessageZMQ : public FairMQMessage
public:
FairMQMessageZMQ();
FairMQMessageZMQ(const size_t size);
FairMQMessageZMQ(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = NULL);
FairMQMessageZMQ(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr);
virtual void Rebuild();
virtual void Rebuild(const size_t size);
virtual void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = NULL);
virtual void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr);
virtual void* GetMessage();
virtual void* GetData();
@@ -38,14 +39,17 @@ class FairMQMessageZMQ : public FairMQMessage
virtual void SetMessage(void* data, const size_t size);
virtual void CloseMessage();
virtual void Copy(FairMQMessage* msg);
virtual void SetDeviceId(const std::string& deviceId);
virtual void Copy(const std::unique_ptr<FairMQMessage>& msg);
void CloseMessage();
virtual ~FairMQMessageZMQ();
private:
zmq_msg_t fMessage;
static std::string fDeviceID;
};
#endif /* FAIRMQMESSAGEZMQ_H_ */

View File

@@ -108,24 +108,7 @@ void FairMQSocketZMQ::Connect(const string& address)
int FairMQSocketZMQ::Send(FairMQMessage* msg, const string& flag)
{
int nbytes = zmq_msg_send(static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, GetConstant(flag));
if (nbytes >= 0)
{
fBytesTx += nbytes;
++fMessagesTx;
return nbytes;
}
if (zmq_errno() == EAGAIN)
{
return -2;
}
if (zmq_errno() == ETERM)
{
LOG(INFO) << "terminating socket " << fId;
return -1;
}
LOG(ERROR) << "Failed sending on socket " << fId << ", reason: " << zmq_strerror(errno);
return nbytes;
return Send(msg, GetConstant(flag));
}
int FairMQSocketZMQ::Send(FairMQMessage* msg, const int flags)
@@ -218,24 +201,7 @@ int64_t FairMQSocketZMQ::Send(const vector<unique_ptr<FairMQMessage>>& msgVec, c
int FairMQSocketZMQ::Receive(FairMQMessage* msg, const string& flag)
{
int nbytes = zmq_msg_recv(static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, GetConstant(flag));
if (nbytes >= 0)
{
fBytesRx += nbytes;
++fMessagesRx;
return nbytes;
}
if (zmq_errno() == EAGAIN)
{
return -2;
}
if (zmq_errno() == ETERM)
{
LOG(INFO) << "terminating socket " << fId;
return -1;
}
LOG(ERROR) << "Failed receiving on socket " << fId << ", reason: " << zmq_strerror(errno);
return nbytes;
return Receive(msg, GetConstant(flag));
}
int FairMQSocketZMQ::Receive(FairMQMessage* msg, const int flags)
@@ -323,6 +289,14 @@ void FairMQSocketZMQ::Terminate()
}
}
void FairMQSocketZMQ::Interrupt()
{
}
void FairMQSocketZMQ::Resume()
{
}
void* FairMQSocketZMQ::GetSocket() const
{
return fSocket;

View File

@@ -47,6 +47,9 @@ class FairMQSocketZMQ : public FairMQSocket
virtual void Close();
virtual void Terminate();
virtual void Interrupt();
virtual void Resume();
virtual void SetOption(const std::string& option, const void* value, size_t valueSize);
virtual void GetOption(const std::string& option, void* value, size_t* valueSize);