… | |
… | |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | /*#include <netinet/in.h>*/ |
5 | /*#include <netinet/in.h>*/ |
6 | |
6 | |
7 | #define TIMEOUT_NONE HUGE_VAL |
|
|
8 | #define EV_USE_EPOLL 1 |
|
|
9 | |
|
|
10 | #define EV_PROTOTYPES 1 |
7 | #define EV_PROTOTYPES 1 |
11 | #include "EV/EVAPI.h" |
8 | #include "EV/EVAPI.h" |
12 | |
9 | |
13 | #include "libev/ev.c" |
10 | #include "libev/ev.c" |
|
|
11 | #include "libev/event.h" |
|
|
12 | #include "libev/event.c" |
|
|
13 | #include "libev/evdns.c" |
14 | |
14 | |
15 | typedef int Signal; |
15 | typedef int Signal; |
16 | |
16 | |
17 | static struct EVAPI evapi; |
17 | static struct EVAPI evapi; |
18 | |
18 | |
… | |
… | |
156 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
156 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
157 | SP = PL_stack_base + mark; PUTBACK; |
157 | SP = PL_stack_base + mark; PUTBACK; |
158 | } |
158 | } |
159 | } |
159 | } |
160 | |
160 | |
161 | #if 0 |
|
|
162 | ///////////////////////////////////////////////////////////////////////////// |
161 | ///////////////////////////////////////////////////////////////////////////// |
163 | // DNS |
162 | // DNS |
164 | |
163 | |
165 | static void |
164 | static void |
166 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
165 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
… | |
… | |
208 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
207 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
209 | } |
208 | } |
210 | |
209 | |
211 | LEAVE; |
210 | LEAVE; |
212 | } |
211 | } |
213 | #endif |
|
|
214 | |
212 | |
215 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
213 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
216 | croak (# repeat " value must be >= 0"); |
214 | croak (# repeat " value must be >= 0"); |
217 | |
215 | |
218 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
216 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
233 | static const struct { |
231 | static const struct { |
234 | const char *name; |
232 | const char *name; |
235 | IV iv; |
233 | IV iv; |
236 | } *civ, const_iv[] = { |
234 | } *civ, const_iv[] = { |
237 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
235 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
236 | const_iv (EV_, MINPRI) |
|
|
237 | const_iv (EV_, MAXPRI) |
|
|
238 | |
238 | const_iv (EV_, UNDEF) |
239 | const_iv (EV_, UNDEF) |
239 | const_iv (EV_, NONE) |
240 | const_iv (EV_, NONE) |
240 | const_iv (EV_, TIMEOUT) |
241 | const_iv (EV_, TIMEOUT) |
241 | const_iv (EV_, READ) |
242 | const_iv (EV_, READ) |
242 | const_iv (EV_, WRITE) |
243 | const_iv (EV_, WRITE) |
… | |
… | |
246 | const_iv (EV_, ERROR) |
247 | const_iv (EV_, ERROR) |
247 | |
248 | |
248 | const_iv (EV, LOOP_ONESHOT) |
249 | const_iv (EV, LOOP_ONESHOT) |
249 | const_iv (EV, LOOP_NONBLOCK) |
250 | const_iv (EV, LOOP_NONBLOCK) |
250 | |
251 | |
251 | const_iv (EV, METHOD_NONE) |
252 | const_iv (EV, METHOD_AUTO) |
252 | const_iv (EV, METHOD_SELECT) |
253 | const_iv (EV, METHOD_SELECT) |
|
|
254 | const_iv (EV, METHOD_POLL) |
253 | const_iv (EV, METHOD_EPOLL) |
255 | const_iv (EV, METHOD_EPOLL) |
|
|
256 | const_iv (EV, METHOD_KQUEUE) |
|
|
257 | const_iv (EV, METHOD_DEVPOLL) |
|
|
258 | const_iv (EV, METHOD_PORT) |
|
|
259 | const_iv (EV, METHOD_ANY) |
254 | }; |
260 | }; |
255 | |
261 | |
256 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
262 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
257 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
263 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
258 | |
264 | |
… | |
… | |
318 | OUTPUT: |
324 | OUTPUT: |
319 | RETVAL |
325 | RETVAL |
320 | |
326 | |
321 | NV ev_time () |
327 | NV ev_time () |
322 | |
328 | |
323 | void ev_init (int flags = 0) |
329 | void ev_init (int methods = EVMETHOD_AUTO) |
324 | |
330 | |
325 | void ev_loop (int flags = 0) |
331 | void ev_loop (int flags = 0) |
326 | |
332 | |
327 | void ev_loop_done (int value = 1) |
333 | void ev_loop_done (int value = 1) |
328 | CODE: |
334 | CODE: |
… | |
… | |
438 | |
444 | |
439 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
445 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
440 | CODE: |
446 | CODE: |
441 | w->cb (w, revents); |
447 | w->cb (w, revents); |
442 | |
448 | |
|
|
449 | int priority (struct ev_watcher *w, int new_priority = 0) |
|
|
450 | CODE: |
|
|
451 | { |
|
|
452 | RETVAL = w->priority; |
|
|
453 | |
|
|
454 | if (items > 1) |
|
|
455 | { |
|
|
456 | int active = ev_is_active (w); |
|
|
457 | |
|
|
458 | if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI) |
|
|
459 | croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI); |
|
|
460 | |
|
|
461 | if (active) |
|
|
462 | { |
|
|
463 | /* grrr. */ |
|
|
464 | PUSHMARK (SP); |
|
|
465 | XPUSHs (ST (0)); |
|
|
466 | call_method ("stop", G_DISCARD | G_VOID); |
|
|
467 | } |
|
|
468 | |
|
|
469 | ev_set_priority (w, new_priority); |
|
|
470 | |
|
|
471 | if (active) |
|
|
472 | { |
|
|
473 | PUSHMARK (SP); |
|
|
474 | XPUSHs (ST (0)); |
|
|
475 | call_method ("start", G_DISCARD | G_VOID); |
|
|
476 | } |
|
|
477 | } |
|
|
478 | } |
|
|
479 | OUTPUT: |
|
|
480 | RETVAL |
|
|
481 | |
443 | MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ |
482 | MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ |
444 | |
483 | |
445 | void ev_io_start (struct ev_io *w) |
484 | void ev_io_start (struct ev_io *w) |
446 | |
485 | |
447 | void ev_io_stop (struct ev_io *w) |
486 | void ev_io_stop (struct ev_io *w) |
… | |
… | |
452 | e_destroy (w); |
491 | e_destroy (w); |
453 | |
492 | |
454 | void set (struct ev_io *w, SV *fh, int events) |
493 | void set (struct ev_io *w, SV *fh, int events) |
455 | CODE: |
494 | CODE: |
456 | { |
495 | { |
457 | int active = w->active; |
496 | int active = ev_is_active (w); |
458 | int fd = sv_fileno (fh); |
497 | int fd = sv_fileno (fh); |
459 | CHECK_FD (fh, fd); |
498 | CHECK_FD (fh, fd); |
460 | |
499 | |
461 | if (active) ev_io_stop (w); |
500 | if (active) ev_io_stop (w); |
462 | |
501 | |
… | |
… | |
471 | { |
510 | { |
472 | RETVAL = newSVsv (w->fh); |
511 | RETVAL = newSVsv (w->fh); |
473 | |
512 | |
474 | if (items > 1) |
513 | if (items > 1) |
475 | { |
514 | { |
476 | int active = w->active; |
515 | int active = ev_is_active (w); |
477 | if (active) ev_io_stop (w); |
516 | if (active) ev_io_stop (w); |
478 | |
517 | |
479 | sv_setsv (w->fh, new_fh); |
518 | sv_setsv (w->fh, new_fh); |
480 | ev_io_set (w, sv_fileno (w->fh), w->events); |
519 | ev_io_set (w, sv_fileno (w->fh), w->events); |
481 | |
520 | |
… | |
… | |
483 | } |
522 | } |
484 | } |
523 | } |
485 | OUTPUT: |
524 | OUTPUT: |
486 | RETVAL |
525 | RETVAL |
487 | |
526 | |
488 | short events (struct ev_io *w, short new_events = EV_UNDEF) |
527 | int events (struct ev_io *w, int new_events = EV_UNDEF) |
489 | CODE: |
528 | CODE: |
490 | { |
529 | { |
491 | RETVAL = w->events; |
530 | RETVAL = w->events; |
492 | |
531 | |
493 | if (items > 1) |
532 | if (items > 1) |
494 | { |
533 | { |
495 | int active = w->active; |
534 | int active = ev_is_active (w); |
496 | if (active) ev_io_stop (w); |
535 | if (active) ev_io_stop (w); |
497 | |
536 | |
498 | ev_io_set (w, w->fd, new_events); |
537 | ev_io_set (w, w->fd, new_events); |
499 | |
538 | |
500 | if (active) ev_io_start (w); |
539 | if (active) ev_io_start (w); |
… | |
… | |
512 | void DESTROY (struct ev_signal *w) |
551 | void DESTROY (struct ev_signal *w) |
513 | CODE: |
552 | CODE: |
514 | ev_signal_stop (w); |
553 | ev_signal_stop (w); |
515 | e_destroy (w); |
554 | e_destroy (w); |
516 | |
555 | |
517 | void set (struct ev_signal *w, SV *signal = 0) |
556 | void set (struct ev_signal *w, SV *signal) |
518 | CODE: |
557 | CODE: |
519 | { |
558 | { |
520 | Signal signum = sv_signum (signal); /* may croak here */ |
559 | Signal signum = sv_signum (signal); /* may croak here */ |
521 | int active = w->active; |
560 | int active = ev_is_active (w); |
522 | |
561 | |
523 | if (active) ev_signal_stop (w); |
562 | if (active) ev_signal_stop (w); |
|
|
563 | |
524 | ev_signal_set (w, signum); |
564 | ev_signal_set (w, signum); |
|
|
565 | |
525 | if (active) ev_signal_start (w); |
566 | if (active) ev_signal_start (w); |
526 | } |
567 | } |
|
|
568 | |
|
|
569 | int signal (struct ev_signal *w, SV *new_signal = 0) |
|
|
570 | CODE: |
|
|
571 | { |
|
|
572 | RETVAL = w->signum; |
|
|
573 | |
|
|
574 | if (items > 1) |
|
|
575 | { |
|
|
576 | Signal signum = sv_signum (new_signal); /* may croak here */ |
|
|
577 | int active = ev_is_active (w); |
|
|
578 | if (active) ev_signal_stop (w); |
|
|
579 | |
|
|
580 | ev_signal_set (w, signum); |
|
|
581 | |
|
|
582 | if (active) ev_signal_start (w); |
|
|
583 | } |
|
|
584 | } |
|
|
585 | OUTPUT: |
|
|
586 | RETVAL |
527 | |
587 | |
528 | MODULE = EV PACKAGE = EV::Time |
588 | MODULE = EV PACKAGE = EV::Time |
529 | |
589 | |
530 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
590 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
531 | |
591 | |
… | |
… | |
547 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
607 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
548 | INIT: |
608 | INIT: |
549 | CHECK_REPEAT (repeat); |
609 | CHECK_REPEAT (repeat); |
550 | CODE: |
610 | CODE: |
551 | { |
611 | { |
552 | int active = w->active; |
612 | int active = ev_is_active (w); |
553 | if (active) ev_timer_stop (w); |
613 | if (active) ev_timer_stop (w); |
554 | ev_timer_set (w, after, repeat); |
614 | ev_timer_set (w, after, repeat); |
555 | if (active) ev_timer_start (w); |
615 | if (active) ev_timer_start (w); |
556 | } |
616 | } |
557 | |
617 | |
… | |
… | |
571 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
631 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
572 | INIT: |
632 | INIT: |
573 | CHECK_REPEAT (interval); |
633 | CHECK_REPEAT (interval); |
574 | CODE: |
634 | CODE: |
575 | { |
635 | { |
576 | int active = w->active; |
636 | int active = ev_is_active (w); |
577 | if (active) ev_periodic_stop (w); |
637 | if (active) ev_periodic_stop (w); |
|
|
638 | |
578 | ev_periodic_set (w, at, interval); |
639 | ev_periodic_set (w, at, interval); |
|
|
640 | |
579 | if (active) ev_periodic_start (w); |
641 | if (active) ev_periodic_start (w); |
580 | } |
642 | } |
581 | |
643 | |
582 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
644 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
583 | |
645 | |
… | |
… | |
624 | e_destroy (w); |
686 | e_destroy (w); |
625 | |
687 | |
626 | void set (struct ev_child *w, int pid) |
688 | void set (struct ev_child *w, int pid) |
627 | CODE: |
689 | CODE: |
628 | { |
690 | { |
629 | int active = w->active; |
691 | int active = ev_is_active (w); |
630 | if (active) ev_child_stop (w); |
692 | if (active) ev_child_stop (w); |
|
|
693 | |
631 | ev_child_set (w, pid); |
694 | ev_child_set (w, pid); |
|
|
695 | |
632 | if (active) ev_child_start (w); |
696 | if (active) ev_child_start (w); |
633 | } |
697 | } |
634 | |
698 | |
|
|
699 | int pid (struct ev_child *w, int new_pid = 0) |
|
|
700 | CODE: |
|
|
701 | { |
|
|
702 | RETVAL = w->pid; |
|
|
703 | |
|
|
704 | if (items > 1) |
|
|
705 | { |
|
|
706 | int active = ev_is_active (w); |
|
|
707 | if (active) ev_child_stop (w); |
|
|
708 | |
|
|
709 | ev_child_set (w, new_pid); |
|
|
710 | |
|
|
711 | if (active) ev_child_start (w); |
|
|
712 | } |
|
|
713 | } |
|
|
714 | OUTPUT: |
|
|
715 | RETVAL |
|
|
716 | |
|
|
717 | |
635 | int status (struct ev_child *w) |
718 | int status (struct ev_child *w) |
636 | CODE: |
719 | CODE: |
637 | RETVAL = w->status; |
720 | RETVAL = w->status; |
638 | OUTPUT: |
721 | OUTPUT: |
639 | RETVAL |
722 | RETVAL |
640 | |
|
|
641 | #if 0 |
|
|
642 | |
723 | |
643 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
724 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
644 | |
725 | |
645 | BOOT: |
726 | BOOT: |
646 | { |
727 | { |
… | |
… | |
729 | |
810 | |
730 | void evdns_search_add (char *domain) |
811 | void evdns_search_add (char *domain) |
731 | |
812 | |
732 | void evdns_search_ndots_set (int ndots) |
813 | void evdns_search_ndots_set (int ndots) |
733 | |
814 | |
|
|
815 | #if 0 |
734 | |
816 | |
735 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
817 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
736 | |
818 | |
737 | BOOT: |
819 | BOOT: |
738 | { |
820 | { |