… | |
… | |
8 | #include "EV/EVAPI.h" |
8 | #include "EV/EVAPI.h" |
9 | |
9 | |
10 | #include "libev/ev.c" |
10 | #include "libev/ev.c" |
11 | #include "libev/event.h" |
11 | #include "libev/event.h" |
12 | #include "libev/event.c" |
12 | #include "libev/event.c" |
|
|
13 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
|
|
14 | #define HAVE_STRUCT_IN6_ADDR 1 |
|
|
15 | #undef HAVE_STRTOK_R |
|
|
16 | #undef strtok_r |
|
|
17 | #define strtok_r fake_strtok_r |
|
|
18 | #include "libev/evdns.h" |
13 | #include "libev/evdns.c" |
19 | #include "libev/evdns.c" |
14 | |
20 | |
15 | typedef int Signal; |
21 | typedef int Signal; |
16 | |
22 | |
17 | static struct EVAPI evapi; |
23 | static struct EVAPI evapi; |
… | |
… | |
25 | *stash_idle, |
31 | *stash_idle, |
26 | *stash_prepare, |
32 | *stash_prepare, |
27 | *stash_check, |
33 | *stash_check, |
28 | *stash_child; |
34 | *stash_child; |
29 | |
35 | |
|
|
36 | #ifndef SIG_SIZE |
|
|
37 | /* kudos to Slaven Rezic for the idea */ |
|
|
38 | static char sig_size [] = { SIG_NUM }; |
|
|
39 | # define SIG_SIZE (sizeof (sig_size) + 1) |
|
|
40 | #endif |
|
|
41 | |
30 | static int |
42 | static int |
31 | sv_signum (SV *sig) |
43 | sv_signum (SV *sig) |
32 | { |
44 | { |
33 | int signum; |
45 | int signum; |
34 | |
46 | |
… | |
… | |
131 | |
143 | |
132 | PUSHMARK (SP); |
144 | PUSHMARK (SP); |
133 | EXTEND (SP, 2); |
145 | EXTEND (SP, 2); |
134 | PUSHs (sv_self); |
146 | PUSHs (sv_self); |
135 | PUSHs (sv_events); |
147 | PUSHs (sv_events); |
136 | |
|
|
137 | if (revents & EV_CHILD) |
|
|
138 | XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status)); |
|
|
139 | |
148 | |
140 | PUTBACK; |
149 | PUTBACK; |
141 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
150 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
142 | SP = PL_stack_base + mark; PUTBACK; |
151 | SP = PL_stack_base + mark; PUTBACK; |
143 | |
152 | |
… | |
… | |
231 | static const struct { |
240 | static const struct { |
232 | const char *name; |
241 | const char *name; |
233 | IV iv; |
242 | IV iv; |
234 | } *civ, const_iv[] = { |
243 | } *civ, const_iv[] = { |
235 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
244 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
245 | const_iv (EV_, MINPRI) |
|
|
246 | const_iv (EV_, MAXPRI) |
|
|
247 | |
236 | const_iv (EV_, UNDEF) |
248 | const_iv (EV_, UNDEF) |
237 | const_iv (EV_, NONE) |
249 | const_iv (EV_, NONE) |
238 | const_iv (EV_, TIMEOUT) |
250 | const_iv (EV_, TIMEOUT) |
239 | const_iv (EV_, READ) |
251 | const_iv (EV_, READ) |
240 | const_iv (EV_, WRITE) |
252 | const_iv (EV_, WRITE) |
… | |
… | |
244 | const_iv (EV_, ERROR) |
256 | const_iv (EV_, ERROR) |
245 | |
257 | |
246 | const_iv (EV, LOOP_ONESHOT) |
258 | const_iv (EV, LOOP_ONESHOT) |
247 | const_iv (EV, LOOP_NONBLOCK) |
259 | const_iv (EV, LOOP_NONBLOCK) |
248 | |
260 | |
249 | const_iv (EV, METHOD_NONE) |
261 | const_iv (EV, METHOD_AUTO) |
250 | const_iv (EV, METHOD_SELECT) |
262 | const_iv (EV, METHOD_SELECT) |
|
|
263 | const_iv (EV, METHOD_POLL) |
251 | const_iv (EV, METHOD_EPOLL) |
264 | const_iv (EV, METHOD_EPOLL) |
|
|
265 | const_iv (EV, METHOD_KQUEUE) |
|
|
266 | const_iv (EV, METHOD_DEVPOLL) |
|
|
267 | const_iv (EV, METHOD_PORT) |
|
|
268 | const_iv (EV, METHOD_ANY) |
252 | }; |
269 | }; |
253 | |
270 | |
254 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
271 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
255 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
272 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
256 | |
273 | |
… | |
… | |
271 | /* the poor man's shared library emulator */ |
288 | /* the poor man's shared library emulator */ |
272 | evapi.ver = EV_API_VERSION; |
289 | evapi.ver = EV_API_VERSION; |
273 | evapi.rev = EV_API_REVISION; |
290 | evapi.rev = EV_API_REVISION; |
274 | evapi.sv_fileno = sv_fileno; |
291 | evapi.sv_fileno = sv_fileno; |
275 | evapi.sv_signum = sv_signum; |
292 | evapi.sv_signum = sv_signum; |
276 | evapi.now = &ev_now; |
293 | evapi.now = ev_now; |
277 | evapi.method = &ev_method; |
294 | evapi.method = ev_method; |
278 | evapi.loop_done = &ev_loop_done; |
295 | evapi.unloop = ev_unloop; |
279 | evapi.time = ev_time; |
296 | evapi.time = ev_time; |
280 | evapi.loop = ev_loop; |
297 | evapi.loop = ev_loop; |
281 | evapi.once = ev_once; |
298 | evapi.once = ev_once; |
282 | evapi.io_start = ev_io_start; |
299 | evapi.io_start = ev_io_start; |
283 | evapi.io_stop = ev_io_stop; |
300 | evapi.io_stop = ev_io_stop; |
… | |
… | |
299 | |
316 | |
300 | sv_setiv (sv, (IV)&evapi); |
317 | sv_setiv (sv, (IV)&evapi); |
301 | SvREADONLY_on (sv); |
318 | SvREADONLY_on (sv); |
302 | } |
319 | } |
303 | |
320 | |
304 | pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child); |
321 | pthread_atfork (0, 0, ev_default_fork); |
305 | } |
322 | } |
306 | |
323 | |
307 | NV ev_now () |
324 | NV ev_now () |
308 | CODE: |
|
|
309 | RETVAL = ev_now; |
|
|
310 | OUTPUT: |
|
|
311 | RETVAL |
|
|
312 | |
325 | |
313 | int ev_method () |
326 | int ev_method () |
314 | CODE: |
|
|
315 | RETVAL = ev_method; |
|
|
316 | OUTPUT: |
|
|
317 | RETVAL |
|
|
318 | |
327 | |
319 | NV ev_time () |
328 | NV ev_time () |
320 | |
329 | |
321 | void ev_init (int flags = 0) |
330 | int ev_default_loop (int methods = EVMETHOD_AUTO) |
322 | |
331 | |
323 | void ev_loop (int flags = 0) |
332 | void ev_loop (int flags = 0) |
324 | |
333 | |
325 | void ev_loop_done (int value = 1) |
334 | void ev_unloop (int how = 1) |
326 | CODE: |
|
|
327 | ev_loop_done = value; |
|
|
328 | |
335 | |
329 | struct ev_io *io (SV *fh, int events, SV *cb) |
336 | struct ev_io *io (SV *fh, int events, SV *cb) |
330 | ALIAS: |
337 | ALIAS: |
331 | io_ns = 1 |
338 | io_ns = 1 |
332 | CODE: |
339 | CODE: |
… | |
… | |
408 | |
415 | |
409 | struct ev_child *child (int pid, SV *cb) |
416 | struct ev_child *child (int pid, SV *cb) |
410 | ALIAS: |
417 | ALIAS: |
411 | check_ns = 1 |
418 | check_ns = 1 |
412 | CODE: |
419 | CODE: |
413 | RETVAL = e_new (sizeof (struct ev_check), cb); |
420 | RETVAL = e_new (sizeof (struct ev_child), cb); |
414 | ev_child_set (RETVAL, pid); |
421 | ev_child_set (RETVAL, pid); |
415 | if (!ix) ev_child_start (RETVAL); |
422 | if (!ix) ev_child_start (RETVAL); |
416 | OUTPUT: |
423 | OUTPUT: |
417 | RETVAL |
424 | RETVAL |
418 | |
425 | |
… | |
… | |
436 | |
443 | |
437 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
444 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
438 | CODE: |
445 | CODE: |
439 | w->cb (w, revents); |
446 | w->cb (w, revents); |
440 | |
447 | |
|
|
448 | int priority (struct ev_watcher *w, int new_priority = 0) |
|
|
449 | CODE: |
|
|
450 | { |
|
|
451 | RETVAL = w->priority; |
|
|
452 | |
|
|
453 | if (items > 1) |
|
|
454 | { |
|
|
455 | int active = ev_is_active (w); |
|
|
456 | |
|
|
457 | if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI) |
|
|
458 | croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI); |
|
|
459 | |
|
|
460 | if (active) |
|
|
461 | { |
|
|
462 | /* grrr. */ |
|
|
463 | PUSHMARK (SP); |
|
|
464 | XPUSHs (ST (0)); |
|
|
465 | call_method ("stop", G_DISCARD | G_VOID); |
|
|
466 | } |
|
|
467 | |
|
|
468 | ev_set_priority (w, new_priority); |
|
|
469 | |
|
|
470 | if (active) |
|
|
471 | { |
|
|
472 | PUSHMARK (SP); |
|
|
473 | XPUSHs (ST (0)); |
|
|
474 | call_method ("start", G_DISCARD | G_VOID); |
|
|
475 | } |
|
|
476 | } |
|
|
477 | } |
|
|
478 | OUTPUT: |
|
|
479 | RETVAL |
|
|
480 | |
441 | MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ |
481 | MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ |
442 | |
482 | |
443 | void ev_io_start (struct ev_io *w) |
483 | void ev_io_start (struct ev_io *w) |
444 | |
484 | |
445 | void ev_io_stop (struct ev_io *w) |
485 | void ev_io_stop (struct ev_io *w) |
… | |
… | |
450 | e_destroy (w); |
490 | e_destroy (w); |
451 | |
491 | |
452 | void set (struct ev_io *w, SV *fh, int events) |
492 | void set (struct ev_io *w, SV *fh, int events) |
453 | CODE: |
493 | CODE: |
454 | { |
494 | { |
455 | int active = w->active; |
495 | int active = ev_is_active (w); |
456 | int fd = sv_fileno (fh); |
496 | int fd = sv_fileno (fh); |
457 | CHECK_FD (fh, fd); |
497 | CHECK_FD (fh, fd); |
458 | |
498 | |
459 | if (active) ev_io_stop (w); |
499 | if (active) ev_io_stop (w); |
460 | |
500 | |
… | |
… | |
469 | { |
509 | { |
470 | RETVAL = newSVsv (w->fh); |
510 | RETVAL = newSVsv (w->fh); |
471 | |
511 | |
472 | if (items > 1) |
512 | if (items > 1) |
473 | { |
513 | { |
474 | int active = w->active; |
514 | int active = ev_is_active (w); |
475 | if (active) ev_io_stop (w); |
515 | if (active) ev_io_stop (w); |
476 | |
516 | |
477 | sv_setsv (w->fh, new_fh); |
517 | sv_setsv (w->fh, new_fh); |
478 | ev_io_set (w, sv_fileno (w->fh), w->events); |
518 | ev_io_set (w, sv_fileno (w->fh), w->events); |
479 | |
519 | |
… | |
… | |
488 | { |
528 | { |
489 | RETVAL = w->events; |
529 | RETVAL = w->events; |
490 | |
530 | |
491 | if (items > 1) |
531 | if (items > 1) |
492 | { |
532 | { |
493 | int active = w->active; |
533 | int active = ev_is_active (w); |
494 | if (active) ev_io_stop (w); |
534 | if (active) ev_io_stop (w); |
495 | |
535 | |
496 | ev_io_set (w, w->fd, new_events); |
536 | ev_io_set (w, w->fd, new_events); |
497 | |
537 | |
498 | if (active) ev_io_start (w); |
538 | if (active) ev_io_start (w); |
… | |
… | |
510 | void DESTROY (struct ev_signal *w) |
550 | void DESTROY (struct ev_signal *w) |
511 | CODE: |
551 | CODE: |
512 | ev_signal_stop (w); |
552 | ev_signal_stop (w); |
513 | e_destroy (w); |
553 | e_destroy (w); |
514 | |
554 | |
515 | void set (struct ev_signal *w, SV *signal = 0) |
555 | void set (struct ev_signal *w, SV *signal) |
516 | CODE: |
556 | CODE: |
517 | { |
557 | { |
518 | Signal signum = sv_signum (signal); /* may croak here */ |
558 | Signal signum = sv_signum (signal); /* may croak here */ |
519 | int active = w->active; |
559 | int active = ev_is_active (w); |
520 | |
560 | |
521 | if (active) ev_signal_stop (w); |
561 | if (active) ev_signal_stop (w); |
|
|
562 | |
522 | ev_signal_set (w, signum); |
563 | ev_signal_set (w, signum); |
|
|
564 | |
523 | if (active) ev_signal_start (w); |
565 | if (active) ev_signal_start (w); |
524 | } |
566 | } |
|
|
567 | |
|
|
568 | int signal (struct ev_signal *w, SV *new_signal = 0) |
|
|
569 | CODE: |
|
|
570 | { |
|
|
571 | RETVAL = w->signum; |
|
|
572 | |
|
|
573 | if (items > 1) |
|
|
574 | { |
|
|
575 | Signal signum = sv_signum (new_signal); /* may croak here */ |
|
|
576 | int active = ev_is_active (w); |
|
|
577 | if (active) ev_signal_stop (w); |
|
|
578 | |
|
|
579 | ev_signal_set (w, signum); |
|
|
580 | |
|
|
581 | if (active) ev_signal_start (w); |
|
|
582 | } |
|
|
583 | } |
|
|
584 | OUTPUT: |
|
|
585 | RETVAL |
525 | |
586 | |
526 | MODULE = EV PACKAGE = EV::Time |
587 | MODULE = EV PACKAGE = EV::Time |
527 | |
588 | |
528 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
589 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
529 | |
590 | |
… | |
… | |
545 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
606 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
546 | INIT: |
607 | INIT: |
547 | CHECK_REPEAT (repeat); |
608 | CHECK_REPEAT (repeat); |
548 | CODE: |
609 | CODE: |
549 | { |
610 | { |
550 | int active = w->active; |
611 | int active = ev_is_active (w); |
551 | if (active) ev_timer_stop (w); |
612 | if (active) ev_timer_stop (w); |
552 | ev_timer_set (w, after, repeat); |
613 | ev_timer_set (w, after, repeat); |
553 | if (active) ev_timer_start (w); |
614 | if (active) ev_timer_start (w); |
554 | } |
615 | } |
555 | |
616 | |
… | |
… | |
569 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
630 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
570 | INIT: |
631 | INIT: |
571 | CHECK_REPEAT (interval); |
632 | CHECK_REPEAT (interval); |
572 | CODE: |
633 | CODE: |
573 | { |
634 | { |
574 | int active = w->active; |
635 | int active = ev_is_active (w); |
575 | if (active) ev_periodic_stop (w); |
636 | if (active) ev_periodic_stop (w); |
|
|
637 | |
576 | ev_periodic_set (w, at, interval); |
638 | ev_periodic_set (w, at, interval); |
|
|
639 | |
577 | if (active) ev_periodic_start (w); |
640 | if (active) ev_periodic_start (w); |
578 | } |
641 | } |
579 | |
642 | |
580 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
643 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
581 | |
644 | |
… | |
… | |
622 | e_destroy (w); |
685 | e_destroy (w); |
623 | |
686 | |
624 | void set (struct ev_child *w, int pid) |
687 | void set (struct ev_child *w, int pid) |
625 | CODE: |
688 | CODE: |
626 | { |
689 | { |
627 | int active = w->active; |
690 | int active = ev_is_active (w); |
628 | if (active) ev_child_stop (w); |
691 | if (active) ev_child_stop (w); |
|
|
692 | |
629 | ev_child_set (w, pid); |
693 | ev_child_set (w, pid); |
|
|
694 | |
630 | if (active) ev_child_start (w); |
695 | if (active) ev_child_start (w); |
631 | } |
696 | } |
632 | |
697 | |
|
|
698 | int pid (struct ev_child *w, int new_pid = 0) |
|
|
699 | CODE: |
|
|
700 | { |
|
|
701 | RETVAL = w->pid; |
|
|
702 | |
|
|
703 | if (items > 1) |
|
|
704 | { |
|
|
705 | int active = ev_is_active (w); |
|
|
706 | if (active) ev_child_stop (w); |
|
|
707 | |
|
|
708 | ev_child_set (w, new_pid); |
|
|
709 | |
|
|
710 | if (active) ev_child_start (w); |
|
|
711 | } |
|
|
712 | } |
|
|
713 | OUTPUT: |
|
|
714 | RETVAL |
|
|
715 | |
|
|
716 | |
633 | int status (struct ev_child *w) |
717 | int rstatus (struct ev_child *w) |
|
|
718 | ALIAS: |
|
|
719 | rpid = 1 |
634 | CODE: |
720 | CODE: |
635 | RETVAL = w->status; |
721 | RETVAL = ix ? w->rpid : w->rstatus; |
636 | OUTPUT: |
722 | OUTPUT: |
637 | RETVAL |
723 | RETVAL |
638 | |
724 | |
639 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
725 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
640 | |
726 | |