Thanks for the reply. but without EV_LOOPONCE , how could i make it not
always wait the whole 1 sec?

i can put an loopbreak in all the possible registered events but that seems
rather hacky.
On Jun 24, 2013 5:44 AM, "Nick Mathewson" <ni...@freehaven.net> wrote:

> On Mon, Jun 24, 2013 at 3:52 AM, 叶雨飞 <sunyuc...@gmail.com> wrote:
> > Hi,
> >
> > I am trying to convert a select() based program into using libevent, but
> i
> > am having trouble to construct a way to do exactly like
> >
> > select() with a timeout of 1 second.
> >
> > basically I want to wait for as long as 1 second of possible events and
> move
> > on to do other stuff in while(1) loop.
> >
> > I tried :
> >
> >         event_base_loopexit(g_event_base, &timeout);
> >         event_base_loop(g_event_base, EVLOOP_ONCE);
> >
> >
> > But I found that after several successful event triggers, the loop became
> > shorter and shorter, Eg. after one event succesffuly triggered, the loop
> > actually ran only 0.5 seconds next time, next time it is roughly 0.25
> > seconds.The more events have triggered once, the faster the loop became.
> >
> > Any idea what to do? And If I was doing it wrong, what is the right way?
>
> EVLOOP_ONCE means "exit right after processing the first batch of
> events", so you probably don't want that one.  And the
> event_base_loopexit() calls will start to stack up: each one creates a
> new one-time event that makes the loop exit.
>
> 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.
>
> yrs,
> --
> Nick
> ***********************************************************************
> To unsubscribe, send an e-mail to majord...@freehaven.net with
> unsubscribe libevent-users    in the body.
>

Reply via email to