[Libevent-users] multiple calls of event_dispatch()

Christian Ress christian at yetisoft.org
Tue Feb 27 14:05:44 EST 2007


Scott Lamb wrote:
> First, keep in mind something that tripped up me when I first started 
> using libevent - the "struct event" you pass to event_add is not 
> duplicated, but rather directly linked into the event_base's queues.

Once you said it I was scared that I've thought differently. That also 
explains why I called event_base_dispatch() again: Without it the event 
loop created in main() would segfault when trying to access the new 
event structure because it was destroyed once the callback block was 
left. When allocating the struct with malloc and using it, it works out 
fine.

> 
> You can create new events 'on demand' with event_once. Which isn't magic 
> - it just internally allocates a new struct event on the heap that adds 
> a callback which - after calling your callback - frees the struct event. 
> You could accomplish the same thing yourself:

event_once seems to be a nice alternative, I'll try around with it.

Thanks to both of you,
Christian



More information about the Libevent-users mailing list