[zeromq-dev] full duplex asynch messaging

Martin Sustrik sustrik at 250bpm.com
Sun Apr 10 08:12:08 CEST 2011


Hi Jared,

> I know that this post is quite old, but I have a question regarding this method
> of polling.
>
> If I poll for OUT, won't it immediately return the event for that socket if it's
> able to be written without blocking?
>
> It seems like this would more or less act like a busy-wait.  You would poll, any
> socket that can write non-blocking would fire immediately, and we would then
> check the queue to identify if a message should be written.  In the event that
> there is no message to be written, we would re-enter the poll, which would fire
> immediately ...
>
> Is my understanding of this ZMQ behavior correct?

Yes. However, when relaying messages, you should do the following:

1. If both inbound fd and outbound fd are active, pass messages.
2. If only outbound fd is active, POLLIN on inbound fd.
3. If only outbound fd is active, POLLOUT on outbound fd.

For example, have a look here:

https://github.com/zeromq/zeromq2-1/blob/master/src/device.cpp

Martin



More information about the zeromq-dev mailing list