[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] event_base_dispatch not returning



Yes, I did the event_add. Was trying to type out from memory.

I didn't realise that event_base_dispatch() doesn't return until all events are finished (which is never, in my case, since all of my events are persistent and never get deleted). I have three groups of events that I was using, two on timeouts and one like the above. I was using three different event_base's for them, but did a little combing through old threads and found out that's not necessary unless you're multithreading (i'm not), so I consolidated them to one base. With this method, the timeout events are firing, but we're still not getting past the call to event_base_dispatch. but if I understand you correctly, that's good behaviour. I've got event_base_dispatch called in the middle of my initialization function, but I suppose moving it to the bottom (ie, the very last thing I do before letting the events drive the program) would do the trick?

That still doesn't answer why the loops were "breaking" prematurely, but it could have something to do with my signal handler - I have one set up for seg faults to break all the loops before exiting, but I'm not sure that was being called before...

Stephen Andrew
Undergraduate, Electrical Engineering
Missouri University of Science and Technology


On Thu, May 22, 2014 at 1:32 PM, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
On Thu, May 22, 2014 at 2:26 PM, Stephen Andrew <sjahf7@xxxxxxx> wrote:
> I'm trying to get an event loop running, using event_base_dispatch. However,
> the function fails to return (blocks)
>
> I had it running, until I changed something in another source file - which
> might be a part of the callback structure.
>
> Here's (sort of) what my code looks like:
>
> ev1 = event_new(base, fd, EV_READ|EV_PERSIST, grab_packet, some_struct)
> event_base_dispatch(base); //this is where it gets stuck

So, assuming that you also do an event_add(ev1, NULL), this code will
ordinarily stay inside event_base_dispatch until there are no more
pending events (that is, until somebody calls event_del(ev1), or until
you call event_base_loopexit, or until you call
event_base_loopbreak(). ÂThe question to answer may be, which of these
cases was making it exit event_base_dispatch() before?

If that doesn't shed light on the problem, I'd try using a debugger to
see whether your program is getting stuck in event_base_dispatch, and
if so, which of the conditions that should be making
event_base_dispatch exit isn't happening.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users  Âin the body.