AnyEvent->loop?

Marc Lehmann schmorp at schmorp.de
Thu Feb 17 02:04:26 CET 2011


On Wed, Feb 16, 2011 at 06:34:08PM +0000, Steve Freegard <steve.freegard at fsl.com> wrote:
> Ok - I'm working on some patches for qpsmtpd (http://smtpd.develooper.com) as someone posted an AnyEvent personality of qpsmtpd to the mailing list.  So this is another standalone program use for AnyEvent.  

it would help, btw., if you didn't create overly long lines in your
e-mail, it makes it rather hard to read. (or tell your MUA to use a proper
content type for these long one-line-paragraphs).

> I was basically using the condvar as a merge point and had it in my mind
> was that this is like a 'yield back to the event loop until the result
> is returned'.

This works, when you use (coro) threads to wait. It cannot work without
them, as "yielding back" would jump where, and return how?

> The only place the a condvar is used is here and in the accept_loop()
> as this is the first plugin I've attempted to convert.  Hence why I
> was surprised at the 'recursive blocking wait detected at ..' and had
> put it down to not calling the real event loop instead of the mainloop
> emulation.

It caught a bug in your code...

> The above code works fine if I call EV::loop instead of
> AnyEvent->condvar->recv in accept_loop.  So do I need to use Coro in
> this case? (an example would be helpful if so).

No, it doesn't work fine at all, all it does is not catch the bug.

Your code recurses in condvars - imagine what happens when you get another
connection while in starttls - you recurse at thatpoint. When you get
enough concurrent connections your callstack will overflow.

Or in more detail: when you run $cv->recv, something will run the event
loop. If the event loop then detects another connection, it will call your
watcher callback, which might call starttls again at some point, at which
point you will have another invocation of the loop, and so on.

And if there is another such place in the code elsewhere, the problem
multiplies.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list