[zeromq-dev] blocking

Martin Sustrik sustrik at 250bpm.com
Sun Jan 22 01:32:47 CET 2012


On 21/01/12 23:34, john skaller wrote:
> Which ops in 0MQ can block?
>
> I know these can block:
>
> send/recv/send_msg/recv_msg
> close
> term

These are blocking: send, sendmsg, recv, recvmsg, poll, term.

Note that zmq_close() is never blocking.

> can anything else block?  Most of the other ops would seem to
> work async so don't block, right?
>
> I have to get rid of all blocking ops. This means, for example, that
> when the client says "send", it doesn't actually call zmq_send.
>
> Instead, the request is wrapped up in a struct and put in a queue.
> A separate pthread picks up the request and arranges to service
> it with a non-blocking op and polling. This will actually dispatch
> any I/O to zmq internals running in the zmq_init n pthreads.
>
> The service request mechanism already exists in Felix, and is already
> used for ordinary socket I/O. But stream I/O sucks. We need messages.. :)

Yes. No problem with that. You can either use zmq_poll() for your main 
event loop, or, if you want to use OS's native polling mechanism, you 
can get an file descriptor to poll on using ZMQ_FD option.

Martin



More information about the zeromq-dev mailing list