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

Re: [Libevent-users] How to make a eventloop similiar to select() with a timeout of 1sec



Hi Nick,

I think you mis-understood my question, I should clarify.Â

In your example, the loop would run for exactly 1 seconds . and always 1 second, is my understanding right? ÂBut the old behavior in the program that uses select() is: however wait for at most 1 seconds. In a busy server however there should always be some io work to do , thus it returns immediately most of the time.Â

The idea of the old program is that if there is no client around, server could just spend sometime waiting, up to 1 sec, I kinda think this is a useless behavior, so maybe I should instead spend some effort figuring out whether i should discard the this behavior instead.

Thanks.


On Mon, Jun 24, 2013 at 6:41 AM, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
On Mon, Jun 24, 2013 at 9:36 AM, åéé <sunyucong@xxxxxxxxx> wrote:
> Thanks for the reply. but without EV_LOOPONCE , how could i make it not
> always wait the whole 1 sec?

"Instead, I'd suggest making a one-second timer event with a callback
Âthat uses event_base_loopexit(g_event_base, NULL) to exit the event
loop."

Something like this:

void exit_after_one_second(evutil_socket_t fd, short events, void *arg)
{
 event_base_loopexit(arg, NULL);
}

int run_for_one_second(struct event_base *base)
{
 int r;
 struct event *ev;
 struct timeval >
 ev = evtimer_new(base, exit_after_one_second, base);
 event_add(ev, &one_second);
 r = event_base_dispatch(base);
 event_free(ev);
 return r;
}
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users  Âin the body.