… | |
… | |
57 | |
57 | |
58 | This module provides an interface to libev |
58 | This module provides an interface to libev |
59 | (L<http://software.schmorp.de/pkg/libev.html>). While the documentation |
59 | (L<http://software.schmorp.de/pkg/libev.html>). While the documentation |
60 | below is comprehensive, one might also consult the documentation of |
60 | below is comprehensive, one might also consult the documentation of |
61 | libev itself (L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod> or |
61 | libev itself (L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod> or |
62 | F<perldoc EV::c_doc>) for more subtle details on watcher semantics or some |
62 | F<perldoc EV::libev>) for more subtle details on watcher semantics or some |
63 | discussion on the available backends, or how to force a specific backend |
63 | discussion on the available backends, or how to force a specific backend |
64 | with C<LIBEV_FLAGS>, or just about in any case because it has much more |
64 | with C<LIBEV_FLAGS>, or just about in any case because it has much more |
65 | detailed information. |
65 | detailed information. |
66 | |
66 | |
67 | This module is very fast and scalable. It is actually so fast that you |
67 | This module is very fast and scalable. It is actually so fast that you |
68 | can use it through the L<AnyEvent> module, stay portable to other event |
68 | can use it through the L<AnyEvent> module, stay portable to other event |
69 | loops (if you don't rely on any watcher types not available through it) |
69 | loops (if you don't rely on any watcher types not available through it) |
70 | and still be faster than with any other event loop currently supported in |
70 | and still be faster than with any other event loop currently supported in |
71 | Perl. |
71 | Perl. |
72 | |
72 | |
|
|
73 | =head2 MODULE EXPORTS |
|
|
74 | |
|
|
75 | This module does not export any symbols. |
|
|
76 | |
73 | =cut |
77 | =cut |
74 | |
78 | |
75 | package EV; |
79 | package EV; |
76 | |
80 | |
77 | no warnings; |
81 | no warnings; |
78 | use strict; |
82 | use strict; |
79 | |
83 | |
80 | BEGIN { |
84 | BEGIN { |
81 | our $VERSION = '3.44'; |
85 | our $VERSION = '3.51'; |
82 | use XSLoader; |
86 | use XSLoader; |
83 | XSLoader::load "EV", $VERSION; |
87 | XSLoader::load "EV", $VERSION; |
84 | } |
88 | } |
85 | |
89 | |
86 | @EV::IO::ISA = |
90 | @EV::IO::ISA = |
… | |
… | |
113 | default loop as this is fastest (perl-wise), best supported by other |
117 | default loop as this is fastest (perl-wise), best supported by other |
114 | modules (e.g. AnyEvent or Coro) and most portable event loop. |
118 | modules (e.g. AnyEvent or Coro) and most portable event loop. |
115 | |
119 | |
116 | For specific programs you can create additional event loops dynamically. |
120 | For specific programs you can create additional event loops dynamically. |
117 | |
121 | |
118 | If you want to take avdantage of kqueue (which often works properly for |
122 | If you want to take advantage of kqueue (which often works properly for |
119 | sockets only) even though the default loop doesn't enable it, you can |
123 | sockets only) even though the default loop doesn't enable it, you can |
120 | I<embed> a kqueue loop into the default loop: running the default loop |
124 | I<embed> a kqueue loop into the default loop: running the default loop |
121 | will then also service the kqueue loop to some extent. See the example in |
125 | will then also service the kqueue loop to some extent. See the example in |
122 | the section about embed watchers for an example on how to achieve that. |
126 | the section about embed watchers for an example on how to achieve that. |
123 | |
127 | |
… | |
… | |
126 | =item $loop = new EV::loop [$flags] |
130 | =item $loop = new EV::loop [$flags] |
127 | |
131 | |
128 | Create a new event loop as per the specified flags. Please refer to |
132 | Create a new event loop as per the specified flags. Please refer to |
129 | the C<ev_loop_new ()> function description in the libev documentation |
133 | the C<ev_loop_new ()> function description in the libev documentation |
130 | (L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#GLOBAL_FUNCTIONS>, |
134 | (L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#GLOBAL_FUNCTIONS>, |
131 | or locally-installed as F<EV::c_doc> manpage) for more info. |
135 | or locally-installed as F<EV::libev> manpage) for more info. |
132 | |
136 | |
133 | The loop will automatically be destroyed when it is no longer referenced |
137 | The loop will automatically be destroyed when it is no longer referenced |
134 | by any watcher and the loop object goes out of scope. |
138 | by any watcher and the loop object goes out of scope. |
135 | |
139 | |
136 | If you are not embedding the loop, then Using C<EV::FLAG_FORKCHECK> |
140 | If you are not embedding the loop, then Using C<EV::FLAG_FORKCHECK> |
… | |
… | |
195 | =item $time = EV::now |
199 | =item $time = EV::now |
196 | |
200 | |
197 | =item $time = $loop->now |
201 | =item $time = $loop->now |
198 | |
202 | |
199 | Returns the time the last event loop iteration has been started. This |
203 | Returns the time the last event loop iteration has been started. This |
200 | is the time that (relative) timers are based on, and refering to it is |
204 | is the time that (relative) timers are based on, and referring to it is |
201 | usually faster then calling EV::time. |
205 | usually faster then calling EV::time. |
202 | |
206 | |
203 | =item $backend = EV::backend |
207 | =item $backend = EV::backend |
204 | |
208 | |
205 | =item $backend = $loop->backend |
209 | =item $backend = $loop->backend |
206 | |
210 | |
207 | Returns an integer describing the backend used by libev (EV::METHOD_SELECT |
211 | Returns an integer describing the backend used by libev (EV::BACKEND_SELECT |
208 | or EV::METHOD_EPOLL). |
212 | or EV::BACKEND_EPOLL). |
209 | |
213 | |
210 | =item EV::loop [$flags] |
214 | =item EV::loop [$flags] |
211 | |
215 | |
212 | =item $loop->loop ([$flags]) |
216 | =item $loop->loop ([$flags]) |
213 | |
217 | |
… | |
… | |
233 | =item $count = EV::loop_count |
237 | =item $count = EV::loop_count |
234 | |
238 | |
235 | =item $count = $loop->loop_count |
239 | =item $count = $loop->loop_count |
236 | |
240 | |
237 | Return the number of times the event loop has polled for new |
241 | Return the number of times the event loop has polled for new |
238 | events. Sometiems useful as a generation counter. |
242 | events. Sometimes useful as a generation counter. |
239 | |
243 | |
240 | =item EV::once $fh_or_undef, $events, $timeout, $cb->($revents) |
244 | =item EV::once $fh_or_undef, $events, $timeout, $cb->($revents) |
241 | |
245 | |
242 | =item $loop->once ($fh_or_undef, $events, $timeout, $cb->($revents)) |
246 | =item $loop->once ($fh_or_undef, $events, $timeout, $cb->($revents)) |
243 | |
247 | |
… | |
… | |
284 | =item $loop->set_timeout_collect_interval ($time) |
288 | =item $loop->set_timeout_collect_interval ($time) |
285 | |
289 | |
286 | These advanced functions set the minimum block interval when polling for I/O events and the minimum |
290 | These advanced functions set the minimum block interval when polling for I/O events and the minimum |
287 | wait interval for timer events. See the libev documentation at |
291 | wait interval for timer events. See the libev documentation at |
288 | L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#FUNCTIONS_CONTROLLING_THE_EVENT_LOOP> |
292 | L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#FUNCTIONS_CONTROLLING_THE_EVENT_LOOP> |
289 | (locally installed as F<EV::c_doc>) for a more detailed discussion. |
293 | (locally installed as F<EV::libev>) for a more detailed discussion. |
290 | |
294 | |
291 | =back |
295 | =back |
292 | |
296 | |
293 | |
297 | |
294 | =head1 WATCHER OBJECTS |
298 | =head1 WATCHER OBJECTS |
… | |
… | |
307 | called with at least two arguments: the watcher and a bitmask of received |
311 | called with at least two arguments: the watcher and a bitmask of received |
308 | events. |
312 | events. |
309 | |
313 | |
310 | Each watcher type has its associated bit in revents, so you can use the |
314 | Each watcher type has its associated bit in revents, so you can use the |
311 | same callback for multiple watchers. The event mask is named after the |
315 | same callback for multiple watchers. The event mask is named after the |
312 | type, i..e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE, |
316 | type, i.e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE, |
313 | EV::periodic sets EV::PERIODIC and so on, with the exception of I/O events |
317 | EV::periodic sets EV::PERIODIC and so on, with the exception of I/O events |
314 | (which can set both EV::READ and EV::WRITE bits), and EV::timer (which |
318 | (which can set both EV::READ and EV::WRITE bits), and EV::timer (which |
315 | uses EV::TIMEOUT). |
319 | uses EV::TIMEOUT). |
316 | |
320 | |
317 | In the rare case where one wants to create a watcher but not start it at |
321 | In the rare case where one wants to create a watcher but not start it at |
… | |
… | |
413 | because you happen to have this long-running UDP port watcher. |
417 | because you happen to have this long-running UDP port watcher. |
414 | |
418 | |
415 | In this case you can clear the keepalive status, which means that even |
419 | In this case you can clear the keepalive status, which means that even |
416 | though your watcher is active, it won't keep C<EV::loop> from returning. |
420 | though your watcher is active, it won't keep C<EV::loop> from returning. |
417 | |
421 | |
418 | The initial value for keepalive is true (enabled), and you cna change it |
422 | The initial value for keepalive is true (enabled), and you can change it |
419 | any time. |
423 | any time. |
420 | |
424 | |
421 | Example: Register an I/O watcher for some UDP socket but do not keep the |
425 | Example: Register an I/O watcher for some UDP socket but do not keep the |
422 | event loop from running just because of that watcher. |
426 | event loop from running just because of that watcher. |
423 | |
427 | |
… | |
… | |
917 | # make the dispatcher handle any new stuff |
921 | # make the dispatcher handle any new stuff |
918 | ... not shown |
922 | ... not shown |
919 | }; |
923 | }; |
920 | |
924 | |
921 | The callbacks of the created watchers will not be called as the watchers |
925 | The callbacks of the created watchers will not be called as the watchers |
922 | are destroyed before this cna happen (remember EV::check gets called |
926 | are destroyed before this can happen (remember EV::check gets called |
923 | first). |
927 | first). |
924 | |
928 | |
925 | The C<check_ns> variant doesn't start (activate) the newly created watcher. |
929 | The C<check_ns> variant doesn't start (activate) the newly created watcher. |
926 | |
930 | |
927 | =back |
931 | =back |
… | |
… | |
958 | loop, other types of watchers might be handled in a delayed or incorrect |
962 | loop, other types of watchers might be handled in a delayed or incorrect |
959 | fashion and must not be used). |
963 | fashion and must not be used). |
960 | |
964 | |
961 | See the libev documentation at |
965 | See the libev documentation at |
962 | L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_embed_code_when_one_backend_> |
966 | L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_embed_code_when_one_backend_> |
963 | (locally installed as F<EV::c_doc>) for more details. |
967 | (locally installed as F<EV::libev>) for more details. |
964 | |
968 | |
965 | In short, this watcher is most useful on BSD systems without working |
969 | In short, this watcher is most useful on BSD systems without working |
966 | kqueue to still be able to handle a large number of sockets: |
970 | kqueue to still be able to handle a large number of sockets: |
967 | |
971 | |
968 | my $socket_loop; |
972 | my $socket_loop; |