Discussion:
event_base_dispatch not returning
(too old to reply)
Stephen Andrew
2014-05-22 18:26:27 UTC
Permalink
Raw Message
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

void grab_packet()
{
...
...
some_other_func();
}

some_other_Func()
{
...
...
yet_another_func();
}

yet_another_func()
{
//changes here caused event_base_dispatch to start blocking
}

Sorry the code is sketchy, but I don't know if I'm authorized to give out
the details of it.

Has anyone else had this problem?

Stephen Andrew
Undergraduate, Electrical Engineering
Missouri University of Science and Technology
Nick Mathewson
2014-05-22 18:32:37 UTC
Permalink
Raw Message
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.
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 ***@freehaven.net with
unsubscribe libevent-users in the body.
Stephen Andrew
2014-05-22 18:43:59 UTC
Permalink
Raw Message
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
Post by Stephen Andrew
Post by Stephen Andrew
I'm trying to get an event loop running, using event_base_dispatch.
However,
Post by Stephen Andrew
the function fails to return (blocks)
I had it running, until I changed something in another source file -
which
Post by Stephen Andrew
might be a part of the callback structure.
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.
***********************************************************************
unsubscribe libevent-users in the body.
Loading...