Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Improved and simplified libuev API proposal
- * troglobit@gmail.com
- */
- uev_ctx_init()
- uev_run() /* Start a ctx w/ registered watchers */
- uev_exit() /* Stop a ctx and free all kernel resources, close descriptors, etc. */
- uev_timer_init() /* Initialize a uev_t timer watcher with callback and optional arg. */
- uev_timer_set() /* Re-set new timeout/period time */
- uev_timer_start() /* Actually allocate kernel resource and register with context/epoll */
- uev_timer_stop() /* Free kernel resource and deregister with the context/epoll */
- uev_io_init() /* Initialize a uev_t I/O watcher */
- uev_io_set()
- uev_io_poll() /* Like uev_timer_start() above */
- uev_io_cancel() /* Like uev_timer_stop() above */
- uev_signal_init() /* Initialize a uev_t signal watcher */
- uev_signal_set()
- uev_signal_wait()
- uev_signal_cancel()
- /****** EXAMPLE
- ****** Nota bene, the below example is only pseudo code ... it's also a very stupid example.
- ******/
- int main()
- {
- uev_t timer, file;
- uev_ctx_t ctx;
- uev_ctx_init(&ctx);
- /* Create and connect event watchers to a given context */
- uev_timer_init(&ctx, &timer, timer_cb, NULL, 1000, 1000);
- uev_io_init(&ctx, &file, read_cb, &timer);
- /* Here is where timers are actually started */
- uev_timer_start(&timer);
- uev_io_poll(&file);
- /* Enter event loop */
- uev_run(&ctx);
- }
- read_cb()
- {
- uev_t *timer = (uev_t *)arg;
- /* Stop a timer */
- uev_timer_stop(timer);
- /* Start timer with new timeout */
- uev_timer_set(timer, 2000, 2000);
- /* Since the loop is already running, and the timer event already
- * connected to a context, it will be started immediately.
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement