… | |
… | |
40 | }; |
40 | }; |
41 | |
41 | |
42 | # CHILD/PID STATUS CHANGES |
42 | # CHILD/PID STATUS CHANGES |
43 | |
43 | |
44 | my $w = EV::child 666, sub { |
44 | my $w = EV::child 666, sub { |
45 | my ($w, $revents, $status) = @_; |
45 | my ($w, $revents) = @_; |
|
|
46 | # my $pid = $w->rpid; |
|
|
47 | my $status = $w->rstatus; |
46 | }; |
48 | }; |
47 | |
49 | |
48 | # MAINLOOP |
50 | # MAINLOOP |
49 | EV::loop; # loop until EV::loop_done is called |
51 | EV::loop; # loop until EV::loop_done is called |
50 | EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled |
52 | EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled |
… | |
… | |
60 | package EV; |
62 | package EV; |
61 | |
63 | |
62 | use strict; |
64 | use strict; |
63 | |
65 | |
64 | BEGIN { |
66 | BEGIN { |
65 | our $VERSION = '0.1'; |
67 | our $VERSION = '0.51'; |
66 | use XSLoader; |
68 | use XSLoader; |
67 | XSLoader::load "EV", $VERSION; |
69 | XSLoader::load "EV", $VERSION; |
68 | } |
70 | } |
69 | |
71 | |
70 | @EV::Io::ISA = |
72 | @EV::Io::ISA = |
… | |
… | |
150 | In the rare case where one wants to create a watcher but not start it at |
152 | In the rare case where one wants to create a watcher but not start it at |
151 | the same time, each constructor has a variant with a trailing C<_ns> in |
153 | the same time, each constructor has a variant with a trailing C<_ns> in |
152 | its name, e.g. EV::io has a non-starting variant EV::io_ns and so on. |
154 | its name, e.g. EV::io has a non-starting variant EV::io_ns and so on. |
153 | |
155 | |
154 | Please note that a watcher will automatically be stopped when the watcher |
156 | Please note that a watcher will automatically be stopped when the watcher |
155 | object is returned, so you I<need> to keep the watcher objects returned by |
157 | object is destroyed, so you I<need> to keep the watcher objects returned by |
156 | the constructors. |
158 | the constructors. |
|
|
159 | |
|
|
160 | Also, all methods changing some aspect of a watcher (->set, ->priority, |
|
|
161 | ->fh and so on) automatically stop and start it again if it is active, |
|
|
162 | which means pending events get lost. |
157 | |
163 | |
158 | =head2 WATCHER TYPES |
164 | =head2 WATCHER TYPES |
159 | |
165 | |
160 | Now lets move to the existing watcher types and asociated methods. |
166 | Now lets move to the existing watcher types and asociated methods. |
161 | |
167 | |
… | |
… | |
184 | |
190 | |
185 | =item $current_cb = $w->cb |
191 | =item $current_cb = $w->cb |
186 | |
192 | |
187 | =item $old_cb = $w->cb ($new_cb) |
193 | =item $old_cb = $w->cb ($new_cb) |
188 | |
194 | |
189 | Queries the callback on the watcher and optionally changes it. You cna do |
195 | Queries the callback on the watcher and optionally changes it. You can do |
190 | this at any time. |
196 | this at any time without the watcher restarting. |
|
|
197 | |
|
|
198 | =item $current_priority = $w->priority |
|
|
199 | |
|
|
200 | =item $old_priority = $w->priority ($new_priority) |
|
|
201 | |
|
|
202 | Queries the priority on the watcher and optionally changes it. Pending |
|
|
203 | watchers with higher priority will be invoked first. The valid range of |
|
|
204 | priorities lies between EV::MAXPRI (default 2) and EV::MINPRI (default |
|
|
205 | -2). If the priority is outside this range it will automatically be |
|
|
206 | normalised to the nearest valid priority. |
|
|
207 | |
|
|
208 | The default priority of any newly-created weatcher is 0. |
191 | |
209 | |
192 | =item $w->trigger ($revents) |
210 | =item $w->trigger ($revents) |
193 | |
211 | |
194 | Call the callback *now* with the given event mask. |
212 | Call the callback *now* with the given event mask. |
195 | |
213 | |
… | |
… | |
323 | =item $w->set ($signal) |
341 | =item $w->set ($signal) |
324 | |
342 | |
325 | Reconfigures the watcher, see the constructor above for details. Can be at |
343 | Reconfigures the watcher, see the constructor above for details. Can be at |
326 | any time. |
344 | any time. |
327 | |
345 | |
|
|
346 | =item $current_signum = $w->signal |
|
|
347 | |
|
|
348 | =item $old_signum = $w->signal ($new_signal) |
|
|
349 | |
|
|
350 | Returns the previously set signal (always as a number not name) and |
|
|
351 | optionally set a new one. |
|
|
352 | |
328 | |
353 | |
329 | =item $w = EV::child $pid, $callback |
354 | =item $w = EV::child $pid, $callback |
330 | |
355 | |
331 | =item $w = EV::child_ns $pid, $callback |
356 | =item $w = EV::child_ns $pid, $callback |
332 | |
357 | |
333 | Call the callback when a status change for pid C<$pid> (or any pid |
358 | Call the callback when a status change for pid C<$pid> (or any pid |
334 | if C<$pid> is 0) has been received. More precisely: when the process |
359 | if C<$pid> is 0) has been received. More precisely: when the process |
335 | receives a SIGCHLD, EV will fetch the outstanding exit/wait status for all |
360 | receives a SIGCHLD, EV will fetch the outstanding exit/wait status for all |
336 | changed/zombie children and call the callback. |
361 | changed/zombie children and call the callback. |
337 | |
362 | |
338 | Unlike all other callbacks, this callback will be called with an |
363 | You can access both status and pid by using the C<rstatus> and C<rpid> |
339 | additional third argument which is the exit status. See the C<waitpid> |
364 | methods on the watcher object. |
340 | function for details. |
|
|
341 | |
365 | |
342 | You can have as many pid watchers per pid as you want. |
366 | You can have as many pid watchers per pid as you want. |
343 | |
367 | |
344 | The C<child_ns> variant doesn't start (activate) the newly created watcher. |
368 | The C<child_ns> variant doesn't start (activate) the newly created watcher. |
345 | |
369 | |
346 | =item $w->set ($pid) |
370 | =item $w->set ($pid) |
347 | |
371 | |
348 | Reconfigures the watcher, see the constructor above for details. Can be at |
372 | Reconfigures the watcher, see the constructor above for details. Can be at |
349 | any time. |
373 | any time. |
|
|
374 | |
|
|
375 | =item $current_pid = $w->pid |
|
|
376 | |
|
|
377 | =item $old_pid = $w->pid ($new_pid) |
|
|
378 | |
|
|
379 | Returns the previously set process id and optionally set a new one. |
|
|
380 | |
|
|
381 | =item $exit_status = $w->rstatus |
|
|
382 | |
|
|
383 | Return the exit/wait status (as returned by waitpid, see the waitpid entry |
|
|
384 | in perlfunc). |
|
|
385 | |
|
|
386 | =item $pid = $w->rpid |
|
|
387 | |
|
|
388 | Return the pid of the awaited child (useful when you have installed a |
|
|
389 | watcher for all pids). |
350 | |
390 | |
351 | |
391 | |
352 | =item $w = EV::idle $callback |
392 | =item $w = EV::idle $callback |
353 | |
393 | |
354 | =item $w = EV::idle_ns $callback |
394 | =item $w = EV::idle_ns $callback |
… | |
… | |
435 | |
475 | |
436 | our $DIED = sub { |
476 | our $DIED = sub { |
437 | warn "EV: error in callback (ignoring): $@"; |
477 | warn "EV: error in callback (ignoring): $@"; |
438 | }; |
478 | }; |
439 | |
479 | |
440 | init; |
480 | default_loop |
|
|
481 | or die 'EV: cannot initialise libev backend. bad $ENV{LIBEV_METHODS}?'; |
441 | |
482 | |
442 | push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; |
483 | push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; |
443 | |
484 | |
444 | 1; |
485 | 1; |
445 | |
486 | |