… | |
… | |
80 | |
80 | |
81 | no warnings; |
81 | no warnings; |
82 | use strict; |
82 | use strict; |
83 | |
83 | |
84 | BEGIN { |
84 | BEGIN { |
85 | our $VERSION = '3.48'; |
85 | our $VERSION = '3.6'; |
86 | use XSLoader; |
86 | use XSLoader; |
87 | XSLoader::load "EV", $VERSION; |
87 | XSLoader::load "EV", $VERSION; |
88 | } |
88 | } |
89 | |
89 | |
90 | @EV::IO::ISA = |
90 | @EV::IO::ISA = |
… | |
… | |
117 | 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 |
118 | modules (e.g. AnyEvent or Coro) and most portable event loop. |
118 | modules (e.g. AnyEvent or Coro) and most portable event loop. |
119 | |
119 | |
120 | For specific programs you can create additional event loops dynamically. |
120 | For specific programs you can create additional event loops dynamically. |
121 | |
121 | |
122 | 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 |
123 | 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 |
124 | 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 |
125 | 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 |
126 | 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. |
127 | |
127 | |
128 | =over 4 |
128 | =over 4 |
129 | |
129 | |
130 | =item $loop = new EV::loop [$flags] |
130 | =item $loop = new EV::Loop [$flags] |
131 | |
131 | |
132 | 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 |
133 | the C<ev_loop_new ()> function description in the libev documentation |
133 | the C<ev_loop_new ()> function description in the libev documentation |
134 | (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>, |
135 | or locally-installed as F<EV::libev> manpage) for more info. |
135 | or locally-installed as F<EV::libev> manpage) for more info. |
… | |
… | |
199 | =item $time = EV::now |
199 | =item $time = EV::now |
200 | |
200 | |
201 | =item $time = $loop->now |
201 | =item $time = $loop->now |
202 | |
202 | |
203 | 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 |
204 | 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 |
205 | usually faster then calling EV::time. |
205 | usually faster then calling EV::time. |
206 | |
206 | |
|
|
207 | =item EV::now_update |
|
|
208 | |
|
|
209 | =item $loop->now_update |
|
|
210 | |
|
|
211 | Establishes the current time by querying the kernel, updating the time |
|
|
212 | returned by C<EV::now> in the progress. This is a costly operation and |
|
|
213 | is usually done automatically within C<EV::loop>. |
|
|
214 | |
|
|
215 | This function is rarely useful, but when some event callback runs for a |
|
|
216 | very long time without entering the event loop, updating libev's idea of |
|
|
217 | the current time is a good idea. |
|
|
218 | |
|
|
219 | =item EV::suspend |
|
|
220 | |
|
|
221 | =item $loop->suspend |
|
|
222 | |
|
|
223 | =item EV::resume |
|
|
224 | |
|
|
225 | =item $loop->resume |
|
|
226 | |
|
|
227 | These two functions suspend and resume a loop, for use when the loop is |
|
|
228 | not used for a while and timeouts should not be processed. |
|
|
229 | |
|
|
230 | A typical use case would be an interactive program such as a game: When |
|
|
231 | the user presses C<^Z> to suspend the game and resumes it an hour later it |
|
|
232 | would be best to handle timeouts as if no time had actually passed while |
|
|
233 | the program was suspended. This can be achieved by calling C<suspend> |
|
|
234 | in your C<SIGTSTP> handler, sending yourself a C<SIGSTOP> and calling |
|
|
235 | C<resume> directly afterwards to resume timer processing. |
|
|
236 | |
|
|
237 | Effectively, all C<timer> watchers will be delayed by the time spend |
|
|
238 | between C<suspend> and C<resume>, and all C<periodic> watchers |
|
|
239 | will be rescheduled (that is, they will lose any events that would have |
|
|
240 | occured while suspended). |
|
|
241 | |
|
|
242 | After calling C<suspend> you B<must not> call I<any> function on the given |
|
|
243 | loop other than C<resume>, and you B<must not> call C<resume> |
|
|
244 | without a previous call to C<suspend>. |
|
|
245 | |
|
|
246 | Calling C<suspend>/C<resume> has the side effect of updating the event |
|
|
247 | loop time (see C<now_update>). |
|
|
248 | |
207 | =item $backend = EV::backend |
249 | =item $backend = EV::backend |
208 | |
250 | |
209 | =item $backend = $loop->backend |
251 | =item $backend = $loop->backend |
210 | |
252 | |
211 | Returns an integer describing the backend used by libev (EV::METHOD_SELECT |
253 | Returns an integer describing the backend used by libev (EV::BACKEND_SELECT |
212 | or EV::METHOD_EPOLL). |
254 | or EV::BACKEND_EPOLL). |
213 | |
255 | |
214 | =item EV::loop [$flags] |
256 | =item EV::loop [$flags] |
215 | |
257 | |
216 | =item $loop->loop ([$flags]) |
258 | =item $loop->loop ([$flags]) |
217 | |
259 | |
… | |
… | |
237 | =item $count = EV::loop_count |
279 | =item $count = EV::loop_count |
238 | |
280 | |
239 | =item $count = $loop->loop_count |
281 | =item $count = $loop->loop_count |
240 | |
282 | |
241 | Return the number of times the event loop has polled for new |
283 | Return the number of times the event loop has polled for new |
242 | events. Sometiems useful as a generation counter. |
284 | events. Sometimes useful as a generation counter. |
243 | |
285 | |
244 | =item EV::once $fh_or_undef, $events, $timeout, $cb->($revents) |
286 | =item EV::once $fh_or_undef, $events, $timeout, $cb->($revents) |
245 | |
287 | |
246 | =item $loop->once ($fh_or_undef, $events, $timeout, $cb->($revents)) |
288 | =item $loop->once ($fh_or_undef, $events, $timeout, $cb->($revents)) |
247 | |
289 | |
… | |
… | |
311 | called with at least two arguments: the watcher and a bitmask of received |
353 | called with at least two arguments: the watcher and a bitmask of received |
312 | events. |
354 | events. |
313 | |
355 | |
314 | Each watcher type has its associated bit in revents, so you can use the |
356 | Each watcher type has its associated bit in revents, so you can use the |
315 | same callback for multiple watchers. The event mask is named after the |
357 | same callback for multiple watchers. The event mask is named after the |
316 | type, i..e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE, |
358 | type, i.e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE, |
317 | EV::periodic sets EV::PERIODIC and so on, with the exception of I/O events |
359 | EV::periodic sets EV::PERIODIC and so on, with the exception of I/O events |
318 | (which can set both EV::READ and EV::WRITE bits), and EV::timer (which |
360 | (which can set both EV::READ and EV::WRITE bits), and EV::timer (which |
319 | uses EV::TIMEOUT). |
361 | uses EV::TIMEOUT). |
320 | |
362 | |
321 | In the rare case where one wants to create a watcher but not start it at |
363 | In the rare case where one wants to create a watcher but not start it at |
… | |
… | |
417 | because you happen to have this long-running UDP port watcher. |
459 | because you happen to have this long-running UDP port watcher. |
418 | |
460 | |
419 | In this case you can clear the keepalive status, which means that even |
461 | In this case you can clear the keepalive status, which means that even |
420 | though your watcher is active, it won't keep C<EV::loop> from returning. |
462 | though your watcher is active, it won't keep C<EV::loop> from returning. |
421 | |
463 | |
422 | The initial value for keepalive is true (enabled), and you cna change it |
464 | The initial value for keepalive is true (enabled), and you can change it |
423 | any time. |
465 | any time. |
424 | |
466 | |
425 | Example: Register an I/O watcher for some UDP socket but do not keep the |
467 | Example: Register an I/O watcher for some UDP socket but do not keep the |
426 | event loop from running just because of that watcher. |
468 | event loop from running just because of that watcher. |
427 | |
469 | |
… | |
… | |
921 | # make the dispatcher handle any new stuff |
963 | # make the dispatcher handle any new stuff |
922 | ... not shown |
964 | ... not shown |
923 | }; |
965 | }; |
924 | |
966 | |
925 | The callbacks of the created watchers will not be called as the watchers |
967 | The callbacks of the created watchers will not be called as the watchers |
926 | are destroyed before this cna happen (remember EV::check gets called |
968 | are destroyed before this can happen (remember EV::check gets called |
927 | first). |
969 | first). |
928 | |
970 | |
929 | The C<check_ns> variant doesn't start (activate) the newly created watcher. |
971 | The C<check_ns> variant doesn't start (activate) the newly created watcher. |
930 | |
972 | |
931 | =back |
973 | =back |