[zeromq-dev] question about integrating zmq socket fd in external select() loop

Chuck Remes lists at chuckremes.com
Mon Aug 6 20:21:55 CEST 2012


Answers are inline.

On Aug 6, 2012, at 11:18 AM, diffuser78 wrote:

> Can someone plz share their experiences around this problem ?
> 
> On Fri, Aug 3, 2012 at 3:38 PM, diffuser78 <diffuser78 at gmail.com> wrote:
> Hi,
>  
> I am writing a lib that uses zmq. This lib is going to be used in an app that already has an external select() loop. Can I use fd's retrieved from ZMQ_FD from zmq_getsockopt() in that select loop successfully ?

Yes, you can. Be sure to read and reread the man page for it though. When you get a signal on your file descriptor, it is *edge* triggered. You must check to see if any messages actually arrived by using the ZMQ_EVENTS option. Then, if there is a message waiting, you must read *all* messages from the queue until you get EAGAIN. This resets the FD so that it can trigger again.

If you do not read all of the messages from the queue, the FD will never trigger again.

>  
> Are there examples already that tell you how to do it ? Are there any things that I should know ?
>  
> I read FAQ section related zmq_poll and also saw man zmq_getsocketopt for ZMQ_FD.
>  
> I wanted to know the persoanl experience of some developer around this.

For examples, you should look at the tests/specs for various language bindings. Most of them at least try to test this functionality to verify the library is hooked up properly.

You could also search github for ZMQ_FD and see what kind of hits you get for code.

cr


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120806/faf977d1/attachment.htm>


More information about the zeromq-dev mailing list