[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
â 24 juin 2013 20:34 CEST, åéé <sunyucong@xxxxxxxxx>Â:
> The server operates in a mode that basically can be described as following:
>
> while(1) {
> do_some_global_stuff();
>
> gather_possible_user_input_and_send_output():
>
> executing_only_one_command_for_each_client_in_sequence();
>
> do_some_other_global_stuff();
> }
Not tested (maybe we cannot pass a NULL callback):
struct event *to = NULL;
do {
if (event_base_got_exit(base) || event_base_got_break(base)) break;
if (to) event_free(to);
/* Do your global stuff here. */
struct timeval one_second = {1,0};
to = evtimer_new(base, NULL, base);
event_add(to, &one_second);
} while (event_base_loop(base, EVLOOP_ONCE) == 0);
event_free(to);
Either there is nothing to do and an event will be triggered by the one
second timeout or there is something to do and you cancel the timeout.
--
panic("Lucy in the sky....");
2.2.16 /usr/src/linux/arch/sparc64/kernel/starfire.c
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.