… | |
… | |
4 | <head> |
4 | <head> |
5 | <title>libev</title> |
5 | <title>libev</title> |
6 | <meta name="description" content="Pod documentation for libev" /> |
6 | <meta name="description" content="Pod documentation for libev" /> |
7 | <meta name="inputfile" content="<standard input>" /> |
7 | <meta name="inputfile" content="<standard input>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
9 | <meta name="created" content="Tue Nov 27 20:38:24 2007" /> |
9 | <meta name="created" content="Tue Nov 27 21:14:27 2007" /> |
10 | <meta name="generator" content="Pod::Xhtml 1.57" /> |
10 | <meta name="generator" content="Pod::Xhtml 1.57" /> |
11 | <link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head> |
11 | <link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head> |
12 | <body> |
12 | <body> |
13 | <div class="pod"> |
13 | <div class="pod"> |
14 | <!-- INDEX START --> |
14 | <!-- INDEX START --> |
… | |
… | |
66 | <p>libev - a high performance full-featured event loop written in C</p> |
66 | <p>libev - a high performance full-featured event loop written in C</p> |
67 | |
67 | |
68 | </div> |
68 | </div> |
69 | <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p> |
69 | <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p> |
70 | <div id="SYNOPSIS_CONTENT"> |
70 | <div id="SYNOPSIS_CONTENT"> |
|
|
71 | <pre> /* this is the only header you need */ |
71 | <pre> #include <ev.h> |
72 | #include <ev.h> |
|
|
73 | |
|
|
74 | /* what follows is a fully working example program */ |
|
|
75 | ev_io stdin_watcher; |
|
|
76 | ev_timer timeout_watcher; |
|
|
77 | |
|
|
78 | /* called when data readable on stdin */ |
|
|
79 | static void |
|
|
80 | stdin_cb (EV_P_ struct ev_io *w, int revents) |
|
|
81 | { |
|
|
82 | /* puts ("stdin ready"); */ |
|
|
83 | ev_io_stop (EV_A_ w); /* just a syntax example */ |
|
|
84 | ev_unloop (EV_A_ EVUNLOOP_ALL); /* leave all loop calls */ |
|
|
85 | } |
|
|
86 | |
|
|
87 | static void |
|
|
88 | timeout_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
89 | { |
|
|
90 | /* puts ("timeout"); */ |
|
|
91 | ev_unloop (EV_A_ EVUNLOOP_ONE); /* leave one loop call */ |
|
|
92 | } |
|
|
93 | |
|
|
94 | int |
|
|
95 | main (void) |
|
|
96 | { |
|
|
97 | struct ev_loop *loop = ev_default_loop (0); |
|
|
98 | |
|
|
99 | /* initialise an io watcher, then start it */ |
|
|
100 | ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ); |
|
|
101 | ev_io_start (loop, &stdin_watcher); |
|
|
102 | |
|
|
103 | /* simple non-repeating 5.5 second timeout */ |
|
|
104 | ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); |
|
|
105 | ev_timer_start (loop, &timeout_watcher); |
|
|
106 | |
|
|
107 | /* loop till timeout or data ready */ |
|
|
108 | ev_loop (loop, 0); |
|
|
109 | |
|
|
110 | return 0; |
|
|
111 | } |
72 | |
112 | |
73 | </pre> |
113 | </pre> |
74 | |
114 | |
75 | </div> |
115 | </div> |
76 | <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p> |
116 | <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p> |