From 5b510656d000f1ac346db32a6a404d717809ae70 Mon Sep 17 00:00:00 2001 From: sigiesec Date: Fri, 2 Feb 2018 16:29:10 +0100 Subject: [PATCH] Problem: unreachable code around socket_base_t::add/remove_signaler Solution: replaced by assertion --- src/socket_base.cpp | 32 ++++++++++---------------------- src/socket_base.hpp | 4 ++-- src/socket_poller.cpp | 3 +-- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 77f4bcd8cf..217758b17a 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -312,9 +312,9 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) return -1; } - // Check whether socket type and transport protocol match. - // Specifically, multicast protocols can't be combined with - // bi-directional messaging patterns (socket types). + // Check whether socket type and transport protocol match. + // Specifically, multicast protocols can't be combined with + // bi-directional messaging patterns (socket types). #if defined ZMQ_HAVE_OPENPGM || defined ZMQ_HAVE_NORM if ((protocol_ == "pgm" || protocol_ == "epgm" || protocol_ == "norm") && options.type != ZMQ_PUB && options.type != ZMQ_SUB @@ -487,32 +487,20 @@ int zmq::socket_base_t::leave (const char *group_) return rc; } -int zmq::socket_base_t::add_signaler (signaler_t *s_) +void zmq::socket_base_t::add_signaler (signaler_t *s_) { - scoped_optional_lock_t sync_lock (thread_safe ? &sync : NULL); - - if (!thread_safe) { - errno = EINVAL; - return -1; - } + zmq_assert (thread_safe); + scoped_lock_t sync_lock (sync); ((mailbox_safe_t *) mailbox)->add_signaler (s_); - - return 0; } -int zmq::socket_base_t::remove_signaler (signaler_t *s_) +void zmq::socket_base_t::remove_signaler (signaler_t *s_) { - scoped_optional_lock_t sync_lock (thread_safe ? &sync : NULL); - - if (!thread_safe) { - errno = EINVAL; - return -1; - } + zmq_assert (thread_safe); + scoped_lock_t sync_lock (sync); ((mailbox_safe_t *) mailbox)->remove_signaler (s_); - - return 0; } int zmq::socket_base_t::bind (const char *addr_) @@ -923,7 +911,7 @@ int zmq::socket_base_t::connect (const char *addr_) } } - // TBD - Should we check address for ZMQ_HAVE_NORM??? + // TBD - Should we check address for ZMQ_HAVE_NORM??? #ifdef ZMQ_HAVE_OPENPGM if (protocol == "pgm" || protocol == "epgm") { diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 8d85bd5f93..26cf604fdf 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -86,8 +86,8 @@ class socket_base_t : public own_t, int term_endpoint (const char *addr_); int send (zmq::msg_t *msg_, int flags_); int recv (zmq::msg_t *msg_, int flags_); - int add_signaler (signaler_t *s); - int remove_signaler (signaler_t *s); + void add_signaler (signaler_t *s); + void remove_signaler (signaler_t *s); int close (); // These functions are used by the polling mechanism to determine diff --git a/src/socket_poller.cpp b/src/socket_poller.cpp index d21791afa1..2cd8cbe789 100644 --- a/src/socket_poller.cpp +++ b/src/socket_poller.cpp @@ -130,8 +130,7 @@ int zmq::socket_poller_t::add (socket_base_t *socket_, } } - rc = socket_->add_signaler (signaler); - zmq_assert (rc == 0); + socket_->add_signaler (signaler); } item_t item = {