From cecd0705f4abef5f14746852e4762d359a37a611 Mon Sep 17 00:00:00 2001 From: Reynald Bourtembourg Date: Tue, 10 Apr 2018 16:15:20 +0200 Subject: [PATCH 1/2] Set the ZMQ Receive Buffer High Water Mark only if it changes (#444) This is to reduce the impact of a bug present in ZMQ 4.2.0 and ZMQ 4.2.1 which led to a bad lwm and hwm calculation when ZMQ_RCVHWM was set after the bind of the socket. See cppTango#444 for more details --- cppapi/client/zmqeventconsumer.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cppapi/client/zmqeventconsumer.cpp b/cppapi/client/zmqeventconsumer.cpp index 42a604da4..5750ceb28 100644 --- a/cppapi/client/zmqeventconsumer.cpp +++ b/cppapi/client/zmqeventconsumer.cpp @@ -886,7 +886,17 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_ if (connect_pub == true) { - event_sub_sock->setsockopt(ZMQ_RCVHWM,&sub_hwm,sizeof(sub_hwm)); + int current_sub_hwm = SUB_HWM; + size_t curr_sub_hw_size = sizeof(current_sub_hwm); + event_sub_sock->getsockopt(ZMQ_RCVHWM,¤t_sub_hwm, &curr_sub_hw_size); + if(sub_hwm != current_sub_hwm) + { + // Set the ZMQ Receive Buffer High Water Mark only if it changes + // This is to reduce the impact of a bug present in ZMQ 4.2.0 and ZMQ 4.2.1 + // which leads to a bad lwm and hwm calculation when ZMQ_RCVHWM is set after + // the bind of the socket. See cppTango#444 for more details + event_sub_sock->setsockopt(ZMQ_RCVHWM, &sub_hwm, sizeof(sub_hwm)); + } event_sub_sock->connect(endpoint); if (force_connect == 0) From a302d7aaa75c79f6ee4f8d433e0911105579f067 Mon Sep 17 00:00:00 2001 From: Reynald Bourtembourg Date: Fri, 4 May 2018 10:21:41 +0200 Subject: [PATCH 2/2] Add ZmqEventConsumer::set_socket_hwm() method --- cppapi/client/eventconsumer.h | 1 + cppapi/client/zmqeventconsumer.cpp | 32 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cppapi/client/eventconsumer.h b/cppapi/client/eventconsumer.h index 57c15007f..21acbd101 100644 --- a/cppapi/client/eventconsumer.h +++ b/cppapi/client/eventconsumer.h @@ -638,6 +638,7 @@ private : void print_error_message(const char *mess) {ApiUtil *au=ApiUtil::instance();au->print_error_message(mess);} void set_ctrl_sock_bound() {sock_bound_mutex.lock();ctrl_socket_bound=true;sock_bound_mutex.unlock();} bool is_ctrl_sock_bound() {bool _b;sock_bound_mutex.lock();_b=ctrl_socket_bound;sock_bound_mutex.unlock();return _b;} + void set_socket_hwm(size_t hwm); bool check_zmq_endpoint(const string &); diff --git a/cppapi/client/zmqeventconsumer.cpp b/cppapi/client/zmqeventconsumer.cpp index 5750ceb28..53ef557e3 100644 --- a/cppapi/client/zmqeventconsumer.cpp +++ b/cppapi/client/zmqeventconsumer.cpp @@ -886,17 +886,7 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_ if (connect_pub == true) { - int current_sub_hwm = SUB_HWM; - size_t curr_sub_hw_size = sizeof(current_sub_hwm); - event_sub_sock->getsockopt(ZMQ_RCVHWM,¤t_sub_hwm, &curr_sub_hw_size); - if(sub_hwm != current_sub_hwm) - { - // Set the ZMQ Receive Buffer High Water Mark only if it changes - // This is to reduce the impact of a bug present in ZMQ 4.2.0 and ZMQ 4.2.1 - // which leads to a bad lwm and hwm calculation when ZMQ_RCVHWM is set after - // the bind of the socket. See cppTango#444 for more details - event_sub_sock->setsockopt(ZMQ_RCVHWM, &sub_hwm, sizeof(sub_hwm)); - } + set_socket_hwm(sub_hwm); event_sub_sock->connect(endpoint); if (force_connect == 0) @@ -3507,6 +3497,26 @@ void ZmqEventConsumer::get_subscribed_event_ids(DeviceProxy *_dev,vector &_ } } +/** + * + * Set the ZMQ Receive Buffer High Water Mark only if it changes + * This is to reduce the impact of a bug present in ZMQ 4.2.0 and ZMQ 4.2.1 + * which leads to a bad lwm and hwm calculation when ZMQ_RCVHWM is set after + * the bind of the socket. See cppTango#444 for more details + * + * @param hwm: new ZMQ receive buffer high water mark + */ +void ZmqEventConsumer::set_socket_hwm(size_t hwm) +{ + int current_sub_hwm = SUB_HWM; + size_t curr_sub_hw_size = sizeof(current_sub_hwm); + event_sub_sock->getsockopt(ZMQ_RCVHWM,¤t_sub_hwm, &curr_sub_hw_size); + if(hwm != current_sub_hwm) + { + event_sub_sock->setsockopt(ZMQ_RCVHWM, &hwm, sizeof(hwm)); + } +} + //-------------------------------------------------------------------------------------------------------------------- // // method :