[zeromq-dev] socket option for number of subscriptions

Matt Weinstein matt_weinstein at yahoo.com
Tue Aug 31 13:29:58 CEST 2010


On Aug 28, 2010, at 9:44 AM, Jon Dyte wrote:

> Hi
>
> I am considering adding a new socket option, in order to get the  
> number
> of subscriptions on the sub side socket.
>
> This is because in the dynamic subscribe/unsubscribe scenario it is
> possible to receive a message whilst in a loop
>
>
> while (true)
> {
>        zmq::message_t msg;
>        sm.recv(&msg);
>        // do an unsubscribe of last remaining subscription for this  
> socket
>
>       // whoops return to the loop and we will block forever
> }
>
> If we could query the number of subscriptions from the socket,
> the program could terminate cleanly.
>
> Thoughts?
>
> Jon
>
It would seem rational to be able to enumerate the subscriptions, but  
there aren't enough args in setsockopt, and a lot of the solutions are  
pretty crufty (like specially formatted buffers).

One thought would be to be able to ship socket info messages:

	// next msg group will have subscriptions	
	s.setsockopt(... ZMQ_RECVSUBS ...)

	for (;;) {
		...
		s.recv(&msg); // get a subscription
		...
		if (! more)
			break;
	}

Haven't looked to see how ugly this would be.

Perhaps set/getsockopt are obsolete, maybe message based control is  
the future :-) ---

		// per context control ?
		ctl_socket = zmq_socket(ctx, ZMQ_CTXCTL);
		...
		zmq_identity(socket, ... ...);	// get my socket's identity
		...
		zmq_send(ctl_socket,  ... command ..., ZMQ_SNDMORE);
		zmq_send(ctl_socket, ... identity ..., ZMQ_SNDMORE);
		zmq_send(ctl_socket,  ... arg1 ..., ZMQ_SNDMORE);
		zmq_send(ctl_socket,  ... arg2 ..., 0);

		for (;;) {
			// get responses....
			zmq_recv(ctl_socket, &msg, 0);
			...
			// do something useful
			...
			if (! more)
				break;
		}

This looks pretty easy to wrap, is generalizable, stays in the  
paradigm, and I can't *wait* to write the DEVICE for this one :-)

Anyway, those are thoughts ;-)

Best.

Matt

> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

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


More information about the zeromq-dev mailing list