Skip to content

Commit

Permalink
Ignore ENOENT during zmq_disconnect call (fixes tango-controls#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
mliszcz committed Jan 26, 2019
1 parent 07eea09 commit 6c67f23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions cppapi/client/eventconsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ private :
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(int hwm);
static void disconnect_socket(zmq::socket_t&, const char*);

bool check_zmq_endpoint(const string &);

Expand Down
20 changes: 18 additions & 2 deletions cppapi/client/zmqeventconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_
if (pos != connected_heartbeat.end())
connected_heartbeat.erase(pos);

heartbeat_sub_sock->disconnect(endpoint);
disconnect_socket(*heartbeat_sub_sock, endpoint);

//
// Remove the event endpoint from the already connected event and disconnect the event socket
Expand All @@ -843,7 +843,7 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_
if (pos != connected_pub.end())
{
connected_pub.erase(pos);
event_sub_sock->disconnect(endpoint_event);
disconnect_socket(*event_sub_sock, endpoint_event);
}
#endif
}
Expand Down Expand Up @@ -3546,6 +3546,22 @@ ReceivedFromAdmin ZmqEventConsumer::initialize_received_from_admin(const Tango::
return result;
}

void ZmqEventConsumer::disconnect_socket(zmq::socket_t& socket, const char* endpoint)
{
try
{
socket.disconnect(endpoint);
}
catch (const zmq::error_t& e)
{
// Silently ignore ENOENT as it indicates that endpoint is already disconnected.
if (e.num() != ENOENT)
{
throw;
}
}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method :
Expand Down

0 comments on commit 6c67f23

Please sign in to comment.