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

Bill Torpey wallstprog at gmail.com
Wed Oct 31 20:44:04 CET 2018


Hi Martin:

This is just a guess, but it’s an educated guess.  The doc for zmq_socket_monitor says:

>  Each call to this method creates a ZMQ_PAIR socket and binds that to the specified inproc:// endpoint. 


The newly-created socket doesn’t have any connections until you connect to it.  (You probably also want to delete the old socket and create a new one to connect to the monitor endpoint).

I haven’t tested this, but based on what I’ve seen from zmq_socket_monitor this seems worth a try.

Regards,

Bill 

P.S. The blocking behavior on the second connect makes sense also: be careful when using socket monitoring — if you don’t consume monitor events, subsequent operations on the sockets you are monitoring will block.

> On Oct 31, 2018, at 3:26 PM, <Martin.Belanger at dell.com> <Martin.Belanger at dell.com> wrote:
> 
> 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).
> 
> Regards,
> Martin
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20181031/ec2ce9fc/attachment.htm>


More information about the zeromq-dev mailing list