From b1c3decbce8ca719378e3ed95fea76c2bfb8c052 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Tue, 5 Sep 2023 20:12:00 +0000 Subject: [PATCH 1/3] Address comments --- common/events_common.h | 6 ++---- tests/events_common_ut.cpp | 13 +++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/common/events_common.h b/common/events_common.h index 92770d7c..c9b91a70 100644 --- a/common/events_common.h +++ b/common/events_common.h @@ -258,9 +258,6 @@ struct serialization int deserialize(const string& s, Map& data) { - if (s.size() < 2) { // zmq identifying message of length 1 - return 0; - } try { istringstream ss(s); boost::archive::text_iarchive iarch(ss); @@ -312,7 +309,8 @@ struct serialization more = 0; zmq_msg_init(&msg); int rc = zmq_msg_recv(&msg, sock, flag); - if (rc != -1) { + int msg_size = static_cast(zmq_msg_size(&msg)); + if (rc != -1 && msg_size > 1) { size_t more_size = sizeof (more); zmq_getsockopt (sock, ZMQ_RCVMORE, &more, &more_size); diff --git a/tests/events_common_ut.cpp b/tests/events_common_ut.cpp index 485a9fcd..a1450347 100644 --- a/tests/events_common_ut.cpp +++ b/tests/events_common_ut.cpp @@ -81,19 +81,24 @@ TEST(events_common, send_recv) void *sock_p1 = zmq_socket (zmq_ctx, ZMQ_PAIR); EXPECT_EQ(0, zmq_bind (sock_p1, path)); - string source("Hello"), source1, source2("#"); + string source("Hello"), source1, source2, source3; map m = {{"foo", "bar"}, {"hello", "world"}, {"good", "day"}}; - map m1, m2; + map m1, m2, m3; EXPECT_EQ(0, zmq_message_send(sock_p0, source, m)); EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source1, m1)); - + EXPECT_EQ(source, source1); EXPECT_EQ(m, m1); + + + EXPECT_EQ(0, zmq_message_send(sock_p0, source2, m2)); + EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source3, m3)); - EXPECT_EQ(0, deserialize(source2, m2)); + EXPECT_EQ(source2, source3); + EXPECT_EQ(m2, m3); zmq_close(sock_p0); zmq_close(sock_p1); From 0b096edf62c7817424211af1db5b540e11c46fa3 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Tue, 5 Sep 2023 20:26:47 +0000 Subject: [PATCH 2/3] Remove space --- tests/events_common_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/events_common_ut.cpp b/tests/events_common_ut.cpp index a1450347..6781ce6b 100644 --- a/tests/events_common_ut.cpp +++ b/tests/events_common_ut.cpp @@ -89,7 +89,7 @@ TEST(events_common, send_recv) EXPECT_EQ(0, zmq_message_send(sock_p0, source, m)); EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source1, m1)); - + EXPECT_EQ(source, source1); EXPECT_EQ(m, m1); From 6584de109d7dc754e3c7c150fe5d9010814f0b7d Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Mon, 11 Sep 2023 17:55:51 +0000 Subject: [PATCH 3/3] Fix review comments --- common/events_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/events_common.h b/common/events_common.h index c9b91a70..68b05526 100644 --- a/common/events_common.h +++ b/common/events_common.h @@ -309,7 +309,7 @@ struct serialization more = 0; zmq_msg_init(&msg); int rc = zmq_msg_recv(&msg, sock, flag); - int msg_size = static_cast(zmq_msg_size(&msg)); + size_t msg_size = zmq_msg_size(&msg); if (rc != -1 && msg_size > 1) { size_t more_size = sizeof (more);