Skip to content

Commit

Permalink
Add empty msg check for transport compatibility checker
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx authored and dennisklein committed Jun 24, 2021
1 parent a8bdb91 commit 4dbb553
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
42 changes: 25 additions & 17 deletions fairmq/FairMQChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,22 +385,7 @@ class FairMQChannel
void CheckSendCompatibility(FairMQMessagePtr& msg)
{
if (fTransportType != msg->GetType()) {
FairMQMessagePtr msgWrapper(NewMessage(
msg->GetData(),
msg->GetSize(),
[](void* /*data*/, void* _msg) { delete static_cast<FairMQMessage*>(_msg); },
msg.get()
));
msg.release();
msg = move(msgWrapper);
}
}

void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec)
{
for (auto& msg : msgVec) {
if (fTransportType != msg->GetType()) {

if (msg->GetSize() > 0) {
FairMQMessagePtr msgWrapper(NewMessage(
msg->GetData(),
msg->GetSize(),
Expand All @@ -409,6 +394,30 @@ class FairMQChannel
));
msg.release();
msg = move(msgWrapper);
} else {
FairMQMessagePtr newMsg(NewMessage());
msg = move(newMsg);
}
}
}

void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec)
{
for (auto& msg : msgVec) {
if (fTransportType != msg->GetType()) {
if (msg->GetSize() > 0) {
FairMQMessagePtr msgWrapper(NewMessage(
msg->GetData(),
msg->GetSize(),
[](void* /*data*/, void* _msg) { delete static_cast<FairMQMessage*>(_msg); },
msg.get()
));
msg.release();
msg = move(msgWrapper);
} else {
FairMQMessagePtr newMsg(NewMessage());
msg = move(newMsg);
}
}
}
}
Expand All @@ -425,7 +434,6 @@ class FairMQChannel
{
for (auto& msg : msgVec) {
if (fTransportType != msg->GetType()) {

FairMQMessagePtr newMsg(NewMessage());
msg = move(newMsg);
}
Expand Down
6 changes: 2 additions & 4 deletions test/helper/devices/TestRep.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ class Rep : public FairMQDevice
auto Run() -> void override
{
auto request1 = FairMQMessagePtr{NewMessage()};
if (Receive(request1, "data") >= 0)
{
if (Receive(request1, "data") >= 0) {
LOG(info) << "Received request 1";
auto reply = FairMQMessagePtr{NewMessage()};
Send(reply, "data");
}
auto request2 = FairMQMessagePtr{NewMessage()};
if (Receive(request2, "data") >= 0)
{
if (Receive(request2, "data") >= 0) {
LOG(info) << "Received request 2";
auto reply = FairMQMessagePtr{NewMessage()};
Send(reply, "data");
Expand Down
3 changes: 1 addition & 2 deletions test/helper/devices/TestReq.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class Req : public FairMQDevice
Send(request, "data");

auto reply = FairMQMessagePtr{NewMessage()};
if (Receive(reply, "data") >= 0)
{
if (Receive(reply, "data") >= 0) {
LOG(info) << "received reply";
}
};
Expand Down
27 changes: 18 additions & 9 deletions test/protocols/_req_rep.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,36 @@ auto RunReqRep(string transport) -> void
{
size_t session{fair::mq::tools::UuidHash()};

auto rep = execute_result{ "", 0 };
auto rep = execute_result{"", 0};
thread rep_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id rep_" << transport << " --control static "
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
cmd << runTestDevice << " --id rep_" << transport
<< " --control static"
<< " --session " << session
<< " --color false"
<< " --mq-config \"" << mqConfig << "\"";
rep = execute(cmd.str(), "[REP]");
});

auto req1 = execute_result{ "", 0 };
auto req1 = execute_result{"", 0};
thread req1_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id req_1" << transport << " --control static "
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
cmd << runTestDevice << " --id req_1" << transport
<< " --control static"
<< " --session " << session
<< " --color false"
<< " --mq-config \"" << mqConfig << "\"";
req1 = execute(cmd.str(), "[REQ1]");
});

auto req2 = execute_result{ "", 0 };
auto req2 = execute_result{"", 0};
thread req2_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id req_2" << transport << " --control static "
<< "--session " << session << " --color false --mq-config \"" << mqConfig << "\"";
cmd << runTestDevice << " --id req_2" << transport
<< " --control static"
<< " --session " << session
<< " --color false"
<< " --mq-config \"" << mqConfig << "\"";
req2 = execute(cmd.str(), "[REQ2]");
});

Expand Down

0 comments on commit 4dbb553

Please sign in to comment.