Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit e76586e

Browse files
authored
Set the ZMQ Receive Buffer High Water Mark only if it changes (#444) (#445)
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
1 parent 401ab50 commit e76586e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cppapi/client/eventconsumer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ private :
638638
void print_error_message(const char *mess) {ApiUtil *au=ApiUtil::instance();au->print_error_message(mess);}
639639
void set_ctrl_sock_bound() {sock_bound_mutex.lock();ctrl_socket_bound=true;sock_bound_mutex.unlock();}
640640
bool is_ctrl_sock_bound() {bool _b;sock_bound_mutex.lock();_b=ctrl_socket_bound;sock_bound_mutex.unlock();return _b;}
641+
void set_socket_hwm(size_t hwm);
641642

642643
bool check_zmq_endpoint(const string &);
643644

cppapi/client/zmqeventconsumer.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_
886886

887887
if (connect_pub == true)
888888
{
889-
event_sub_sock->setsockopt(ZMQ_RCVHWM,&sub_hwm,sizeof(sub_hwm));
889+
set_socket_hwm(sub_hwm);
890890

891891
event_sub_sock->connect(endpoint);
892892
if (force_connect == 0)
@@ -3497,6 +3497,26 @@ void ZmqEventConsumer::get_subscribed_event_ids(DeviceProxy *_dev,vector<int> &_
34973497
}
34983498
}
34993499

3500+
/**
3501+
*
3502+
* Set the ZMQ Receive Buffer High Water Mark only if it changes
3503+
* This is to reduce the impact of a bug present in ZMQ 4.2.0 and ZMQ 4.2.1
3504+
* which leads to a bad lwm and hwm calculation when ZMQ_RCVHWM is set after
3505+
* the bind of the socket. See cppTango#444 for more details
3506+
*
3507+
* @param hwm: new ZMQ receive buffer high water mark
3508+
*/
3509+
void ZmqEventConsumer::set_socket_hwm(size_t hwm)
3510+
{
3511+
int current_sub_hwm = SUB_HWM;
3512+
size_t curr_sub_hw_size = sizeof(current_sub_hwm);
3513+
event_sub_sock->getsockopt(ZMQ_RCVHWM,&current_sub_hwm, &curr_sub_hw_size);
3514+
if(hwm != current_sub_hwm)
3515+
{
3516+
event_sub_sock->setsockopt(ZMQ_RCVHWM, &hwm, sizeof(hwm));
3517+
}
3518+
}
3519+
35003520
//--------------------------------------------------------------------------------------------------------------------
35013521
//
35023522
// method :

0 commit comments

Comments
 (0)