From c663f37761c7bebd0061061ede13a4e9aef5b6f4 Mon Sep 17 00:00:00 2001 From: MinRK Date: Sun, 27 Oct 2013 22:50:04 -0700 Subject: [PATCH 1/5] add missing msg->init for ROUTER_RAW with empty message --- src/router.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/router.cpp b/src/router.cpp index 5bac2d82..6fabf67f 100644 --- a/src/router.cpp +++ b/src/router.cpp @@ -225,6 +225,8 @@ int zmq::router_t::xsend (msg_t *msg_) current_out->terminate (false); int rc = msg_->close (); errno_assert (rc == 0); + rc = msg_->init (); + errno_assert (rc == 0); current_out = NULL; return 0; } From 60032ef3301316ef00e9bce4f34a9a22d075b83e Mon Sep 17 00:00:00 2001 From: MinRK Date: Sun, 27 Oct 2013 22:50:32 -0700 Subject: [PATCH 2/5] test zmq_msg_close after sending empty message on ROUTER_RAW --- tests/Makefile.am | 2 + tests/test_router_raw_empty.cpp | 65 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/test_router_raw_empty.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index 035b8ac8..ccc4b64a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,6 +19,7 @@ noinst_PROGRAMS = test_system \ test_term_endpoint \ test_monitor \ test_router_mandatory \ + test_router_raw_empty \ test_probe_router \ test_stream \ test_disconnect_inproc \ @@ -64,6 +65,7 @@ test_last_endpoint_SOURCES = test_last_endpoint.cpp test_term_endpoint_SOURCES = test_term_endpoint.cpp test_monitor_SOURCES = test_monitor.cpp test_router_mandatory_SOURCES = test_router_mandatory.cpp +test_router_raw_empty_SOURCES = test_router_raw_empty.cpp test_probe_router_SOURCES = test_probe_router.cpp test_stream_SOURCES = test_stream.cpp test_disconnect_inproc_SOURCES = test_disconnect_inproc.cpp diff --git a/tests/test_router_raw_empty.cpp b/tests/test_router_raw_empty.cpp new file mode 100644 index 00000000..29a00bf6 --- /dev/null +++ b/tests/test_router_raw_empty.cpp @@ -0,0 +1,65 @@ +/* + Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" + +int main (void) { + setup_test_environment(); + void *ctx = zmq_ctx_new(); + assert(ctx); + + void *router = zmq_socket(ctx, ZMQ_ROUTER); + assert(router); + void *dealer = zmq_socket(ctx, ZMQ_DEALER); + assert(dealer); + + int one=1; + int rc = zmq_setsockopt(router, ZMQ_ROUTER_RAW, &one, sizeof(int)); + assert(rc >= 0); + rc = zmq_setsockopt(router, ZMQ_ROUTER_MANDATORY, &one, sizeof(int)); + assert(rc >= 0); + + rc = zmq_bind(router, "tcp://127.0.0.1:5555"); + rc = zmq_connect(dealer, "tcp://127.0.0.1:5555"); + zmq_send(dealer, "", 0, 0); + + + zmq_msg_t ident, empty, echo; + zmq_msg_init(&ident); + rc = zmq_msg_recv(&ident, router, 0); + assert(rc >= 0); + rc = zmq_msg_init_data(&empty, (void*)"", 0, NULL, NULL); + assert(rc >= 0); + + rc = zmq_msg_send(&ident, router, ZMQ_SNDMORE); + assert(rc >= 0); + rc = zmq_msg_close(&ident); + assert(rc >= 0); + + rc = zmq_msg_send(&empty, router, 0); + assert(rc >= 0); + + // This close used to fail with Bad Address + rc = zmq_msg_close(&empty); + assert(rc >= 0); + + close_zero_linger(dealer); + close_zero_linger(router); + zmq_ctx_term(ctx); +} \ No newline at end of file From f0b69bba286dcd9689e40674a84cf1ab940a2d81 Mon Sep 17 00:00:00 2001 From: Richard Newton Date: Mon, 28 Oct 2013 08:30:31 +0000 Subject: [PATCH 3/5] Fix test warning. --- tests/test_router_raw_empty.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_router_raw_empty.cpp b/tests/test_router_raw_empty.cpp index 29a00bf6..83dc10cd 100644 --- a/tests/test_router_raw_empty.cpp +++ b/tests/test_router_raw_empty.cpp @@ -40,7 +40,7 @@ int main (void) { zmq_send(dealer, "", 0, 0); - zmq_msg_t ident, empty, echo; + zmq_msg_t ident, empty; zmq_msg_init(&ident); rc = zmq_msg_recv(&ident, router, 0); assert(rc >= 0); @@ -62,4 +62,4 @@ int main (void) { close_zero_linger(dealer); close_zero_linger(router); zmq_ctx_term(ctx); -} \ No newline at end of file +} From 30f470eff56d4b7f778cd83bda0ea689cf752a41 Mon Sep 17 00:00:00 2001 From: Richard Newton Date: Mon, 28 Oct 2013 08:34:32 +0000 Subject: [PATCH 4/5] Fix test warning. --- tests/test_ctx_options.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ctx_options.cpp b/tests/test_ctx_options.cpp index 1c107440..900e1250 100644 --- a/tests/test_ctx_options.cpp +++ b/tests/test_ctx_options.cpp @@ -33,7 +33,7 @@ int main (void) assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0); rc = zmq_ctx_set (ctx, ZMQ_IPV6, true); - assert (zmq_ctx_get (ctx, ZMQ_IPV6) == true); + assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 1); void *router = zmq_socket (ctx, ZMQ_ROUTER); int ipv6; From de239f358e02c4d42a2c4426ffee893e101c90b2 Mon Sep 17 00:00:00 2001 From: Richard Newton Date: Wed, 6 Nov 2013 15:19:04 +0000 Subject: [PATCH 5/5] Fix race condition on shutdown --- src/ctx.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ctx.cpp b/src/ctx.cpp index fa35cf0e..b078c7c5 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -107,7 +107,6 @@ int zmq::ctx_t::terminate () // restarted. bool restarted = terminating; terminating = true; - slot_sync.unlock (); // First attempt to terminate the context. if (!restarted) { @@ -115,13 +114,12 @@ int zmq::ctx_t::terminate () // First send stop command to sockets so that any blocking calls // can be interrupted. If there are no sockets we can ask reaper // thread to stop. - slot_sync.lock (); for (sockets_t::size_type i = 0; i != sockets.size (); i++) sockets [i]->stop (); if (sockets.empty ()) reaper->stop (); - slot_sync.unlock (); } + slot_sync.unlock(); // Wait till reaper thread closes all the sockets. command_t cmd;