… | |
… | |
132 | .TH "<STANDARD INPUT>" 1 "2007-11-27" "perl v5.8.8" "User Contributed Perl Documentation" |
132 | .TH "<STANDARD INPUT>" 1 "2007-11-27" "perl v5.8.8" "User Contributed Perl Documentation" |
133 | .SH "NAME" |
133 | .SH "NAME" |
134 | libev \- a high performance full\-featured event loop written in C |
134 | libev \- a high performance full\-featured event loop written in C |
135 | .SH "SYNOPSIS" |
135 | .SH "SYNOPSIS" |
136 | .IX Header "SYNOPSIS" |
136 | .IX Header "SYNOPSIS" |
137 | .Vb 1 |
137 | .Vb 2 |
|
|
138 | \& /* this is the only header you need */ |
138 | \& #include <ev.h> |
139 | \& #include <ev.h> |
|
|
140 | .Ve |
|
|
141 | .PP |
|
|
142 | .Vb 3 |
|
|
143 | \& /* what follows is a fully working example program */ |
|
|
144 | \& ev_io stdin_watcher; |
|
|
145 | \& ev_timer timeout_watcher; |
|
|
146 | .Ve |
|
|
147 | .PP |
|
|
148 | .Vb 8 |
|
|
149 | \& /* called when data readable on stdin */ |
|
|
150 | \& static void |
|
|
151 | \& stdin_cb (EV_P_ struct ev_io *w, int revents) |
|
|
152 | \& { |
|
|
153 | \& /* puts ("stdin ready"); */ |
|
|
154 | \& ev_io_stop (EV_A_ w); /* just a syntax example */ |
|
|
155 | \& ev_unloop (EV_A_ EVUNLOOP_ALL); /* leave all loop calls */ |
|
|
156 | \& } |
|
|
157 | .Ve |
|
|
158 | .PP |
|
|
159 | .Vb 6 |
|
|
160 | \& static void |
|
|
161 | \& timeout_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
162 | \& { |
|
|
163 | \& /* puts ("timeout"); */ |
|
|
164 | \& ev_unloop (EV_A_ EVUNLOOP_ONE); /* leave one loop call */ |
|
|
165 | \& } |
|
|
166 | .Ve |
|
|
167 | .PP |
|
|
168 | .Vb 4 |
|
|
169 | \& int |
|
|
170 | \& main (void) |
|
|
171 | \& { |
|
|
172 | \& struct ev_loop *loop = ev_default_loop (0); |
|
|
173 | .Ve |
|
|
174 | .PP |
|
|
175 | .Vb 3 |
|
|
176 | \& /* initialise an io watcher, then start it */ |
|
|
177 | \& ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ); |
|
|
178 | \& ev_io_start (loop, &stdin_watcher); |
|
|
179 | .Ve |
|
|
180 | .PP |
|
|
181 | .Vb 3 |
|
|
182 | \& /* simple non-repeating 5.5 second timeout */ |
|
|
183 | \& ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); |
|
|
184 | \& ev_timer_start (loop, &timeout_watcher); |
|
|
185 | .Ve |
|
|
186 | .PP |
|
|
187 | .Vb 2 |
|
|
188 | \& /* loop till timeout or data ready */ |
|
|
189 | \& ev_loop (loop, 0); |
|
|
190 | .Ve |
|
|
191 | .PP |
|
|
192 | .Vb 2 |
|
|
193 | \& return 0; |
|
|
194 | \& } |
139 | .Ve |
195 | .Ve |
140 | .SH "DESCRIPTION" |
196 | .SH "DESCRIPTION" |
141 | .IX Header "DESCRIPTION" |
197 | .IX Header "DESCRIPTION" |
142 | Libev is an event loop: you register interest in certain events (such as a |
198 | Libev is an event loop: you register interest in certain events (such as a |
143 | file descriptor being readable or a timeout occuring), and it will manage |
199 | file descriptor being readable or a timeout occuring), and it will manage |