… | |
… | |
39 | }; |
39 | }; |
40 | |
40 | |
41 | # CHILD/PID STATUS CHANGES |
41 | # CHILD/PID STATUS CHANGES |
42 | |
42 | |
43 | my $w = EV::child 666, sub { |
43 | my $w = EV::child 666, sub { |
44 | my ($w, $revents, $status) = @_; |
44 | my ($w, $revents) = @_; |
|
|
45 | # my $pid = $w->rpid; |
|
|
46 | my $status = $w->rstatus; |
45 | }; |
47 | }; |
46 | |
48 | |
47 | # MAINLOOP |
49 | # MAINLOOP |
48 | EV::loop; # loop until EV::loop_done is called |
50 | EV::loop; # loop until EV::loop_done is called |
49 | EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled |
51 | EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled |
… | |
… | |
115 | In the rare case where one wants to create a watcher but not start it at |
117 | In the rare case where one wants to create a watcher but not start it at |
116 | the same time, each constructor has a variant with a trailing "_ns" in |
118 | the same time, each constructor has a variant with a trailing "_ns" in |
117 | its name, e.g. EV::io has a non-starting variant EV::io_ns and so on. |
119 | its name, e.g. EV::io has a non-starting variant EV::io_ns and so on. |
118 | |
120 | |
119 | Please note that a watcher will automatically be stopped when the |
121 | Please note that a watcher will automatically be stopped when the |
120 | watcher object is returned, so you *need* to keep the watcher objects |
122 | watcher object is destroyed, so you *need* to keep the watcher objects |
121 | returned by the constructors. |
123 | returned by the constructors. |
|
|
124 | |
|
|
125 | Also, all methods changing some aspect of a watcher (->set, ->priority, |
|
|
126 | ->fh and so on) automatically stop and start it again if it is active, |
|
|
127 | which means pending events get lost. |
122 | |
128 | |
123 | WATCHER TYPES |
129 | WATCHER TYPES |
124 | Now lets move to the existing watcher types and asociated methods. |
130 | Now lets move to the existing watcher types and asociated methods. |
125 | |
131 | |
126 | The following methods are available for all watchers. Then followes a |
132 | The following methods are available for all watchers. Then followes a |
… | |
… | |
144 | Returns true if the watcher is active, false otherwise. |
150 | Returns true if the watcher is active, false otherwise. |
145 | |
151 | |
146 | $current_cb = $w->cb |
152 | $current_cb = $w->cb |
147 | $old_cb = $w->cb ($new_cb) |
153 | $old_cb = $w->cb ($new_cb) |
148 | Queries the callback on the watcher and optionally changes it. You |
154 | Queries the callback on the watcher and optionally changes it. You |
149 | cna do this at any time. |
155 | can do this at any time without the watcher restarting. |
|
|
156 | |
|
|
157 | $current_priority = $w->priority |
|
|
158 | $old_priority = $w->priority ($new_priority) |
|
|
159 | Queries the priority on the watcher and optionally changes it. |
|
|
160 | Pending watchers with higher priority will be invoked first. The |
|
|
161 | valid range of priorities lies between EV::MAXPRI (default 2) and |
|
|
162 | EV::MINPRI (default -2). If the priority is outside this range it |
|
|
163 | will automatically be normalised to the nearest valid priority. |
|
|
164 | |
|
|
165 | The default priority of any newly-created weatcher is 0. |
150 | |
166 | |
151 | $w->trigger ($revents) |
167 | $w->trigger ($revents) |
152 | Call the callback *now* with the given event mask. |
168 | Call the callback *now* with the given event mask. |
153 | |
169 | |
154 | $w = EV::io $fileno_or_fh, $eventmask, $callback |
170 | $w = EV::io $fileno_or_fh, $eventmask, $callback |
… | |
… | |
266 | watcher. |
282 | watcher. |
267 | |
283 | |
268 | $w->set ($signal) |
284 | $w->set ($signal) |
269 | Reconfigures the watcher, see the constructor above for details. Can |
285 | Reconfigures the watcher, see the constructor above for details. Can |
270 | be at any time. |
286 | be at any time. |
|
|
287 | |
|
|
288 | $current_signum = $w->signal |
|
|
289 | $old_signum = $w->signal ($new_signal) |
|
|
290 | Returns the previously set signal (always as a number not name) and |
|
|
291 | optionally set a new one. |
271 | |
292 | |
272 | $w = EV::child $pid, $callback |
293 | $w = EV::child $pid, $callback |
273 | $w = EV::child_ns $pid, $callback |
294 | $w = EV::child_ns $pid, $callback |
274 | Call the callback when a status change for pid $pid (or any pid if |
295 | Call the callback when a status change for pid $pid (or any pid if |
275 | $pid is 0) has been received. More precisely: when the process |
296 | $pid is 0) has been received. More precisely: when the process |
276 | receives a SIGCHLD, EV will fetch the outstanding exit/wait status |
297 | receives a SIGCHLD, EV will fetch the outstanding exit/wait status |
277 | for all changed/zombie children and call the callback. |
298 | for all changed/zombie children and call the callback. |
278 | |
299 | |
279 | Unlike all other callbacks, this callback will be called with an |
300 | You can access both status and pid by using the "rstatus" and "rpid" |
280 | additional third argument which is the exit status. See the |
301 | methods on the watcher object. |
281 | "waitpid" function for details. |
|
|
282 | |
302 | |
283 | You can have as many pid watchers per pid as you want. |
303 | You can have as many pid watchers per pid as you want. |
284 | |
304 | |
285 | The "child_ns" variant doesn't start (activate) the newly created |
305 | The "child_ns" variant doesn't start (activate) the newly created |
286 | watcher. |
306 | watcher. |
287 | |
307 | |
288 | $w->set ($pid) |
308 | $w->set ($pid) |
289 | Reconfigures the watcher, see the constructor above for details. Can |
309 | Reconfigures the watcher, see the constructor above for details. Can |
290 | be at any time. |
310 | be at any time. |
|
|
311 | |
|
|
312 | $current_pid = $w->pid |
|
|
313 | $old_pid = $w->pid ($new_pid) |
|
|
314 | Returns the previously set process id and optionally set a new one. |
|
|
315 | |
|
|
316 | $exit_status = $w->rstatus |
|
|
317 | Return the exit/wait status (as returned by waitpid, see the waitpid |
|
|
318 | entry in perlfunc). |
|
|
319 | |
|
|
320 | $pid = $w->rpid |
|
|
321 | Return the pid of the awaited child (useful when you have installed |
|
|
322 | a watcher for all pids). |
291 | |
323 | |
292 | $w = EV::idle $callback |
324 | $w = EV::idle $callback |
293 | $w = EV::idle_ns $callback |
325 | $w = EV::idle_ns $callback |
294 | Call the callback when there are no pending io, timer/periodic, |
326 | Call the callback when there are no pending io, timer/periodic, |
295 | signal or child events, i.e. when the process is idle. |
327 | signal or child events, i.e. when the process is idle. |