[zeromq-dev] some notes on using zmq_poll() with ZMQ_SUB socket
sustrik at 250bpm.com
Tue Jan 12 12:12:37 CET 2010
> 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.
More information about the zeromq-dev