[zeromq-dev] How do I close one pair of a multiply-connected socket?

Kim Lester kim at dfusion.com.au
Mon Jul 25 17:14:40 CEST 2011

I have code that executes the statement
	zmq_connect(s, remote_endpoint);
multiple times to create a multiple-endpoint event receiver.
It works well.

How however I have one situation where, for efficiency, I want to not-receive events from certain endpoints.

Context: I only need to listen to events from a particular endpoint periodically (say for 30 seconds per day) however that endpoint may create dozens of events per second. This is not large numbers I know but the thread in question is _really_ busy receiving thousands of other packets/sec and I don't want to bother it with unnecessary work. It's a matter of both principle and practice.

The solution that feels correct is to open/close the endpoint pair in question as required (given the large ratio of ignored:interested time) whilst leaving other endpoints connected to "s" open. However zmq_close(s) will close the whole socket.
What I perceive I want is a "zmq_disconnect(s, remote_endpoint)" function to complement the added zmq_socket functionality.

I don't think zmq_subscribe/unsubscribe will work in my particular case. Besides that I suspect adding subscribe filter(s) would slow down performance slightly and anyway the unwanted packets will have already been received and partially processed, wasting CPU resources.

I don't want to create a separate endpoint just for this connection as it breaks my own API model/code.

Closing all with zmq_close(s) and reopening n-1 is not elegant and will miss events.

If you want to claim the impact of receiving and discarding a message is insignificant you would need to justify it well, bearing in mind my application has constrained CPU resources and if I took the "ignore it" approach throughout my application it wouldn't run at all....

My question: How do I close just one endpoint-pair?

Couldn't see anything obvious in the manuals.

Have I missed something ?
Should thre be a zmq_disconnect(pair) call ?
What is the best solution ?


More information about the zeromq-dev mailing list