1LIBEV(3)       libev - high performance full featured event loop      LIBEV(3)
2
3
4

NAME

6       libev - a high performance full-featured event loop written in C
7

SYNOPSIS

9          #include <ev.h>
10
11   EXAMPLE PROGRAM
12          // a single header file is required
13          #include <ev.h>
14
15          #include <stdio.h> // for puts
16
17          // every watcher type has its own typedef'd struct
18          // with the name ev_TYPE
19          ev_io stdin_watcher;
20          ev_timer timeout_watcher;
21
22          // all watcher callbacks have a similar signature
23          // this callback is called when data is readable on stdin
24          static void
25          stdin_cb (EV_P_ ev_io *w, int revents)
26          {
27            puts ("stdin ready");
28            // for one-shot events, one must manually stop the watcher
29            // with its corresponding stop function.
30            ev_io_stop (EV_A_ w);
31
32            // this causes all nested ev_run's to stop iterating
33            ev_break (EV_A_ EVBREAK_ALL);
34          }
35
36          // another callback, this time for a time-out
37          static void
38          timeout_cb (EV_P_ ev_timer *w, int revents)
39          {
40            puts ("timeout");
41            // this causes the innermost ev_run to stop iterating
42            ev_break (EV_A_ EVBREAK_ONE);
43          }
44
45          int
46          main (void)
47          {
48            // use the default event loop unless you have special needs
49            struct ev_loop *loop = EV_DEFAULT;
50
51            // initialise an io watcher, then start it
52            // this one will watch for stdin to become readable
53            ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
54            ev_io_start (loop, &stdin_watcher);
55
56            // initialise a timer watcher, then start it
57            // simple non-repeating 5.5 second timeout
58            ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.);
59            ev_timer_start (loop, &timeout_watcher);
60
61            // now wait for events to arrive
62            ev_run (loop, 0);
63
64            // break was called, so exit
65            return 0;
66          }
67

ABOUT THIS DOCUMENT

69       This document documents the libev software package.
70
71       The newest version of this document is also available as an html-
72       formatted web page you might find easier to navigate when reading it
73       for the first time:
74       <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod>.
75
76       While this document tries to be as complete as possible in documenting
77       libev, its usage and the rationale behind its design, it is not a
78       tutorial on event-based programming, nor will it introduce event-based
79       programming with libev.
80
81       Familiarity with event based programming techniques in general is
82       assumed throughout this document.
83