… | |
… | |
60 | our $VERSION = '0.01'; |
60 | our $VERSION = '0.01'; |
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 | The C<io_ns> variant doesn't add/start the newly created watcher. |
114 | Youc an additionall set a timeout to occur on the watcher, but note that |
|
|
115 | this timeout will not be reset when you get an I/O event in the EV::PERSIST |
|
|
116 | case, and reaching a timeout will always stop the watcher even in the |
|
|
117 | EV::PERSIST case. |
|
|
118 | |
|
|
119 | If you want a timeout to occur only after a specific time of inactivity, set |
|
|
120 | a repeating timeout and do NOT use EV::PERSIST. |
107 | |
121 | |
108 | Eventmask can be one or more of these constants ORed together: |
122 | Eventmask can be one or more of these constants ORed together: |
109 | |
123 | |
110 | EV::READ wait until read() wouldn't block anymore |
124 | EV::READ wait until read() wouldn't block anymore |
111 | EV::WRITE wait until write() wouldn't block anymore |
125 | EV::WRITE wait until write() wouldn't block anymore |
112 | EV::PERSIST stay active after an event occured |
126 | EV::PERSIST stay active after a (non-timeout) event occured |
|
|
127 | |
|
|
128 | The C<io_ns> variant doesn't add/start the newly created watcher. |
113 | |
129 | |
114 | =item my $w = EV::timer $after, $repeat, $callback |
130 | =item my $w = EV::timer $after, $repeat, $callback |
115 | |
131 | |
116 | =item my $w = EV::timer_ns $after, $repeat, $callback |
132 | =item my $w = EV::timer_ns $after, $repeat, $callback |
117 | |
133 | |
… | |
… | |
138 | |
154 | |
139 | This can be used to schedule a callback to run at very regular intervals, |
155 | This can be used to schedule a callback to run at very regular intervals, |
140 | as long as the processing time is less then the interval (otherwise |
156 | as long as the processing time is less then the interval (otherwise |
141 | obviously events will be skipped). |
157 | obviously events will be skipped). |
142 | |
158 | |
|
|
159 | Another way to think about it (for the mathematically inclined) is that |
|
|
160 | C<timer_abs> will try to tun the callback at the next possible time where |
|
|
161 | C<$time = $at (mod $interval)>, regardless of any time jumps. |
|
|
162 | |
143 | The C<timer_abs_ns> variant doesn't add/start the newly created watcher. |
163 | The C<timer_abs_ns> variant doesn't add/start the newly created watcher. |
144 | |
164 | |
145 | =item my $w = EV::signal $signum, $callback |
165 | =item my $w = EV::signal $signum, $callback |
146 | |
166 | |
147 | =item my $w = EV::signal_ns $signum, $callback |
167 | =item my $w = EV::signal_ns $signum, $callback |
… | |
… | |
209 | =head1 BUGS |
229 | =head1 BUGS |
210 | |
230 | |
211 | Lots. Libevent itself isn't well tested and rather buggy, and this module |
231 | Lots. Libevent itself isn't well tested and rather buggy, and this module |
212 | is quite new at the moment. |
232 | is quite new at the moment. |
213 | |
233 | |
214 | Please note that the epoll method is not, in general, reliable in |
234 | Please note that the epoll method is not, in general, reliable in programs |
215 | programs that use fork (even if no libveent calls are being made in the |
235 | that use fork (even if no libveent calls are being made in the forked |
216 | forked process). Since this is such a common issue, this module will |
236 | process). If your program behaves erratically, try setting the environment |
217 | force the epoll method in EV to be off *unless* the global variable |
237 | variable C<EVENT_NOEPOLL> first when running the program. |
218 | $EV::ENABLE_EPOLL is set to 1 *before* loading this module for the first |
238 | |
219 | time. |
239 | In general, if you fork, then you can only use the EV module in one of the |
|
|
240 | children. |
220 | |
241 | |
221 | =cut |
242 | =cut |
222 | |
243 | |
|
|
244 | our $DIED = sub { |
|
|
245 | warn "EV: error in callback (ignoring): $@"; |
|
|
246 | }; |
|
|
247 | |
223 | our $NPRI = 4; |
248 | our $NPRI = 4; |
224 | our $BASE; |
|
|
225 | our $ENABLE_EPOLL; |
|
|
226 | |
|
|
227 | { |
|
|
228 | local $ENV{EVENT_NOEPOLL}; |
|
|
229 | $ENV{EVENT_NOEPOLL} = 1 unless $ENABLE_EPOLL; |
|
|
230 | $BASE = init; |
249 | our $BASE = init; |
231 | } |
|
|
232 | |
|
|
233 | priority_init $NPRI; |
250 | priority_init $NPRI; |
234 | |
251 | |
235 | push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; |
252 | push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; |
236 | |
253 | |
237 | 1; |
254 | 1; |