… | |
… | |
25 | }; |
25 | }; |
26 | |
26 | |
27 | my $w = EV::io \*STDIN, EV::READ | EV::PERSIST, sub { |
27 | my $w = EV::io \*STDIN, EV::READ | EV::PERSIST, sub { |
28 | my ($w, $events) = @_; # all callbacks get the watcher object and event mask |
28 | my ($w, $events) = @_; # all callbacks get the watcher object and event mask |
29 | if ($events & EV::TIMEOUT) { |
29 | if ($events & EV::TIMEOUT) { |
30 | warn "nothign received on stdin for 10 seconds, retrying"; |
30 | warn "nothing received on stdin for 10 seconds, retrying"; |
31 | } else { |
31 | } else { |
32 | warn "stdin is readable, you entered: ", <STDIN>; |
32 | warn "stdin is readable, you entered: ", <STDIN>; |
33 | } |
33 | } |
34 | }; |
34 | }; |
35 | $w->timeout (10); |
35 | $w->timeout (10); |
… | |
… | |
55 | package EV; |
55 | package EV; |
56 | |
56 | |
57 | use strict; |
57 | use strict; |
58 | |
58 | |
59 | BEGIN { |
59 | BEGIN { |
60 | our $VERSION = '0.01'; |
60 | our $VERSION = '0.02'; |
61 | use XSLoader; |
61 | use XSLoader; |
62 | XSLoader::load "EV", $VERSION; |
62 | XSLoader::load "EV", $VERSION; |
63 | } |
63 | } |
64 | |
64 | |
65 | =head1 FUNCTIONAL INTERFACE |
65 | =head1 BASIC INTERFACE |
66 | |
66 | |
67 | =over 4 |
67 | =over 4 |
68 | |
68 | |
69 | =item $EV::NPRI |
69 | =item $EV::NPRI |
70 | |
70 | |
71 | How many priority levels are available. |
71 | How many priority levels are available. |
|
|
72 | |
|
|
73 | =item $EV::DIED |
|
|
74 | |
|
|
75 | Must contain a reference to a function that is called when a callback |
|
|
76 | throws an exception (with $@ containing thr error). The default prints an |
|
|
77 | informative message and continues. |
|
|
78 | |
|
|
79 | If this callback throws an exception it will be silently ignored. |
72 | |
80 | |
73 | =item $time = EV::now |
81 | =item $time = EV::now |
74 | |
82 | |
75 | Returns the time in (fractional) seconds since the epoch. |
83 | Returns the time in (fractional) seconds since the epoch. |
76 | |
84 | |
… | |
… | |
101 | |
109 | |
102 | As long as the returned watcher object is alive, call the C<$callback> |
110 | As long as the returned watcher object is alive, call the C<$callback> |
103 | when the events specified in C<$eventmask> happen. Initially, the timeout |
111 | when the events specified in C<$eventmask> happen. Initially, the timeout |
104 | is disabled. |
112 | is disabled. |
105 | |
113 | |
106 | Youc an additionall set a timeout to occur on the watcher, but note that |
114 | You can additionall set a timeout to occur on the watcher, but note that |
107 | this timeout will not be reset when you get an I/O event in the EV::PERSIST |
115 | this timeout will not be reset when you get an I/O event in the EV::PERSIST |
108 | case, and reaching a timeout will always stop the watcher even in the |
116 | case, and reaching a timeout will always stop the watcher even in the |
109 | EV::PERSIST case. |
117 | EV::PERSIST case. |
110 | |
118 | |
111 | If you want a timeout to occur only after a specific time of inactivity, set |
119 | If you want a timeout to occur only after a specific time of inactivity, set |
… | |
… | |
116 | EV::READ wait until read() wouldn't block anymore |
124 | EV::READ wait until read() wouldn't block anymore |
117 | EV::WRITE wait until write() wouldn't block anymore |
125 | EV::WRITE wait until write() wouldn't block anymore |
118 | EV::PERSIST stay active after a (non-timeout) event occured |
126 | EV::PERSIST stay active after a (non-timeout) event occured |
119 | |
127 | |
120 | The C<io_ns> variant doesn't add/start the newly created watcher. |
128 | The C<io_ns> variant doesn't add/start the newly created watcher. |
|
|
129 | |
|
|
130 | =item my $w = EV::timed_io $fileno_or_fh, $eventmask, $timeout, $callback |
|
|
131 | |
|
|
132 | =item my $w = EV::timed_io_ns $fileno_or_fh, $eventmask, $timeout, $callback |
|
|
133 | |
|
|
134 | Same as C<io> and C<io_ns>, but also specifies a timeout (as if there was |
|
|
135 | a call to C<< $w->timeout ($timout, 1) >>. The persist flag is not allowed |
|
|
136 | and will automatically be cleared. The watcher will be restarted after each event. |
|
|
137 | |
|
|
138 | If the timeout is zero or undef, no timeout will be set, and a normal |
|
|
139 | watcher (with the persist flag set!) will be created. |
|
|
140 | |
|
|
141 | This has the effect of timing out after the specified period of inactivity |
|
|
142 | has happened. |
|
|
143 | |
|
|
144 | Due to the design of libevent, this is also relatively inefficient, having |
|
|
145 | one or two io watchers and a separate timeout watcher that you reset on |
|
|
146 | activity (by calling its C<start> method) is usually more efficient. |
121 | |
147 | |
122 | =item my $w = EV::timer $after, $repeat, $callback |
148 | =item my $w = EV::timer $after, $repeat, $callback |
123 | |
149 | |
124 | =item my $w = EV::timer_ns $after, $repeat, $callback |
150 | =item my $w = EV::timer_ns $after, $repeat, $callback |
125 | |
151 | |
… | |
… | |
194 | |
220 | |
195 | =item $current_fh = $w->fh |
221 | =item $current_fh = $w->fh |
196 | |
222 | |
197 | =item $old_fh = $w->fh ($new_fh) |
223 | =item $old_fh = $w->fh ($new_fh) |
198 | |
224 | |
199 | Returns the previously set filehandle and optionally set a new one. |
225 | Returns the previously set filehandle and optionally set a new one (also |
|
|
226 | clears the EV::SIGNAL flag when setting a filehandle). |
|
|
227 | |
|
|
228 | =item $current_signal = $w->signal |
|
|
229 | |
|
|
230 | =item $old_signal = $w->signal ($new_signal) |
|
|
231 | |
|
|
232 | Returns the previously set signal number and optionally set a new one (also sets |
|
|
233 | the EV::SIGNAL flag when setting a signal). |
200 | |
234 | |
201 | =item $current_eventmask = $w->events |
235 | =item $current_eventmask = $w->events |
202 | |
236 | |
203 | =item $old_eventmask = $w->events ($new_eventmask) |
237 | =item $old_eventmask = $w->events ($new_eventmask) |
204 | |
238 | |
… | |
… | |
231 | In general, if you fork, then you can only use the EV module in one of the |
265 | In general, if you fork, then you can only use the EV module in one of the |
232 | children. |
266 | children. |
233 | |
267 | |
234 | =cut |
268 | =cut |
235 | |
269 | |
|
|
270 | our $DIED = sub { |
|
|
271 | warn "EV: error in callback (ignoring): $@"; |
|
|
272 | }; |
|
|
273 | |
236 | our $NPRI = 4; |
274 | our $NPRI = 4; |
237 | our $BASE = init; |
275 | our $BASE = init; |
238 | priority_init $NPRI; |
276 | priority_init $NPRI; |
239 | |
277 | |
240 | push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; |
278 | push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; |