… | |
… | |
40 | my ($w, $revents) = @_; |
40 | my ($w, $revents) = @_; |
41 | my $status = $w->rstatus; |
41 | my $status = $w->rstatus; |
42 | }; |
42 | }; |
43 | |
43 | |
44 | # MAINLOOP |
44 | # MAINLOOP |
45 | EV::loop; # loop until EV::loop_done is called or all watchers stop |
45 | EV::loop; # loop until EV::unloop is called or all watchers stop |
46 | EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled |
46 | EV::loop EV::LOOP_ONESHOT; # block until at least one event could be handled |
47 | EV::loop EV::LOOP_NONBLOCK; # try to handle same events, but do not block |
47 | EV::loop EV::LOOP_NONBLOCK; # try to handle same events, but do not block |
48 | |
48 | |
49 | DESCRIPTION |
49 | DESCRIPTION |
50 | This module provides an interface to libev |
50 | This module provides an interface to libev |
… | |
… | |
70 | Returns an integer describing the backend used by libev |
70 | Returns an integer describing the backend used by libev |
71 | (EV::METHOD_SELECT or EV::METHOD_EPOLL). |
71 | (EV::METHOD_SELECT or EV::METHOD_EPOLL). |
72 | |
72 | |
73 | EV::loop [$flags] |
73 | EV::loop [$flags] |
74 | Begin checking for events and calling callbacks. It returns when a |
74 | Begin checking for events and calling callbacks. It returns when a |
75 | callback calls EV::loop_done. |
75 | callback calls EV::unloop. |
76 | |
76 | |
77 | The $flags argument can be one of the following: |
77 | The $flags argument can be one of the following: |
78 | |
78 | |
79 | 0 as above |
79 | 0 as above |
80 | EV::LOOP_ONESHOT block at most once (wait, but do not loop) |
80 | EV::LOOP_ONESHOT block at most once (wait, but do not loop) |
81 | EV::LOOP_NONBLOCK do not block at all (fetch/handle events but do not wait) |
81 | EV::LOOP_NONBLOCK do not block at all (fetch/handle events but do not wait) |
82 | |
82 | |
83 | EV::loop_done [$how] |
83 | EV::unloop [$how] |
84 | When called with no arguments or an argument of 1, makes the |
84 | When called with no arguments or an argument of EV::UNLOOP_ONE, |
85 | innermost call to EV::loop return. |
85 | makes the innermost call to EV::loop return. |
86 | |
86 | |
87 | When called with an agrument of 2, all calls to EV::loop will return |
87 | When called with an argument of EV::UNLOOP_ALL, all calls to |
88 | as fast as possible. |
88 | EV::loop will return as fast as possible. |
89 | |
89 | |
90 | WATCHER |
90 | WATCHER |
91 | A watcher is an object that gets created to record your interest in some |
91 | A watcher is an object that gets created to record your interest in some |
92 | event. For instance, if you want to wait for STDIN to become readable, |
92 | event. For instance, if you want to wait for STDIN to become readable, |
93 | you would create an EV::io watcher for that: |
93 | you would create an EV::io watcher for that: |
… | |
… | |
202 | Calls the callback after $after seconds. If $repeat is non-zero, the |
202 | Calls the callback after $after seconds. If $repeat is non-zero, the |
203 | timer will be restarted (with the $repeat value as $after) after the |
203 | timer will be restarted (with the $repeat value as $after) after the |
204 | callback returns. |
204 | callback returns. |
205 | |
205 | |
206 | This means that the callback would be called roughly after $after |
206 | This means that the callback would be called roughly after $after |
207 | seconds, and then every $repeat seconds. "Roughly" because the time |
207 | seconds, and then every $repeat seconds. The timer does his best not |
208 | of callback processing is not taken into account, so the timer will |
208 | to drift, but it will not invoke the timer more often then once per |
209 | slowly drift. If that isn't acceptable, look at EV::periodic. |
209 | event loop iteration, and might drift in other cases. If that isn't |
|
|
210 | acceptable, look at EV::periodic, which can provide long-term stable |
|
|
211 | timers. |
210 | |
212 | |
211 | The timer is based on a monotonic clock, that is if somebody is |
213 | The timer is based on a monotonic clock, that is, if somebody is |
212 | sitting in front of the machine while the timer is running and |
214 | sitting in front of the machine while the timer is running and |
213 | changes the system clock, the timer will nevertheless run (roughly) |
215 | changes the system clock, the timer will nevertheless run (roughly) |
214 | the same time. |
216 | the same time. |
215 | |
217 | |
216 | The "timer_ns" variant doesn't start (activate) the newly created |
218 | The "timer_ns" variant doesn't start (activate) the newly created |
… | |
… | |
222 | |
224 | |
223 | $w->again |
225 | $w->again |
224 | Similar to the "start" method, but has special semantics for |
226 | Similar to the "start" method, but has special semantics for |
225 | repeating timers: |
227 | repeating timers: |
226 | |
228 | |
|
|
229 | If the timer is active and non-repeating, it will be stopped. |
|
|
230 | |
227 | If the timer is active and repeating, reset the timeout to occur |
231 | If the timer is active and repeating, reset the timeout to occur |
228 | $repeat seconds after now. |
232 | $repeat seconds after now. |
229 | |
233 | |
230 | If the timer is active and non-repeating, it will be stopped. |
|
|
231 | |
|
|
232 | If the timer is in active and repeating, start it. |
234 | If the timer is inactive and repeating, start it using the repeat |
|
|
235 | value. |
233 | |
236 | |
234 | Otherwise do nothing. |
237 | Otherwise do nothing. |
235 | |
238 | |
236 | This behaviour is useful when you have a timeout for some IO |
239 | This behaviour is useful when you have a timeout for some IO |
237 | operation. You create a timer object with the same value for $after |
240 | operation. You create a timer object with the same value for $after |
… | |
… | |
275 | at the next possible time where "$time = $at (mod $interval)", |
278 | at the next possible time where "$time = $at (mod $interval)", |
276 | regardless of any time jumps. |
279 | regardless of any time jumps. |
277 | |
280 | |
278 | * manual reschedule mode ($reschedule_cb = coderef) |
281 | * manual reschedule mode ($reschedule_cb = coderef) |
279 | In this mode $interval and $at are both being ignored. Instead, |
282 | In this mode $interval and $at are both being ignored. Instead, |
280 | each time the periodic watcher gets scheduled, the first |
283 | each time the periodic watcher gets scheduled, the reschedule |
281 | callback ($reschedule_cb) will be called with the watcher as |
284 | callback ($reschedule_cb) will be called with the watcher as |
282 | first, and the current time as second argument. |
285 | first, and the current time as second argument. |
283 | |
286 | |
284 | *This callback MUST NOT stop or destroy this or any other |
287 | *This callback MUST NOT stop or destroy this or any other |
285 | periodic watcher, ever*. If you need to stop it, return 1e30 and |
288 | periodic watcher, ever*. If you need to stop it, return 1e30 and |