[zeromq-dev] ZMQ_FD with request sockets

Francois-Xavier Bourlet fx at dotcloud.com
Fri Dec 9 01:44:10 CET 2011


On Thu, Dec 8, 2011 at 4:22 PM, Chuck Remes <cremes.devlist at mac.com> wrote:
>
> On Dec 8, 2011, at 6:14 PM, Francois-Xavier Bourlet wrote:
>
>> You don't need to call recv right after any send, but when you want to
>> receive something, you need to call recv before trying to wait for any
>> events. In the case recv failed with a tryagain error, you can then
>> wait for an event.
>
> This isn't correct. You should be able to call zmq_poll() on the socket and detect any read/write events.
>

zmq_poll on a readable ZMQ socket will simply return in the second to
let you read the socket, while waiting on an ZMQ_FD will only return
when the socket change from a non-readable or non-writable state to
the corresponding readable/writable one.

> ZMQ_FD is a bit tricky. Even if it returns that there was an event, you *must* check the socket with ZMQ_EVENTS to determine if it was a read or write event. Sometimes it is neither because the library uses that FD to signal some internal things too. That's why it is important to check the event with ZMQ_EVENTS.
>

Agreed that you should always check ZMQ_EVENTS when you get any events
on the ZMQ_FD socket.

> Also, as Francois correctly stated earlier in this thread, zmq_poll() is edge triggered. What this means in practice is that once you receive an event on a socket, you *must* process all *messages* on that socket before zmq_poll() will trigger it again.
>

zmq_poll work directly on ZMQ sockets and doesnt have the
edge-trigerred behavior (zmq_pool on readable socket will simply
return instantaneously with ready to read socket).

> cr
>

PS: my firstname is François-Xavier, or FX :)

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



-- 
François-Xavier Bourlet



More information about the zeromq-dev mailing list