FairMQ: Add functionality to set used message size

This commit is contained in:
Alexey Rybalchenko
2017-12-05 12:51:07 +01:00
committed by Mohammad Al-Turany
parent ac4695b215
commit e5aa85b61d
10 changed files with 250 additions and 98 deletions

View File

@@ -1,8 +1,8 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
@@ -141,11 +141,27 @@ void* FairMQMessageNN::GetData()
return fMessage;
}
size_t FairMQMessageNN::GetSize()
size_t FairMQMessageNN::GetSize() const
{
return fSize;
}
bool FairMQMessageNN::SetUsedSize(const size_t size)
{
if (size <= fSize)
{
// with size smaller than original nanomsg will simply "chop" the data, avoiding reallocation
fMessage = nn_reallocmsg(fMessage, size);
fSize = size;
return true;
}
else
{
LOG(ERROR) << "FairMQMessageNN::SetUsedSize: cannot set used size higher than original.";
return false;
}
}
void FairMQMessageNN::SetMessage(void* data, const size_t size)
{
fMessage = data;

View File

@@ -1,8 +1,8 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
@@ -33,21 +33,23 @@ class FairMQMessageNN : public FairMQMessage
FairMQMessageNN(const FairMQMessageNN&) = delete;
FairMQMessageNN operator=(const FairMQMessageNN&) = delete;
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 = nullptr);
void Rebuild() override;
void Rebuild(const size_t size) override;
void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) override;
virtual void* GetMessage();
virtual void* GetData();
virtual size_t GetSize();
void* GetMessage() override;
void* GetData() override;
size_t GetSize() const override;
virtual void SetMessage(void* data, const size_t size);
bool SetUsedSize(const size_t size) override;
virtual FairMQ::Transport GetType() const;
void SetMessage(void* data, const size_t size) override;
virtual void Copy(const std::unique_ptr<FairMQMessage>& msg);
FairMQ::Transport GetType() const override;
virtual ~FairMQMessageNN();
void Copy(const std::unique_ptr<FairMQMessage>& msg) override;
~FairMQMessageNN() override;
friend class FairMQSocketNN;

View File

@@ -65,7 +65,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, const string& name, const str
}
if (type == "sub")
{
nn_setsockopt(fSocket, NN_SUB, NN_SUB_SUBSCRIBE, NULL, 0);
nn_setsockopt(fSocket, NN_SUB, NN_SUB_SUBSCRIBE, nullptr, 0);
}
}
@@ -185,7 +185,7 @@ int FairMQSocketNN::Receive(FairMQMessagePtr& msg, const int flags)
while (true)
{
void* ptr = NULL;
void* ptr = nullptr;
nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags);
if (nbytes >= 0)
{
@@ -310,7 +310,7 @@ int64_t FairMQSocketNN::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const
while (true)
{
// pointer to point to received message buffer
char* ptr = NULL;
char* ptr = nullptr;
// receive the message into a buffer allocated by nanomsg and let ptr point to it
int nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags);
if (nbytes >= 0) // if no errors or non-blocking timeouts
@@ -396,7 +396,7 @@ void FairMQSocketNN::Resume()
void* FairMQSocketNN::GetSocket() const
{
return NULL; // dummy method to comply with the interface. functionality not possible in zeromq.
return nullptr; // dummy method to comply with the interface. functionality not possible in zeromq.
}
int FairMQSocketNN::GetSocket(int /*nothing*/) const