[zeromq-dev] some notes on using zmq_poll() with ZMQ_SUB socket

Pavel Gushcha pavimus at gmail.com
Tue Jan 12 15:22:17 CET 2010

Patch works, but i got problem with timeout. When i set timeout to 2
sec and receive each second messages with not matching topics
zmq_poll() will not return after timeout.

2010/1/12 Martin Sustrik <sustrik at 250bpm.com>:
> 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

More information about the zeromq-dev mailing list