… | |
… | |
89 | fh = SvRV (fh); |
89 | fh = SvRV (fh); |
90 | |
90 | |
91 | if (SvTYPE (fh) == SVt_PVGV) |
91 | if (SvTYPE (fh) == SVt_PVGV) |
92 | return PerlIO_fileno (IoIFP (sv_2io (fh))); |
92 | return PerlIO_fileno (IoIFP (sv_2io (fh))); |
93 | |
93 | |
94 | if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff)) |
94 | if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL)) |
95 | return SvIV (fh); |
95 | return SvIV (fh); |
96 | |
96 | |
97 | return -1; |
97 | return -1; |
98 | } |
98 | } |
99 | |
99 | |
… | |
… | |
142 | } |
142 | } |
143 | |
143 | |
144 | return rv; |
144 | return rv; |
145 | } |
145 | } |
146 | |
146 | |
|
|
147 | static SV *sv_events_cache; |
|
|
148 | |
147 | static void |
149 | static void |
148 | e_cb (struct ev_watcher *w, int revents) |
150 | e_cb (struct ev_watcher *w, int revents) |
149 | { |
151 | { |
150 | dSP; |
152 | dSP; |
151 | I32 mark = SP - PL_stack_base; |
153 | I32 mark = SP - PL_stack_base; |
152 | SV *sv_self, *sv_events, *sv_status = 0; |
154 | SV *sv_self, *sv_events; |
153 | static SV *sv_events_cache; |
|
|
154 | |
155 | |
155 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
156 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
156 | |
157 | |
157 | if (sv_events_cache) |
158 | if (sv_events_cache) |
158 | { |
159 | { |
… | |
… | |
167 | PUSHs (sv_self); |
168 | PUSHs (sv_self); |
168 | PUSHs (sv_events); |
169 | PUSHs (sv_events); |
169 | |
170 | |
170 | PUTBACK; |
171 | PUTBACK; |
171 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
172 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
172 | SP = PL_stack_base + mark; PUTBACK; |
|
|
173 | |
173 | |
174 | SvREFCNT_dec (sv_self); |
174 | SvREFCNT_dec (sv_self); |
175 | SvREFCNT_dec (sv_status); |
|
|
176 | |
175 | |
177 | if (sv_events_cache) |
176 | if (sv_events_cache) |
178 | SvREFCNT_dec (sv_events); |
177 | SvREFCNT_dec (sv_events); |
179 | else |
178 | else |
180 | sv_events_cache = sv_events; |
179 | sv_events_cache = sv_events; |
… | |
… | |
182 | if (SvTRUE (ERRSV)) |
181 | if (SvTRUE (ERRSV)) |
183 | { |
182 | { |
184 | PUSHMARK (SP); |
183 | PUSHMARK (SP); |
185 | PUTBACK; |
184 | PUTBACK; |
186 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
185 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
187 | SP = PL_stack_base + mark; PUTBACK; |
|
|
188 | } |
186 | } |
|
|
187 | |
|
|
188 | SP = PL_stack_base + mark; |
|
|
189 | PUTBACK; |
|
|
190 | } |
|
|
191 | |
|
|
192 | static void |
|
|
193 | e_once_cb (int revents, void *arg) |
|
|
194 | { |
|
|
195 | dSP; |
|
|
196 | I32 mark = SP - PL_stack_base; |
|
|
197 | SV *sv_events; |
|
|
198 | |
|
|
199 | if (sv_events_cache) |
|
|
200 | { |
|
|
201 | sv_events = sv_events_cache; sv_events_cache = 0; |
|
|
202 | SvIV_set (sv_events, revents); |
|
|
203 | } |
|
|
204 | else |
|
|
205 | sv_events = newSViv (revents); |
|
|
206 | |
|
|
207 | PUSHMARK (SP); |
|
|
208 | XPUSHs (sv_events); |
|
|
209 | |
|
|
210 | PUTBACK; |
|
|
211 | call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL); |
|
|
212 | |
|
|
213 | SvREFCNT_dec ((SV *)arg); |
|
|
214 | |
|
|
215 | if (sv_events_cache) |
|
|
216 | SvREFCNT_dec (sv_events); |
|
|
217 | else |
|
|
218 | sv_events_cache = sv_events; |
|
|
219 | |
|
|
220 | if (SvTRUE (ERRSV)) |
|
|
221 | { |
|
|
222 | PUSHMARK (SP); |
|
|
223 | PUTBACK; |
|
|
224 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
225 | } |
|
|
226 | |
|
|
227 | SP = PL_stack_base + mark; |
|
|
228 | PUTBACK; |
189 | } |
229 | } |
190 | |
230 | |
191 | static ev_tstamp |
231 | static ev_tstamp |
192 | e_periodic_cb (struct ev_periodic *w, ev_tstamp now) |
232 | e_periodic_cb (struct ev_periodic *w, ev_tstamp now) |
193 | { |
233 | { |
… | |
… | |
323 | const_iv (EV, LOOP_ONESHOT) |
363 | const_iv (EV, LOOP_ONESHOT) |
324 | const_iv (EV, LOOP_NONBLOCK) |
364 | const_iv (EV, LOOP_NONBLOCK) |
325 | const_iv (EV, UNLOOP_ONE) |
365 | const_iv (EV, UNLOOP_ONE) |
326 | const_iv (EV, UNLOOP_ALL) |
366 | const_iv (EV, UNLOOP_ALL) |
327 | |
367 | |
328 | const_iv (EV, METHOD_SELECT) |
368 | const_iv (EV, BACKEND_SELECT) |
329 | const_iv (EV, METHOD_POLL) |
369 | const_iv (EV, BACKEND_POLL) |
330 | const_iv (EV, METHOD_EPOLL) |
370 | const_iv (EV, BACKEND_EPOLL) |
331 | const_iv (EV, METHOD_KQUEUE) |
371 | const_iv (EV, BACKEND_KQUEUE) |
332 | const_iv (EV, METHOD_DEVPOLL) |
372 | const_iv (EV, BACKEND_DEVPOLL) |
333 | const_iv (EV, METHOD_PORT) |
373 | const_iv (EV, BACKEND_PORT) |
334 | const_iv (EV, FLAG_AUTO) |
374 | const_iv (EV, FLAG_AUTO) |
335 | const_iv (EV, FLAG_NOENV) |
375 | const_iv (EV, FLAG_NOENV) |
336 | }; |
376 | }; |
337 | |
377 | |
338 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
378 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
… | |
… | |
356 | evapi.ver = EV_API_VERSION; |
396 | evapi.ver = EV_API_VERSION; |
357 | evapi.rev = EV_API_REVISION; |
397 | evapi.rev = EV_API_REVISION; |
358 | evapi.sv_fileno = sv_fileno; |
398 | evapi.sv_fileno = sv_fileno; |
359 | evapi.sv_signum = sv_signum; |
399 | evapi.sv_signum = sv_signum; |
360 | evapi.now = ev_now; |
400 | evapi.now = ev_now; |
361 | evapi.method = ev_method; |
401 | evapi.backend = ev_backend; |
362 | evapi.unloop = ev_unloop; |
402 | evapi.unloop = ev_unloop; |
363 | evapi.time = ev_time; |
403 | evapi.time = ev_time; |
364 | evapi.loop = ev_loop; |
404 | evapi.loop = ev_loop; |
365 | evapi.once = ev_once; |
405 | evapi.once = ev_once; |
366 | evapi.io_start = ev_io_start; |
406 | evapi.io_start = ev_io_start; |
… | |
… | |
389 | #endif |
429 | #endif |
390 | } |
430 | } |
391 | |
431 | |
392 | NV ev_now () |
432 | NV ev_now () |
393 | |
433 | |
394 | int ev_method () |
434 | unsigned int ev_backend () |
395 | |
435 | |
396 | NV ev_time () |
436 | NV ev_time () |
397 | |
437 | |
398 | int ev_default_loop (int methods = EVFLAG_AUTO) |
438 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
399 | |
439 | |
400 | void ev_loop (int flags = 0) |
440 | void ev_loop (int flags = 0) |
401 | |
441 | |
402 | void ev_unloop (int how = 1) |
442 | void ev_unloop (int how = 1) |
403 | |
443 | |
… | |
… | |
486 | OUTPUT: |
526 | OUTPUT: |
487 | RETVAL |
527 | RETVAL |
488 | |
528 | |
489 | struct ev_child *child (int pid, SV *cb) |
529 | struct ev_child *child (int pid, SV *cb) |
490 | ALIAS: |
530 | ALIAS: |
491 | check_ns = 1 |
531 | child_ns = 1 |
492 | CODE: |
532 | CODE: |
493 | RETVAL = e_new (sizeof (struct ev_child), cb); |
533 | RETVAL = e_new (sizeof (struct ev_child), cb); |
494 | ev_child_set (RETVAL, pid); |
534 | ev_child_set (RETVAL, pid); |
495 | if (!ix) ev_child_start (RETVAL); |
535 | if (!ix) ev_child_start (RETVAL); |
496 | OUTPUT: |
536 | OUTPUT: |
497 | RETVAL |
537 | RETVAL |
498 | |
538 | |
|
|
539 | void once (SV *fh, int events, NV timeout, SV *cb) |
|
|
540 | CODE: |
|
|
541 | ev_once (sv_fileno (fh), events, timeout, e_once_cb, newSVsv (cb)); |
499 | |
542 | |
500 | PROTOTYPES: DISABLE |
543 | PROTOTYPES: DISABLE |
501 | |
544 | |
502 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
545 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
503 | |
546 | |