[zeromq-dev] Enable/Disable monitoring with zmq_socket_monitor()

Martin.Belanger at dell.com Martin.Belanger at dell.com
Wed Oct 31 20:26:42 CET 2018

I want to be able to turn on/off monitoring using zmq_socket_monitor().

I turn on monitoring as follows:
  zmq_socket_monitor(sock_to_monitor_p, "inproc://monitor-my-sock", ZMQ_EVENT_ALL)

And I turn it off this way:
  zmq_socket_monitor(sock_to_monitor_p, NULL, 0)

I designed my main process to be configurable. I send messages to it to tell it to turn monitoring on/off in real time.

The first time I turn on monitoring, everything works as expected, i.e. the monitor thread starts receiving events.
When I turn off monitoring, again everything works fine, events are no longer received.
When I try to turn on monitoring again, nothing happens. The monitor thread doesn't receive events.
When I try to turn on monitoring yet again, the API zmq_socket_monitor() just blocks (doesn't return).

Any idea why this is happening?

I looked at function zmq::socket_base_t::monitor() and I can't see anything wrong with it. I see that this function will close the monitor socket when endpoint_=NULL. And it will create a new monitor socket when endpoint_ is not NULL. That function was clearly designed to allow switching monitoring on/off as often as we like. So not sure what is going on here.

By the way, it would be nice if there was a separate API to allow changing the event mask without having to close and open the monitor socket. This way I could change the events back and forth between 0 and ZMQ_EVENT_ALL. That would achieve what I'm trying to do with minimal impact (i.e. no socket closing and re-opening).


More information about the zeromq-dev mailing list