Skip to content

Commit

Permalink
Refs eProsima#3787 Avoid CDRMessage_t creation each time OnDataReceiv…
Browse files Browse the repository at this point in the history
…ed is called. (eProsima#318)
  • Loading branch information
LuisGP authored and richiware committed Nov 13, 2018
1 parent b939150 commit 72743c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/fastrtps/rtps/network/ReceiverResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ReceiverResource : public TransportReceiverInterface

std::mutex mtx;
MessageReceiver* receiver;
CDRMessage_t msg;
};

} // namespace rtps
Expand Down
11 changes: 6 additions & 5 deletions src/cpp/rtps/network/ReceiverResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ namespace eprosima{
namespace fastrtps{
namespace rtps{

ReceiverResource::ReceiverResource(TransportInterface& transport,
const Locator_t& locator, uint32_t max_size)
: mValid(false), receiver(nullptr)
ReceiverResource::ReceiverResource(TransportInterface& transport, const Locator_t& locator, uint32_t max_size)
: mValid(false)
, receiver(nullptr)
, msg(0)
{
// Internal channel is opened and assigned to this resource.
mValid = transport.OpenInputChannel(locator, this, max_size);
Expand All @@ -50,6 +51,7 @@ ReceiverResource::ReceiverResource(ReceiverResource&& rValueResource)
rValueResource.receiver = nullptr;
mValid = rValueResource.mValid;
rValueResource.mValid = false;
msg = std::move(rValueResource.msg);
}

bool ReceiverResource::SupportsLocator(const Locator_t& localLocator)
Expand All @@ -75,7 +77,7 @@ void ReceiverResource::UnregisterReceiver(MessageReceiver* rcv)
receiver = nullptr;
}

void ReceiverResource::OnDataReceived(const octet * data, const uint32_t size,
void ReceiverResource::OnDataReceived(const octet * data, const uint32_t size,
const Locator_t & localLocator, const Locator_t & remoteLocator)
{
(void)localLocator;
Expand All @@ -85,7 +87,6 @@ void ReceiverResource::OnDataReceived(const octet * data, const uint32_t size,

if (rcv != nullptr)
{
CDRMessage_t msg(0);
msg.wraps = true;
msg.buffer = const_cast<octet*>(data);
msg.length = size;
Expand Down

0 comments on commit 72743c1

Please sign in to comment.