void helper_start(mowgli_eventloop_helper_proc_t *helper, void *userdata) { mowgli_eventloop_t *eventloop = helper->eventloop; mowgli_writef(helper->fd, "hi from pid %d\n", getpid()); mowgli_timer_add(eventloop, "timer_tick", (mowgli_event_dispatch_func_t *) timer_tick, helper, 1); mowgli_timer_add_once(eventloop, "timer_oneshot", (mowgli_event_dispatch_func_t *) timer_oneshot, helper, 5); mowgli_eventloop_run(eventloop); mowgli_writef(helper->fd, "eventloop halted\n"); mowgli_eventloop_destroy(eventloop); }
void timer_tick(mowgli_eventloop_helper_proc_t *helper) { static int ticks = 0; mowgli_writef(helper->fd, "tick: %d\n", ++ticks); if (ticks > 10) mowgli_eventloop_break(helper->eventloop); }
void timer_oneshot(mowgli_eventloop_helper_proc_t *helper) { mowgli_writef(helper->fd, "oneshot timer hit\n"); }