From 83f41526c9413e27ebea9d9c291065ff7d26c205 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 15 Aug 2018 12:18:18 +0200 Subject: [PATCH] Problem: code duplication around options_t::conflate Solution: extract functionality into get_effective_conflate_option --- src/ctx.cpp | 10 +--------- src/options.hpp | 9 +++++++++ src/session_base.cpp | 6 +----- src/socket_base.cpp | 12 ++---------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/ctx.cpp b/src/ctx.cpp index c7ffb47d..39ebb3c5 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -617,15 +617,7 @@ void zmq::ctx_t::connect_inproc_sockets ( errno_assert (rc == 0); } - bool conflate = - pending_connection_.endpoint.options.conflate - && (pending_connection_.endpoint.options.type == ZMQ_DEALER - || pending_connection_.endpoint.options.type == ZMQ_PULL - || pending_connection_.endpoint.options.type == ZMQ_PUSH - || pending_connection_.endpoint.options.type == ZMQ_PUB - || pending_connection_.endpoint.options.type == ZMQ_SUB); - - if (!conflate) { + if (!get_effective_conflate_option (pending_connection_.endpoint.options)) { pending_connection_.connect_pipe->set_hwms_boost (bind_options_.sndhwm, bind_options_.rcvhwm); pending_connection_.bind_pipe->set_hwms_boost ( diff --git a/src/options.hpp b/src/options.hpp index bc61d85f..b591e961 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -268,6 +268,15 @@ struct options_t std::map app_metadata; }; +inline bool get_effective_conflate_option (const options_t &options) +{ + // conflate is only effective for some socket types + return options.conflate + && (options.type == ZMQ_DEALER || options.type == ZMQ_PULL + || options.type == ZMQ_PUSH || options.type == ZMQ_PUB + || options.type == ZMQ_SUB); +} + int do_getsockopt (void *const optval_, size_t *const optvallen_, const void *value_, diff --git a/src/session_base.cpp b/src/session_base.cpp index 364ee37d..b66f1fa6 100644 --- a/src/session_base.cpp +++ b/src/session_base.cpp @@ -394,11 +394,7 @@ void zmq::session_base_t::process_attach (i_engine *engine_) object_t *parents[2] = {this, _socket}; pipe_t *pipes[2] = {NULL, NULL}; - bool conflate = - options.conflate - && (options.type == ZMQ_DEALER || options.type == ZMQ_PULL - || options.type == ZMQ_PUSH || options.type == ZMQ_PUB - || options.type == ZMQ_SUB); + const bool conflate = get_effective_conflate_option (options); int hwms[2] = {conflate ? -1 : options.rcvhwm, conflate ? -1 : options.sndhwm}; diff --git a/src/socket_base.cpp b/src/socket_base.cpp index dbdc021a..7b2e7bc4 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -703,11 +703,7 @@ int zmq::socket_base_t::connect (const char *addr_) object_t *parents[2] = {this, peer.socket == NULL ? this : peer.socket}; pipe_t *new_pipes[2] = {NULL, NULL}; - const bool conflate = - options.conflate - && (options.type == ZMQ_DEALER || options.type == ZMQ_PULL - || options.type == ZMQ_PUSH || options.type == ZMQ_PUB - || options.type == ZMQ_SUB); + const bool conflate = get_effective_conflate_option (options); int hwms[2] = {conflate ? -1 : sndhwm, conflate ? -1 : rcvhwm}; bool conflates[2] = {conflate, conflate}; @@ -942,11 +938,7 @@ int zmq::socket_base_t::connect (const char *addr_) object_t *parents[2] = {this, session}; pipe_t *new_pipes[2] = {NULL, NULL}; - const bool conflate = - options.conflate - && (options.type == ZMQ_DEALER || options.type == ZMQ_PULL - || options.type == ZMQ_PUSH || options.type == ZMQ_PUB - || options.type == ZMQ_SUB); + const bool conflate = get_effective_conflate_option (options); int hwms[2] = {conflate ? -1 : options.sndhwm, conflate ? -1 : options.rcvhwm};