From ab09f5da9825a02ee0df3d295101d7245f3dd555 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 21 Aug 2018 13:03:29 +0200 Subject: [PATCH 1/3] Problem: addition of new single-argument message_t introduces ambiguity when calling e.g. socket_t::send Solution: make single-argument constructor explicit --- tests/active_poller.cpp | 20 ++++++++++---------- tests/poller.cpp | 12 ++++++------ zmq.hpp | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/active_poller.cpp b/tests/active_poller.cpp index d07c366..7f7dcc2 100644 --- a/tests/active_poller.cpp +++ b/tests/active_poller.cpp @@ -157,7 +157,7 @@ TEST(active_poller, poll_basic) { server_client_setup s; - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); zmq::active_poller_t active_poller; bool message_received = false; @@ -196,7 +196,7 @@ TEST(active_poller, client_server) ASSERT_NO_THROW(active_poller.add(s.server, ZMQ_POLLIN, handler)); // client sends message - ASSERT_NO_THROW(s.client.send(send_msg)); + ASSERT_NO_THROW(s.client.send(zmq::message_t{send_msg})); ASSERT_EQ(1, active_poller.wait(std::chrono::milliseconds{-1})); ASSERT_EQ(events, ZMQ_POLLIN); @@ -235,7 +235,7 @@ TEST(active_poller, remove_invalid_socket_throws) TEST(active_poller, wait_on_added_empty_handler) { server_client_setup s; - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); zmq::active_poller_t active_poller; zmq::active_poller_t::handler_t handler; ASSERT_NO_THROW(active_poller.add(s.server, ZMQ_POLLIN, handler)); @@ -290,7 +290,7 @@ TEST(active_poller, poll_client_server) ASSERT_NO_THROW(active_poller.add(s.server, ZMQ_POLLIN, s.handler)); // client sends message - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); // wait for message and verify events ASSERT_NO_THROW(active_poller.wait(std::chrono::milliseconds{500})); @@ -315,7 +315,7 @@ TEST(active_poller, wait_one_return) active_poller.add(s.server, ZMQ_POLLIN, [&count](short) { ++count; })); // client sends message - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); // wait for message and verify events ASSERT_EQ(1, active_poller.wait(std::chrono::milliseconds{500})); @@ -325,7 +325,7 @@ TEST(active_poller, wait_one_return) TEST(active_poller, wait_on_move_constructed_active_poller) { server_client_setup s; - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); zmq::active_poller_t a; zmq::active_poller_t::handler_t handler; ASSERT_NO_THROW(a.add(s.server, ZMQ_POLLIN, handler)); @@ -339,7 +339,7 @@ TEST(active_poller, wait_on_move_constructed_active_poller) TEST(active_poller, wait_on_move_assigned_active_poller) { server_client_setup s; - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); zmq::active_poller_t a; zmq::active_poller_t::handler_t handler; ASSERT_NO_THROW(a.add(s.server, ZMQ_POLLIN, handler)); @@ -360,14 +360,14 @@ TEST(active_poller, received_on_move_constructed_active_poller) zmq::active_poller_t a; ASSERT_NO_THROW(a.add(s.server, ZMQ_POLLIN, [&count](short) { ++count; })); // client sends message - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); // wait for message and verify it is received ASSERT_EQ(1, a.wait(std::chrono::milliseconds{500})); ASSERT_EQ(1u, count); // Move construct active_poller b zmq::active_poller_t b{std::move(a)}; // client sends message again - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); // wait for message and verify it is received ASSERT_EQ(1, b.wait(std::chrono::milliseconds{500})); ASSERT_EQ(2u, count); @@ -398,7 +398,7 @@ TEST(active_poller, remove_from_handler) ASSERT_EQ(ITER_NO, active_poller.size()); // Clients send messages for (auto &s : setup_list) { - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); } // Wait for all servers to receive a message diff --git a/tests/poller.cpp b/tests/poller.cpp index 5872107..25abadd 100644 --- a/tests/poller.cpp +++ b/tests/poller.cpp @@ -128,7 +128,7 @@ TEST(poller, poll_basic) { common_server_client_setup s; - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); zmq::poller_t poller; std::vector events{1}; @@ -206,7 +206,7 @@ TEST(poller, poll_client_server) ASSERT_NO_THROW(poller.add(s.server, ZMQ_POLLIN, s.server)); // client sends message - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); // wait for message and verify events std::vector events(1); @@ -229,7 +229,7 @@ TEST(poller, wait_one_return) ASSERT_NO_THROW(poller.add(s.server, ZMQ_POLLIN, nullptr)); // client sends message - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); // wait for message and verify events std::vector events(1); @@ -239,7 +239,7 @@ TEST(poller, wait_one_return) TEST(poller, wait_on_move_constructed_poller) { common_server_client_setup s; - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); zmq::poller_t<> a; ASSERT_NO_THROW(a.add(s.server, ZMQ_POLLIN, nullptr)); zmq::poller_t<> b{std::move(a)}; @@ -252,7 +252,7 @@ TEST(poller, wait_on_move_constructed_poller) TEST(poller, wait_on_move_assigned_poller) { common_server_client_setup s; - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); zmq::poller_t<> a; ASSERT_NO_THROW(a.add(s.server, ZMQ_POLLIN, nullptr)); zmq::poller_t<> b; @@ -279,7 +279,7 @@ TEST(poller, remove_from_handler) } // Clients send messages for (auto &s : setup_list) { - ASSERT_NO_THROW(s.client.send("Hi")); + ASSERT_NO_THROW(s.client.send(zmq::message_t{"Hi"})); } // Wait for all servers to receive a message diff --git a/zmq.hpp b/zmq.hpp index a820afe..ee41ecf 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -264,7 +264,7 @@ class message_t #if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11) template - message_t(const T &msg_) : message_t(std::begin(msg_), std::end(msg_)) + explicit message_t(const T &msg_) : message_t(std::begin(msg_), std::end(msg_)) { } #endif From 120c7ae3f2fd6cc42b40df6932e5c76358df6b3e Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 21 Aug 2018 13:36:01 +0200 Subject: [PATCH 2/3] Problem: no test case for previously existing send functionality Solution: added test case --- tests/socket.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/socket.cpp b/tests/socket.cpp index a0397a1..c3cf9bc 100644 --- a/tests/socket.cpp +++ b/tests/socket.cpp @@ -14,3 +14,16 @@ TEST(socket, create_by_enum_destroy) zmq::socket_t socket(context, zmq::socket_type::router); } #endif + +TEST(socket, send_receive_const_buffer) +{ + zmq::context_t context; + zmq::socket_t sender(context, ZMQ_PAIR); + zmq::socket_t receiver(context, ZMQ_PAIR); + receiver.bind("inproc://test"); + sender.connect("inproc://test"); + ASSERT_EQ(2, sender.send("Hi", 2)); + char buf[2]; + ASSERT_EQ(2, receiver.recv(buf, 2)); + ASSERT_EQ(0, memcmp(buf, "Hi", 2)); +} From 7d53a04e81e28a76a67328abb5e9fa9885c34c95 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 21 Aug 2018 13:51:17 +0200 Subject: [PATCH 3/3] Set version to 4.3.1 to prepare bugfix release --- zmq.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zmq.hpp b/zmq.hpp index ee41ecf..c73e89e 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -63,8 +63,8 @@ /* Version macros for compile-time API version detection */ #define CPPZMQ_VERSION_MAJOR 4 -#define CPPZMQ_VERSION_MINOR 4 -#define CPPZMQ_VERSION_PATCH 0 +#define CPPZMQ_VERSION_MINOR 3 +#define CPPZMQ_VERSION_PATCH 1 #define CPPZMQ_VERSION \ ZMQ_MAKE_VERSION(CPPZMQ_VERSION_MAJOR, CPPZMQ_VERSION_MINOR, \