… | |
… | |
8 | |
8 | |
9 | =head1 DESCRIPTION |
9 | =head1 DESCRIPTION |
10 | |
10 | |
11 | Libev is an event loop: you register interest in certain events (such as a |
11 | Libev is an event loop: you register interest in certain events (such as a |
12 | file descriptor being readable or a timeout occuring), and it will manage |
12 | file descriptor being readable or a timeout occuring), and it will manage |
13 | these event sources and provide your program events. |
13 | these event sources and provide your program with events. |
14 | |
14 | |
15 | To do this, it must take more or less complete control over your process |
15 | To do this, it must take more or less complete control over your process |
16 | (or thread) by executing the I<event loop> handler, and will then |
16 | (or thread) by executing the I<event loop> handler, and will then |
17 | communicate events via a callback mechanism. |
17 | communicate events via a callback mechanism. |
18 | |
18 | |
… | |
… | |
25 | |
25 | |
26 | Libev supports select, poll, the linux-specific epoll and the bsd-specific |
26 | Libev supports select, poll, the linux-specific epoll and the bsd-specific |
27 | kqueue mechanisms for file descriptor events, relative timers, absolute |
27 | kqueue mechanisms for file descriptor events, relative timers, absolute |
28 | timers with customised rescheduling, signal events, process status change |
28 | timers with customised rescheduling, signal events, process status change |
29 | events (related to SIGCHLD), and event watchers dealing with the event |
29 | events (related to SIGCHLD), and event watchers dealing with the event |
30 | loop mechanism itself (idle, prepare and check watchers). |
30 | loop mechanism itself (idle, prepare and check watchers). It also is quite |
|
|
31 | fast (see a L<http://libev.schmorp.de/bench.html|benchmark> comparing it |
|
|
32 | to libevent). |
31 | |
33 | |
32 | =head1 CONVENTIONS |
34 | =head1 CONVENTIONS |
33 | |
35 | |
34 | Libev is very configurable. In this manual the default configuration |
36 | Libev is very configurable. In this manual the default configuration |
35 | will be described, which supports multiple event loops. For more info |
37 | will be described, which supports multiple event loops. For more info |
… | |
… | |
39 | argument of name C<loop> (which is always of type C<struct ev_loop *>) |
41 | argument of name C<loop> (which is always of type C<struct ev_loop *>) |
40 | will not have this argument. |
42 | will not have this argument. |
41 | |
43 | |
42 | =head1 TIME AND OTHER GLOBAL FUNCTIONS |
44 | =head1 TIME AND OTHER GLOBAL FUNCTIONS |
43 | |
45 | |
44 | Libev represents time as a single floating point number. This type is |
46 | Libev represents time as a single floating point number, representing the |
|
|
47 | (fractional) number of seconds since the (POSIX) epoch (somewhere near |
|
|
48 | the beginning of 1970, details are complicated, don't ask). This type is |
45 | called C<ev_tstamp>, which is what you should use too. It usually aliases |
49 | called C<ev_tstamp>, which is what you should use too. It usually aliases |
46 | to the double type in C. |
50 | to the double type in C. |
47 | |
51 | |
48 | =over 4 |
52 | =over 4 |
49 | |
53 | |
… | |
… | |
291 | |
295 | |
292 | As long as your watcher is active (has been started but not stopped) you |
296 | As long as your watcher is active (has been started but not stopped) you |
293 | must not touch the values stored in it. Most specifically you must never |
297 | must not touch the values stored in it. Most specifically you must never |
294 | reinitialise it or call its set method. |
298 | reinitialise it or call its set method. |
295 | |
299 | |
296 | You cna check wether an event is active by calling the C<ev_is_active |
300 | You cna check whether an event is active by calling the C<ev_is_active |
297 | (watcher *)> macro. To see wether an event is outstanding (but the |
301 | (watcher *)> macro. To see whether an event is outstanding (but the |
298 | callback for it has not been called yet) you cna use the C<ev_is_pending |
302 | callback for it has not been called yet) you cna use the C<ev_is_pending |
299 | (watcher *)> macro. |
303 | (watcher *)> macro. |
300 | |
304 | |
301 | Each and every callback receives the event loop pointer as first, the |
305 | Each and every callback receives the event loop pointer as first, the |
302 | registered watcher structure as second, and a bitset of received events as |
306 | registered watcher structure as second, and a bitset of received events as |
… | |
… | |
398 | This section describes each watcher in detail, but will not repeat |
402 | This section describes each watcher in detail, but will not repeat |
399 | information given in the last section. |
403 | information given in the last section. |
400 | |
404 | |
401 | =head2 struct ev_io - is my file descriptor readable or writable |
405 | =head2 struct ev_io - is my file descriptor readable or writable |
402 | |
406 | |
403 | I/O watchers check wether a file descriptor is readable or writable |
407 | I/O watchers check whether a file descriptor is readable or writable |
404 | in each iteration of the event loop (This behaviour is called |
408 | in each iteration of the event loop (This behaviour is called |
405 | level-triggering because you keep receiving events as long as the |
409 | level-triggering because you keep receiving events as long as the |
406 | condition persists. Remember you cna stop the watcher if you don't want to |
410 | condition persists. Remember you cna stop the watcher if you don't want to |
407 | act on the event and neither want to receive future events). |
411 | act on the event and neither want to receive future events). |
408 | |
412 | |
… | |
… | |
465 | state where you do not expect data to travel on the socket, you can stop |
469 | state where you do not expect data to travel on the socket, you can stop |
466 | the timer, and again will automatically restart it if need be. |
470 | the timer, and again will automatically restart it if need be. |
467 | |
471 | |
468 | =back |
472 | =back |
469 | |
473 | |
470 | =head2 ev_periodic |
474 | =head2 ev_periodic - to cron or not to cron it |
471 | |
475 | |
472 | Periodic watchers are also timers of a kind, but they are very versatile |
476 | Periodic watchers are also timers of a kind, but they are very versatile |
473 | (and unfortunately a bit complex). |
477 | (and unfortunately a bit complex). |
474 | |
478 | |
475 | Unlike ev_timer's, they are not based on real time (or relative time) |
479 | Unlike ev_timer's, they are not based on real time (or relative time) |