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

[Libevent-users] Putting event on the top of the queue



Hello! 

I'm using event2 libs and i want to know if it is possible to put new event on the top of the queue.

For example, i have next events queue: 

ev1 -> ev2 -> ev3 

While processing ev1 an error occured. Now i want to create new event(err_ev) that will close all application's modules and insert it before ev2. 

ev1 -> err_ev -> ev2-> ev3

So i'll be able to free all allocated data in ev1 and close application "normally". 

Some pseudo-code:

void ScheduleFree()
{
	event *ev;

	ev = event_new(base,-1,EV_TIMEOUT,err_ev,data);               
        event_base_set(base,ev);
}

void ev1()
{
	uint8_t *some_awesome_data = (uint8_t*)malloc(100); 

... do some stuff

	if (error)
	{
		ScheduleFree();
		free(some_awesome_data);
		return;
	}
... do some stuff

	free(some_awesome_data);
}

void err_ev()
{
... stop all modules and free data
	event_base_free(base);
}


Unfortunately, event_new will put ev to end of the queue. Is there any method to put event exactly after ev1? Or may be, is there another solution that avoids such memory leaks? (stl::auto_ptr or boost::scoped_ptr also will not solve this problem)

Thank you, for attention!


***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.