[zeromq-dev] External Event Loop
Praveen Baratam
praveen.baratam+zmq at gmail.com
Wed Jan 26 08:39:39 CET 2011
Hello Jonathan & Martin,
What does it exactly mean? Does the program crash in such case or what? -
Martin
No it does not crash! Just that the poll/epoll will not return any events on
ZMQ_FD.
Here is the schematic that dint work...
1. Create a XREQ socket
2. Set the identity
3. connect to XREP endpoint using inproc transport. (XREP is continuously
sending messages to named XREQ endpoints on another thread)
4. Get the FD through ZMQ_FD
5. create a poll-set and poll for events in a loop
6. Process those events with in the loop
In the above mentioned way poll does not return any events with respect to
FD from ZMQ_FD
Here is a schematic that works
1. Create a XREQ socket
2. Set the identity
3. connect to XREP endpoint using inproc transport. (XREP is continuously
sending messages to named XREQ endpoints on another thread)
*4. Do a non-blocking recv on the socket until EGAIN is returned*
5. Get the FD through ZMQ_FD
6. Create a poll-set and poll for events in a loop
7. Process those events with in the loop
Step 4 was necessary to get any events from poll/epoll on the FD from
ZMQ_FD.
My way is different from that of Jonathan in that I do not create a watcher
on ZMQ_FD when reading from socket returns EAGAIN and destroy it after
getting a callback. I create a watcher during initialization and when ever
there is a callback from the watcher, I do a non-blocking recv on the socket
in a loop until EAGAIN is returned. I only destroy the watcher when i no
longer need the socket in question.
Thank you
Praveen
On Wed, Jan 26, 2011 at 6:53 AM, Jonathan Rockway <jon at jrock.us> wrote:
> * On Tue, Jan 25 2011, Martin Sustrik wrote:
> > Hi Praveen,
> >
> >> Actually when sockets are created and bound/connected they are not ready
> >> for polling using ZMQ_FD.
> >
> > What does it exactly mean? Does the program crash in such case or what?
>
> Also, FWIW, I do not get this behavior with 2.1.0+ (and haven't tried it
> with earlier versions, as the docs say it's not going to work anyway).
> I have a somewhat complex set of apps that all communicate via zmq
> running in an EV event loop (with lots of other EV watchers in each
> app), and it all works beautifully; I've never had any problems at all.
> I've written test cases for the various edge cases (trying to write when
> ZMQ_HWM + ZMQ_SNDBUF are hit), and everything works fine. (In that
> case, ZMQ_EVENTS indicates no writability, so I make a write watcher,
> when the watcher is activated, I check ZMQ_EVENTS again, and then try
> the write if writability is indicated. This always works.)
>
> What I have not done is try this with zmq < 2.1.0, or read the code for
> that. (I've looked at the ZMQ_FD + ZMQ_EVENTS related code in the git
> version, and it all works like I would expect.) Is ZMQ_FD even supposed
> to be used for external event loops pre-2.1.0?
>
> (I'm confused because I've read the mongrel2 source code, and still
> don't really understand how Zed integrates ZMQ into his superpoll event
> loop. But it works really well, so I'll assume that I'm missing some
> detail there.)
>
> Regards,
> Jonathan Rockway
>
> --
> print just => another => perl => hacker => if $,=$"
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110126/7e883dd9/attachment.htm>
More information about the zeromq-dev
mailing list