ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.pm
(Generate patch)

Comparing EV/EV.pm (file contents):
Revision 1.20 by root, Thu Nov 1 17:17:32 2007 UTC vs.
Revision 1.29 by root, Tue Nov 6 17:20:42 2007 UTC

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
60package EV; 62package EV;
61 63
62use strict; 64use strict;
63 65
64BEGIN { 66BEGIN {
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 =
150In the rare case where one wants to create a watcher but not start it at 152In the rare case where one wants to create a watcher but not start it at
151the same time, each constructor has a variant with a trailing C<_ns> in 153the same time, each constructor has a variant with a trailing C<_ns> in
152its name, e.g. EV::io has a non-starting variant EV::io_ns and so on. 154its name, e.g. EV::io has a non-starting variant EV::io_ns and so on.
153 155
154Please note that a watcher will automatically be stopped when the watcher 156Please note that a watcher will automatically be stopped when the watcher
155object is returned, so you I<need> to keep the watcher objects returned by 157object is destroyed, so you I<need> to keep the watcher objects returned by
156the constructors. 158the constructors.
159
160Also, 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,
162which means pending events get lost.
157 163
158=head2 WATCHER TYPES 164=head2 WATCHER TYPES
159 165
160Now lets move to the existing watcher types and asociated methods. 166Now 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
189Queries the callback on the watcher and optionally changes it. You cna do 195Queries the callback on the watcher and optionally changes it. You can do
190this at any time. 196this at any time without the watcher restarting.
197
198=item $current_priority = $w->priority
199
200=item $old_priority = $w->priority ($new_priority)
201
202Queries the priority on the watcher and optionally changes it. Pending
203watchers with higher priority will be invoked first. The valid range of
204priorities lies between EV::MAXPRI (default 2) and EV::MINPRI (default
205-2). If the priority is outside this range it will automatically be
206normalised to the nearest valid priority.
207
208The default priority of any newly-created weatcher is 0.
191 209
192=item $w->trigger ($revents) 210=item $w->trigger ($revents)
193 211
194Call the callback *now* with the given event mask. 212Call the callback *now* with the given event mask.
195 213
291EV::periodic will try to run the callback at the next possible time where 309EV::periodic will try to run the callback at the next possible time where
292C<$time = $at (mod $interval)>, regardless of any time jumps. 310C<$time = $at (mod $interval)>, regardless of any time jumps.
293 311
294This periodic timer is based on "wallclock time", that is, if the clock 312This periodic timer is based on "wallclock time", that is, if the clock
295changes (C<ntp>, C<date -s> etc.), then the timer will nevertheless run at 313changes (C<ntp>, C<date -s> etc.), then the timer will nevertheless run at
296the specified time. 314the specified time. This means it will never drift (it might jitter, but
315it will not drift).
297 316
298The C<periodic_ns> variant doesn't start (activate) the newly created watcher. 317The C<periodic_ns> variant doesn't start (activate) the newly created watcher.
299 318
300=item $w->set ($at, $interval) 319=item $w->set ($at, $interval)
301 320
322=item $w->set ($signal) 341=item $w->set ($signal)
323 342
324Reconfigures the watcher, see the constructor above for details. Can be at 343Reconfigures the watcher, see the constructor above for details. Can be at
325any time. 344any time.
326 345
346=item $current_signum = $w->signal
347
348=item $old_signum = $w->signal ($new_signal)
349
350Returns the previously set signal (always as a number not name) and
351optionally set a new one.
352
327 353
328=item $w = EV::child $pid, $callback 354=item $w = EV::child $pid, $callback
329 355
330=item $w = EV::child_ns $pid, $callback 356=item $w = EV::child_ns $pid, $callback
331 357
332Call the callback when a status change for pid C<$pid> (or any pid 358Call the callback when a status change for pid C<$pid> (or any pid
333if C<$pid> is 0) has been received. More precisely: when the process 359if C<$pid> is 0) has been received. More precisely: when the process
334receives a SIGCHLD, EV will fetch the outstanding exit/wait status for all 360receives a SIGCHLD, EV will fetch the outstanding exit/wait status for all
335changed/zombie children and call the callback. 361changed/zombie children and call the callback.
336 362
337Unlike all other callbacks, this callback will be called with an 363You can access both status and pid by using the C<rstatus> and C<rpid>
338additional third argument which is the exit status. See the C<waitpid> 364methods on the watcher object.
339function for details.
340 365
341You can have as many pid watchers per pid as you want. 366You can have as many pid watchers per pid as you want.
342 367
343The C<child_ns> variant doesn't start (activate) the newly created watcher. 368The C<child_ns> variant doesn't start (activate) the newly created watcher.
344 369
345=item $w->set ($pid) 370=item $w->set ($pid)
346 371
347Reconfigures the watcher, see the constructor above for details. Can be at 372Reconfigures the watcher, see the constructor above for details. Can be at
348any time. 373any time.
374
375=item $current_pid = $w->pid
376
377=item $old_pid = $w->pid ($new_pid)
378
379Returns the previously set process id and optionally set a new one.
380
381=item $exit_status = $w->rstatus
382
383Return the exit/wait status (as returned by waitpid, see the waitpid entry
384in perlfunc).
385
386=item $pid = $w->rpid
387
388Return the pid of the awaited child (useful when you have installed a
389watcher for all pids).
349 390
350 391
351=item $w = EV::idle $callback 392=item $w = EV::idle $callback
352 393
353=item $w = EV::idle_ns $callback 394=item $w = EV::idle_ns $callback
434 475
435our $DIED = sub { 476our $DIED = sub {
436 warn "EV: error in callback (ignoring): $@"; 477 warn "EV: error in callback (ignoring): $@";
437}; 478};
438 479
439init; 480default_loop
481 or die 'EV: cannot initialise libev backend. bad $ENV{LIBEV_METHODS}?';
440 482
441push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; 483push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"];
442 484
4431; 4851;
444 486

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines