[zeromq-dev] some notes on using zmq_poll() with ZMQ_SUB socket
Martin Sustrik
sustrik at 250bpm.com
Tue Jan 12 14:45:43 CET 2010
Pavel,
>> I tried to use zmq_poll() on two ZMQ_SUB socket and get strange
>> behaviour. After looking at source code, i understood that i must use
>> non blocking recv() on socket after zmq_poll(). This is because
>> zmq_poll() will return if in ZMQ_SUB socket is message available, but
>> it is not matching to subscribed topics. When after zmq_poll() you use
>> blocking recv() it will filter this non matching message and will wait
>> for another message from only this socket. When you use non blocking
>> recv() you will get EINPROGRESS and you can do zmq_poll() next time.
>>
>> I am right? If so, may be some words can be added to zmq_poll() man
>> page about this usecase?
>
> Yes. You are right. There's even a ticket to fix this behaviour
> (ZMQII-34), so once the problem is fixed zmq_poll won't return POLLIN if
> there's a non-matching message.
>
> What it requires is that on sub_t::xhas_in, messages are read and
> checked whether they pass the filter. If the message matches, it should
> be stored for later retrieval by recv() function. If there are no more
> messages, false should be returned instead.
I've patched this and tested it slightly. Can you try the patch
(attached) and let me know whether it works as you would expect?
Thanks.
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: poll.patch
Type: text/x-patch
Size: 5057 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100112/346990cf/attachment.bin>
More information about the zeromq-dev
mailing list