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

Re: Re: [Libevent-users] Destroying event from callback function



why not replace the following struct with args?

typedef struct {
struct event *evt;
void *otherargs;
} Parameter;
Parameter *p = malloc(xx)
evt = event_new(xxx, p);
p->evt = evt;

...

-Song

On , MichaÅ KrÃl <mharnen@xxxxxxxxx> wrote:
> Hi!
>
> Thanks for your response. Unfortunately I want to invoke this event more then once, and stop invoking after particular condition occurs, so it's more like:
>
> void cb_func(agrs){
>
> ÂÂÂ //do some work
>
> ÂÂÂÂ if(cond)
> ÂÂÂÂÂÂÂÂ event_del(event);
> ÂÂÂ
> }
>
> 2011/4/7 èæ jaxecn@xxxxxxxxx>
>
> hi,maybe you callÂevent_new without the flag of EV_PERSISTENT,so when cb_func is triggered ,the event isÂautomaticÂdeleted by event_base_loop,it's seems there is two ev_del calls in  your example ,forgive my pool english..
>
>
>
>
> 2011/4/7 MichaÅ KrÃl mharnen@xxxxxxxxx>
>
>
> Hi,
>
> I was wondering if there is any way I can access event object within callback function in libevent2? I know I can put it in global variable, but I'll have a lot of events and I want to access particular one, so I want to avoid it.
>
>
>
>
> I cannot pass it as an argument because I'll have pointer to event structure after setting callback in evet_new.
>
> To be precise I want to do something like this:
>
>
> int main(){
> ÂÂÂÂ event = event_new(base, socket, flags, cb_func, args);
>
>
>
>
> ÂÂÂÂ event_add(event);
> }
>
> void cb_func(args){
>
> ÂÂÂÂ //do some work
>
> ÂÂÂÂ event_del(event);Â
>
> Thanks in advance
>
>
>
>
> Michal
>
>
>
>
>
>
>
>
>
>
>
>
>
>