[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
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 one_second = {1,0};
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.