… | |
… | |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | /*#include <netinet/in.h>*/ |
5 | /*#include <netinet/in.h>*/ |
6 | |
6 | |
7 | #define EV_PROTOTYPES 1 |
7 | #define EV_PROTOTYPES 1 |
|
|
8 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
|
|
9 | #define EV_H <ev.h> |
8 | #include "EV/EVAPI.h" |
10 | #include "EV/EVAPI.h" |
9 | |
11 | |
10 | /* fix perl api breakage */ |
12 | /* fix perl api breakage */ |
11 | #undef signal |
13 | #undef signal |
12 | #undef sigaction |
14 | #undef sigaction |
… | |
… | |
17 | # define NFDBITS PERL_NFDBITS |
19 | # define NFDBITS PERL_NFDBITS |
18 | # define fd_mask Perl_fd_mask |
20 | # define fd_mask Perl_fd_mask |
19 | #endif |
21 | #endif |
20 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
22 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
21 | #include "libev/ev.c" |
23 | #include "libev/ev.c" |
22 | #include "event.c" |
|
|
23 | |
24 | |
24 | #ifndef _WIN32 |
25 | #ifndef _WIN32 |
25 | # include <pthread.h> |
26 | # include <pthread.h> |
26 | #endif |
27 | #endif |
27 | |
28 | |
|
|
29 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
|
|
30 | |
28 | #define WFLAG_KEEPALIVE 1 |
31 | #define WFLAG_KEEPALIVE 1 |
29 | |
32 | |
30 | #define UNREF(w) \ |
33 | #define UNREF(w) \ |
31 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
34 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
32 | && !ev_is_active (w)) \ |
35 | && !ev_is_active (w)) \ |
33 | ev_unref (w->loop); |
36 | ev_unref (e_loop (w)); |
34 | |
37 | |
35 | #define REF(w) \ |
38 | #define REF(w) \ |
36 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
39 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
37 | && ev_is_active (w)) \ |
40 | && ev_is_active (w)) \ |
38 | ev_ref (w->loop); |
41 | ev_ref (e_loop (w)); |
39 | |
42 | |
40 | #define START(type,w) \ |
43 | #define START(type,w) \ |
41 | do { \ |
44 | do { \ |
42 | UNREF (w); \ |
45 | UNREF (w); \ |
43 | ev_ ## type ## _start (w->loop, w); \ |
46 | ev_ ## type ## _start (e_loop (w), w); \ |
44 | } while (0) |
47 | } while (0) |
45 | |
48 | |
46 | #define STOP(type,w) \ |
49 | #define STOP(type,w) \ |
47 | do { \ |
50 | do { \ |
48 | REF (w); \ |
51 | REF (w); \ |
49 | ev_ ## type ## _stop (w->loop, w); \ |
52 | ev_ ## type ## _stop (e_loop (w), w); \ |
50 | } while (0) |
53 | } while (0) |
51 | |
54 | |
52 | #define RESET(type,w,seta) \ |
55 | #define RESET(type,w,seta) \ |
53 | do { \ |
56 | do { \ |
54 | int active = ev_is_active (w); \ |
57 | int active = ev_is_active (w); \ |
… | |
… | |
57 | if (active) START (type, w); \ |
60 | if (active) START (type, w); \ |
58 | } while (0) |
61 | } while (0) |
59 | |
62 | |
60 | typedef int Signal; |
63 | typedef int Signal; |
61 | |
64 | |
|
|
65 | static SV *default_loop_sv; |
|
|
66 | |
62 | static struct EVAPI evapi; |
67 | static struct EVAPI evapi; |
63 | |
68 | |
64 | static HV |
69 | static HV |
|
|
70 | *stash_loop, |
65 | *stash_watcher, |
71 | *stash_watcher, |
66 | *stash_io, |
72 | *stash_io, |
67 | *stash_timer, |
73 | *stash_timer, |
68 | *stash_periodic, |
74 | *stash_periodic, |
69 | *stash_signal, |
75 | *stash_signal, |
… | |
… | |
121 | |
127 | |
122 | return -1; |
128 | return -1; |
123 | } |
129 | } |
124 | |
130 | |
125 | static void * |
131 | static void * |
126 | e_new (int size, SV *cb_sv) |
132 | e_new (int size, SV *cb_sv, SV *loop) |
127 | { |
133 | { |
128 | ev_watcher *w; |
134 | ev_watcher *w; |
129 | SV *self = NEWSV (0, size); |
135 | SV *self = NEWSV (0, size); |
130 | SvPOK_only (self); |
136 | SvPOK_only (self); |
131 | SvCUR_set (self, size); |
137 | SvCUR_set (self, size); |
132 | |
138 | |
133 | w = (ev_watcher *)SvPVX (self); |
139 | w = (ev_watcher *)SvPVX (self); |
134 | |
140 | |
135 | ev_init (w, e_cb); |
141 | ev_init (w, e_cb); |
136 | |
142 | |
137 | w->loop = EV_DEFAULT; |
143 | w->loop = SvREFCNT_inc (SvRV (loop)); |
138 | w->flags = WFLAG_KEEPALIVE; |
144 | w->flags = WFLAG_KEEPALIVE; |
139 | w->data = 0; |
145 | w->data = 0; |
140 | w->fh = 0; |
146 | w->fh = 0; |
141 | w->cb_sv = newSVsv (cb_sv); |
147 | w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); |
142 | w->self = self; |
148 | w->self = self; |
143 | |
149 | |
144 | return (void *)w; |
150 | return (void *)w; |
145 | } |
151 | } |
146 | |
152 | |
147 | static void |
153 | static void |
148 | e_destroy (void *w_) |
154 | e_destroy (void *w_) |
149 | { |
155 | { |
150 | ev_watcher *w = (ev_watcher *)w_; |
156 | ev_watcher *w = (ev_watcher *)w_; |
151 | |
157 | |
|
|
158 | SvREFCNT_dec (w->loop ); w->loop = 0; |
152 | SvREFCNT_dec (w->fh ); w->fh = 0; |
159 | SvREFCNT_dec (w->fh ); w->fh = 0; |
153 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
160 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
154 | SvREFCNT_dec (w->data ); w->data = 0; |
161 | SvREFCNT_dec (w->data ); w->data = 0; |
155 | } |
162 | } |
156 | |
163 | |
… | |
… | |
355 | }; |
362 | }; |
356 | |
363 | |
357 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
364 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
358 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
365 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
359 | |
366 | |
|
|
367 | stash_loop = gv_stashpv ("EV::Loop" , 1); |
360 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
368 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
361 | stash_io = gv_stashpv ("EV::IO" , 1); |
369 | stash_io = gv_stashpv ("EV::IO" , 1); |
362 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
370 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
363 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
371 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
364 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
372 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
… | |
… | |
381 | evapi.sv_signum = sv_signum; |
389 | evapi.sv_signum = sv_signum; |
382 | evapi.supported_backends = ev_supported_backends (); |
390 | evapi.supported_backends = ev_supported_backends (); |
383 | evapi.recommended_backends = ev_recommended_backends (); |
391 | evapi.recommended_backends = ev_recommended_backends (); |
384 | evapi.embeddable_backends = ev_embeddable_backends (); |
392 | evapi.embeddable_backends = ev_embeddable_backends (); |
385 | evapi.time = ev_time; |
393 | evapi.time = ev_time; |
|
|
394 | evapi.sleep = ev_sleep; |
386 | evapi.loop_new = ev_loop_new; |
395 | evapi.loop_new = ev_loop_new; |
387 | evapi.loop_destroy = ev_loop_destroy; |
396 | evapi.loop_destroy = ev_loop_destroy; |
388 | evapi.loop_fork = ev_loop_fork; |
397 | evapi.loop_fork = ev_loop_fork; |
389 | evapi.loop_count = ev_loop_count; |
398 | evapi.loop_count = ev_loop_count; |
390 | evapi.now = ev_now; |
399 | evapi.now = ev_now; |
… | |
… | |
428 | #ifndef _WIN32 |
437 | #ifndef _WIN32 |
429 | pthread_atfork (0, 0, ev_default_fork); |
438 | pthread_atfork (0, 0, ev_default_fork); |
430 | #endif |
439 | #endif |
431 | } |
440 | } |
432 | |
441 | |
433 | SV *ev_default_loop (unsigned int flags = ev_supported_backends ()) |
442 | SV *ev_default_loop (unsigned int flags = 0) |
434 | CODE: |
443 | CODE: |
435 | { |
444 | { |
|
|
445 | if (!default_loop_sv) |
|
|
446 | { |
436 | evapi.default_loop = ev_default_loop (flags); |
447 | evapi.default_loop = ev_default_loop (flags); |
|
|
448 | |
437 | if (!evapi.default_loop) |
449 | if (!evapi.default_loop) |
438 | XSRETURN_UNDEF; |
450 | XSRETURN_UNDEF; |
439 | |
451 | |
440 | RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))), |
452 | default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop); |
441 | gv_stashpv ("EV::Loop::Default", 1)); |
453 | } |
|
|
454 | |
|
|
455 | RETVAL = newSVsv (default_loop_sv); |
442 | } |
456 | } |
443 | OUTPUT: |
457 | OUTPUT: |
444 | RETVAL |
458 | RETVAL |
|
|
459 | |
|
|
460 | void ev_default_destroy () |
|
|
461 | CODE: |
|
|
462 | ev_default_destroy (); |
|
|
463 | SvREFCNT_dec (default_loop_sv); |
|
|
464 | default_loop_sv = 0; |
|
|
465 | |
|
|
466 | unsigned int ev_supported_backends () |
|
|
467 | |
|
|
468 | unsigned int ev_recommended_backends () |
|
|
469 | |
|
|
470 | unsigned int ev_embeddable_backends () |
445 | |
471 | |
446 | NV ev_time () |
472 | NV ev_time () |
447 | |
473 | |
448 | NV ev_now () |
474 | NV ev_now () |
449 | C_ARGS: evapi.default_loop |
475 | C_ARGS: evapi.default_loop |
… | |
… | |
452 | C_ARGS: evapi.default_loop |
478 | C_ARGS: evapi.default_loop |
453 | |
479 | |
454 | unsigned int ev_loop_count () |
480 | unsigned int ev_loop_count () |
455 | C_ARGS: evapi.default_loop |
481 | C_ARGS: evapi.default_loop |
456 | |
482 | |
|
|
483 | void ev_set_io_collect_interval (NV interval) |
|
|
484 | C_ARGS: evapi.default_loop, interval |
|
|
485 | |
|
|
486 | void ev_set_timeout_collect_interval (NV interval) |
|
|
487 | C_ARGS: evapi.default_loop, interval |
|
|
488 | |
457 | void ev_loop (int flags = 0) |
489 | void ev_loop (int flags = 0) |
458 | C_ARGS: evapi.default_loop, flags |
490 | C_ARGS: evapi.default_loop, flags |
459 | |
491 | |
460 | void ev_unloop (int how = 1) |
492 | void ev_unloop (int how = 1) |
461 | C_ARGS: evapi.default_loop, how |
493 | C_ARGS: evapi.default_loop, how |
… | |
… | |
478 | CODE: |
510 | CODE: |
479 | { |
511 | { |
480 | int fd = sv_fileno (fh); |
512 | int fd = sv_fileno (fh); |
481 | CHECK_FD (fh, fd); |
513 | CHECK_FD (fh, fd); |
482 | |
514 | |
483 | RETVAL = e_new (sizeof (ev_io), cb); |
515 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
484 | RETVAL->fh = newSVsv (fh); |
516 | RETVAL->fh = newSVsv (fh); |
485 | ev_io_set (RETVAL, fd, events); |
517 | ev_io_set (RETVAL, fd, events); |
486 | if (!ix) START (io, RETVAL); |
518 | if (!ix) START (io, RETVAL); |
487 | } |
519 | } |
488 | OUTPUT: |
520 | OUTPUT: |
… | |
… | |
492 | ALIAS: |
524 | ALIAS: |
493 | timer_ns = 1 |
525 | timer_ns = 1 |
494 | INIT: |
526 | INIT: |
495 | CHECK_REPEAT (repeat); |
527 | CHECK_REPEAT (repeat); |
496 | CODE: |
528 | CODE: |
497 | RETVAL = e_new (sizeof (ev_timer), cb); |
529 | RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv); |
498 | ev_timer_set (RETVAL, after, repeat); |
530 | ev_timer_set (RETVAL, after, repeat); |
499 | if (!ix) START (timer, RETVAL); |
531 | if (!ix) START (timer, RETVAL); |
500 | OUTPUT: |
532 | OUTPUT: |
501 | RETVAL |
533 | RETVAL |
502 | |
534 | |
… | |
… | |
506 | INIT: |
538 | INIT: |
507 | CHECK_REPEAT (interval); |
539 | CHECK_REPEAT (interval); |
508 | CODE: |
540 | CODE: |
509 | { |
541 | { |
510 | ev_periodic *w; |
542 | ev_periodic *w; |
511 | w = e_new (sizeof (ev_periodic), cb); |
543 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
512 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
544 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
513 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
545 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
514 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
546 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
515 | if (!ix) START (periodic, w); |
547 | if (!ix) START (periodic, w); |
516 | } |
548 | } |
… | |
… | |
523 | CODE: |
555 | CODE: |
524 | { |
556 | { |
525 | Signal signum = sv_signum (signal); |
557 | Signal signum = sv_signum (signal); |
526 | CHECK_SIG (signal, signum); |
558 | CHECK_SIG (signal, signum); |
527 | |
559 | |
528 | RETVAL = e_new (sizeof (ev_signal), cb); |
560 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
529 | ev_signal_set (RETVAL, signum); |
561 | ev_signal_set (RETVAL, signum); |
530 | if (!ix) START (signal, RETVAL); |
562 | if (!ix) START (signal, RETVAL); |
531 | } |
563 | } |
532 | OUTPUT: |
564 | OUTPUT: |
533 | RETVAL |
565 | RETVAL |
534 | |
566 | |
535 | ev_idle *idle (SV *cb) |
567 | ev_idle *idle (SV *cb) |
536 | ALIAS: |
568 | ALIAS: |
537 | idle_ns = 1 |
569 | idle_ns = 1 |
538 | CODE: |
570 | CODE: |
539 | RETVAL = e_new (sizeof (ev_idle), cb); |
571 | RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv); |
540 | ev_idle_set (RETVAL); |
572 | ev_idle_set (RETVAL); |
541 | if (!ix) START (idle, RETVAL); |
573 | if (!ix) START (idle, RETVAL); |
542 | OUTPUT: |
574 | OUTPUT: |
543 | RETVAL |
575 | RETVAL |
544 | |
576 | |
545 | ev_prepare *prepare (SV *cb) |
577 | ev_prepare *prepare (SV *cb) |
546 | ALIAS: |
578 | ALIAS: |
547 | prepare_ns = 1 |
579 | prepare_ns = 1 |
548 | CODE: |
580 | CODE: |
549 | RETVAL = e_new (sizeof (ev_prepare), cb); |
581 | RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv); |
550 | ev_prepare_set (RETVAL); |
582 | ev_prepare_set (RETVAL); |
551 | if (!ix) START (prepare, RETVAL); |
583 | if (!ix) START (prepare, RETVAL); |
552 | OUTPUT: |
584 | OUTPUT: |
553 | RETVAL |
585 | RETVAL |
554 | |
586 | |
555 | ev_check *check (SV *cb) |
587 | ev_check *check (SV *cb) |
556 | ALIAS: |
588 | ALIAS: |
557 | check_ns = 1 |
589 | check_ns = 1 |
558 | CODE: |
590 | CODE: |
559 | RETVAL = e_new (sizeof (ev_check), cb); |
591 | RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv); |
560 | ev_check_set (RETVAL); |
592 | ev_check_set (RETVAL); |
561 | if (!ix) START (check, RETVAL); |
593 | if (!ix) START (check, RETVAL); |
562 | OUTPUT: |
594 | OUTPUT: |
563 | RETVAL |
595 | RETVAL |
564 | |
596 | |
565 | ev_fork *fork (SV *cb) |
597 | ev_fork *fork (SV *cb) |
566 | ALIAS: |
598 | ALIAS: |
567 | fork_ns = 1 |
599 | fork_ns = 1 |
568 | CODE: |
600 | CODE: |
569 | RETVAL = e_new (sizeof (ev_fork), cb); |
601 | RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv); |
570 | ev_fork_set (RETVAL); |
602 | ev_fork_set (RETVAL); |
571 | if (!ix) START (fork, RETVAL); |
603 | if (!ix) START (fork, RETVAL); |
572 | OUTPUT: |
604 | OUTPUT: |
573 | RETVAL |
605 | RETVAL |
574 | |
606 | |
575 | ev_child *child (int pid, SV *cb) |
607 | ev_child *child (int pid, SV *cb) |
576 | ALIAS: |
608 | ALIAS: |
577 | child_ns = 1 |
609 | child_ns = 1 |
578 | CODE: |
610 | CODE: |
579 | RETVAL = e_new (sizeof (ev_child), cb); |
611 | RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); |
580 | ev_child_set (RETVAL, pid); |
612 | ev_child_set (RETVAL, pid); |
581 | if (!ix) START (child, RETVAL); |
613 | if (!ix) START (child, RETVAL); |
582 | OUTPUT: |
614 | OUTPUT: |
583 | RETVAL |
615 | RETVAL |
584 | |
616 | |
585 | ev_stat *stat (SV *path, NV interval, SV *cb) |
617 | ev_stat *stat (SV *path, NV interval, SV *cb) |
586 | ALIAS: |
618 | ALIAS: |
587 | stat_ns = 1 |
619 | stat_ns = 1 |
588 | CODE: |
620 | CODE: |
589 | RETVAL = e_new (sizeof (ev_stat), cb); |
621 | RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv); |
590 | RETVAL->fh = newSVsv (path); |
622 | RETVAL->fh = newSVsv (path); |
591 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
623 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
592 | if (!ix) START (stat, RETVAL); |
624 | if (!ix) START (stat, RETVAL); |
|
|
625 | OUTPUT: |
|
|
626 | RETVAL |
|
|
627 | |
|
|
628 | ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef) |
|
|
629 | ALIAS: |
|
|
630 | embed_ns = 1 |
|
|
631 | CODE: |
|
|
632 | { |
|
|
633 | if (!(ev_backend (loop) & ev_embeddable_backends ())) |
|
|
634 | croak ("passed loop is not embeddable via EV::embed,"); |
|
|
635 | |
|
|
636 | RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); |
|
|
637 | RETVAL->fh = newSVsv (ST (0)); |
|
|
638 | ev_embed_set (RETVAL, loop); |
|
|
639 | |
|
|
640 | if (!SvOK (cb)) ev_set_cb (RETVAL, 0); |
|
|
641 | |
|
|
642 | if (!ix) START (embed, RETVAL); |
|
|
643 | } |
593 | OUTPUT: |
644 | OUTPUT: |
594 | RETVAL |
645 | RETVAL |
595 | |
646 | |
596 | void once (SV *fh, int events, SV *timeout, SV *cb) |
647 | void once (SV *fh, int events, SV *timeout, SV *cb) |
597 | CODE: |
648 | CODE: |
… | |
… | |
610 | int ev_is_active (ev_watcher *w) |
661 | int ev_is_active (ev_watcher *w) |
611 | |
662 | |
612 | int ev_is_pending (ev_watcher *w) |
663 | int ev_is_pending (ev_watcher *w) |
613 | |
664 | |
614 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
665 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
615 | C_ARGS: w->loop, w, revents |
666 | C_ARGS: e_loop (w), w, revents |
616 | |
667 | |
617 | int ev_clear_pending (ev_watcher *w) |
668 | int ev_clear_pending (ev_watcher *w) |
618 | C_ARGS: w->loop, w |
669 | C_ARGS: e_loop (w), w |
619 | |
670 | |
620 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
671 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
621 | C_ARGS: w->loop, w, revents |
672 | C_ARGS: e_loop (w), w, revents |
622 | |
673 | |
623 | int keepalive (ev_watcher *w, int new_value = 0) |
674 | int keepalive (ev_watcher *w, int new_value = 0) |
624 | CODE: |
675 | CODE: |
625 | { |
676 | { |
626 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
677 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
… | |
… | |
656 | { |
707 | { |
657 | SvREFCNT_dec (w->data); |
708 | SvREFCNT_dec (w->data); |
658 | w->data = newSVsv (new_data); |
709 | w->data = newSVsv (new_data); |
659 | } |
710 | } |
660 | } |
711 | } |
|
|
712 | OUTPUT: |
|
|
713 | RETVAL |
|
|
714 | |
|
|
715 | SV *loop (ev_watcher *w) |
|
|
716 | CODE: |
|
|
717 | RETVAL = newRV_inc (w->loop); |
661 | OUTPUT: |
718 | OUTPUT: |
662 | RETVAL |
719 | RETVAL |
663 | |
720 | |
664 | int priority (ev_watcher *w, int new_priority = 0) |
721 | int priority (ev_watcher *w, int new_priority = 0) |
665 | CODE: |
722 | CODE: |
… | |
… | |
803 | void ev_timer_again (ev_timer *w) |
860 | void ev_timer_again (ev_timer *w) |
804 | INIT: |
861 | INIT: |
805 | CHECK_REPEAT (w->repeat); |
862 | CHECK_REPEAT (w->repeat); |
806 | CODE: |
863 | CODE: |
807 | REF (w); |
864 | REF (w); |
808 | ev_timer_again (w->loop, w); |
865 | ev_timer_again (e_loop (w), w); |
809 | UNREF (w); |
866 | UNREF (w); |
810 | |
867 | |
811 | void DESTROY (ev_timer *w) |
868 | void DESTROY (ev_timer *w) |
812 | CODE: |
869 | CODE: |
813 | STOP (timer, w); |
870 | STOP (timer, w); |
… | |
… | |
838 | STOP (periodic, w); |
895 | STOP (periodic, w); |
839 | |
896 | |
840 | void ev_periodic_again (ev_periodic *w) |
897 | void ev_periodic_again (ev_periodic *w) |
841 | CODE: |
898 | CODE: |
842 | REF (w); |
899 | REF (w); |
843 | ev_periodic_again (w->loop, w); |
900 | ev_periodic_again (e_loop (w), w); |
844 | UNREF (w); |
901 | UNREF (w); |
845 | |
902 | |
846 | void DESTROY (ev_periodic *w) |
903 | void DESTROY (ev_periodic *w) |
847 | CODE: |
904 | CODE: |
848 | STOP (periodic, w); |
905 | STOP (periodic, w); |
… | |
… | |
878 | void DESTROY (ev_idle *w) |
935 | void DESTROY (ev_idle *w) |
879 | CODE: |
936 | CODE: |
880 | STOP (idle, w); |
937 | STOP (idle, w); |
881 | e_destroy (w); |
938 | e_destroy (w); |
882 | |
939 | |
883 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ |
940 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_ |
884 | |
941 | |
885 | void ev_prepare_start (ev_prepare *w) |
942 | void ev_prepare_start (ev_prepare *w) |
886 | CODE: |
943 | CODE: |
887 | START (prepare, w); |
944 | START (prepare, w); |
888 | |
945 | |
… | |
… | |
1019 | PPCODE: |
1076 | PPCODE: |
1020 | { |
1077 | { |
1021 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1078 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1022 | |
1079 | |
1023 | if (ix == 1) |
1080 | if (ix == 1) |
1024 | ev_stat_stat (w->loop, w); |
1081 | ev_stat_stat (e_loop (w), w); |
1025 | else if (!s->st_nlink) |
1082 | else if (!s->st_nlink) |
1026 | errno = ENOENT; |
1083 | errno = ENOENT; |
1027 | |
1084 | |
1028 | PL_statcache.st_dev = s->st_nlink; |
1085 | PL_statcache.st_dev = s->st_nlink; |
1029 | PL_statcache.st_ino = s->st_ino; |
1086 | PL_statcache.st_ino = s->st_ino; |
… | |
… | |
1056 | PUSHs (sv_2mortal (newSVuv (4096))); |
1113 | PUSHs (sv_2mortal (newSVuv (4096))); |
1057 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
1114 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
1058 | } |
1115 | } |
1059 | } |
1116 | } |
1060 | |
1117 | |
|
|
1118 | MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_ |
|
|
1119 | |
|
|
1120 | void ev_embed_start (ev_embed *w) |
|
|
1121 | CODE: |
|
|
1122 | START (embed, w); |
|
|
1123 | |
|
|
1124 | void ev_embed_stop (ev_embed *w) |
|
|
1125 | CODE: |
|
|
1126 | STOP (embed, w); |
|
|
1127 | |
|
|
1128 | void DESTROY (ev_embed *w) |
|
|
1129 | CODE: |
|
|
1130 | STOP (embed, w); |
|
|
1131 | e_destroy (w); |
|
|
1132 | |
|
|
1133 | void set (ev_embed *w, struct ev_loop *loop) |
|
|
1134 | CODE: |
|
|
1135 | { |
|
|
1136 | sv_setsv (w->fh, ST (1)); |
|
|
1137 | RESET (embed, w, (w, loop)); |
|
|
1138 | } |
|
|
1139 | |
|
|
1140 | SV *other (ev_embed *w) |
|
|
1141 | CODE: |
|
|
1142 | RETVAL = newSVsv (w->fh); |
|
|
1143 | OUTPUT: |
|
|
1144 | RETVAL |
|
|
1145 | |
|
|
1146 | MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ |
|
|
1147 | |
|
|
1148 | SV *new (SV *klass, unsigned int flags = 0) |
|
|
1149 | CODE: |
|
|
1150 | { |
|
|
1151 | struct ev_loop *loop = ev_loop_new (flags); |
|
|
1152 | |
|
|
1153 | if (!loop) |
|
|
1154 | XSRETURN_UNDEF; |
|
|
1155 | |
|
|
1156 | RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop); |
|
|
1157 | } |
|
|
1158 | OUTPUT: |
|
|
1159 | RETVAL |
|
|
1160 | |
|
|
1161 | void DESTROY (struct ev_loop *loop) |
|
|
1162 | CODE: |
|
|
1163 | if (loop != evapi.default_loop) /* global destruction sucks */ |
|
|
1164 | ev_loop_destroy (loop); |
|
|
1165 | |
|
|
1166 | void ev_loop_fork (struct ev_loop *loop) |
|
|
1167 | |
|
|
1168 | NV ev_now (struct ev_loop *loop) |
|
|
1169 | |
|
|
1170 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1171 | |
|
|
1172 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1173 | |
|
|
1174 | unsigned int ev_backend (struct ev_loop *loop) |
|
|
1175 | |
|
|
1176 | unsigned int ev_loop_count (struct ev_loop *loop) |
|
|
1177 | |
|
|
1178 | void ev_loop (struct ev_loop *loop, int flags = 0) |
|
|
1179 | |
|
|
1180 | void ev_unloop (struct ev_loop *loop, int how = 1) |
|
|
1181 | |
|
|
1182 | void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) |
|
|
1183 | |
1061 | #if 0 |
1184 | #if 0 |
1062 | |
1185 | |
1063 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1186 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1064 | |
1187 | CODE: |
1065 | BOOT: |
|
|
1066 | { |
1188 | { |
1067 | HV *stash = gv_stashpv ("EV::HTTP", 1); |
1189 | Signal signum = sv_signum (signal); |
|
|
1190 | CHECK_SIG (signal, signum); |
1068 | |
1191 | |
1069 | static const struct { |
1192 | ev_feed_signal_event (loop, signum); |
1070 | const char *name; |
|
|
1071 | IV iv; |
|
|
1072 | } *civ, const_iv[] = { |
|
|
1073 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
1074 | const_iv (HTTP_, OK) |
|
|
1075 | const_iv (HTTP_, NOCONTENT) |
|
|
1076 | const_iv (HTTP_, MOVEPERM) |
|
|
1077 | const_iv (HTTP_, MOVETEMP) |
|
|
1078 | const_iv (HTTP_, NOTMODIFIED) |
|
|
1079 | const_iv (HTTP_, BADREQUEST) |
|
|
1080 | const_iv (HTTP_, NOTFOUND) |
|
|
1081 | const_iv (HTTP_, SERVUNAVAIL) |
|
|
1082 | const_iv (EVHTTP_, REQ_OWN_CONNECTION) |
|
|
1083 | const_iv (EVHTTP_, PROXY_REQUEST) |
|
|
1084 | const_iv (EVHTTP_, REQ_GET) |
|
|
1085 | const_iv (EVHTTP_, REQ_POST) |
|
|
1086 | const_iv (EVHTTP_, REQ_HEAD) |
|
|
1087 | const_iv (EVHTTP_, REQUEST) |
|
|
1088 | const_iv (EVHTTP_, RESPONSE) |
|
|
1089 | }; |
|
|
1090 | |
|
|
1091 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
1092 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
1093 | } |
1193 | } |
1094 | |
|
|
1095 | MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_ |
|
|
1096 | |
|
|
1097 | #HttpRequest new (SV *klass, SV *cb) |
|
|
1098 | |
|
|
1099 | #void DESTROY (struct evhttp_request *req); |
|
|
1100 | |
1194 | |
1101 | #endif |
1195 | #endif |
1102 | |
1196 | |
|
|
1197 | ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) |
|
|
1198 | ALIAS: |
|
|
1199 | io_ns = 1 |
|
|
1200 | CODE: |
|
|
1201 | { |
|
|
1202 | int fd = sv_fileno (fh); |
|
|
1203 | CHECK_FD (fh, fd); |
1103 | |
1204 | |
|
|
1205 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
|
|
1206 | RETVAL->fh = newSVsv (fh); |
|
|
1207 | ev_io_set (RETVAL, fd, events); |
|
|
1208 | if (!ix) START (io, RETVAL); |
|
|
1209 | } |
|
|
1210 | OUTPUT: |
|
|
1211 | RETVAL |
1104 | |
1212 | |
|
|
1213 | ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb) |
|
|
1214 | ALIAS: |
|
|
1215 | timer_ns = 1 |
|
|
1216 | INIT: |
|
|
1217 | CHECK_REPEAT (repeat); |
|
|
1218 | CODE: |
|
|
1219 | RETVAL = e_new (sizeof (ev_timer), cb, ST (0)); |
|
|
1220 | ev_timer_set (RETVAL, after, repeat); |
|
|
1221 | if (!ix) START (timer, RETVAL); |
|
|
1222 | OUTPUT: |
|
|
1223 | RETVAL |
1105 | |
1224 | |
|
|
1225 | SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb) |
|
|
1226 | ALIAS: |
|
|
1227 | periodic_ns = 1 |
|
|
1228 | INIT: |
|
|
1229 | CHECK_REPEAT (interval); |
|
|
1230 | CODE: |
|
|
1231 | { |
|
|
1232 | ev_periodic *w; |
|
|
1233 | w = e_new (sizeof (ev_periodic), cb, ST (0)); |
|
|
1234 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
1235 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
|
|
1236 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
|
|
1237 | if (!ix) START (periodic, w); |
|
|
1238 | } |
|
|
1239 | OUTPUT: |
|
|
1240 | RETVAL |
1106 | |
1241 | |
|
|
1242 | #if 0 |
1107 | |
1243 | |
|
|
1244 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
|
|
1245 | ALIAS: |
|
|
1246 | signal_ns = 1 |
|
|
1247 | CODE: |
|
|
1248 | { |
|
|
1249 | Signal signum = sv_signum (signal); |
|
|
1250 | CHECK_SIG (signal, signum); |
1108 | |
1251 | |
|
|
1252 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
|
|
1253 | ev_signal_set (RETVAL, signum); |
|
|
1254 | if (!ix) START (signal, RETVAL); |
|
|
1255 | } |
|
|
1256 | OUTPUT: |
|
|
1257 | RETVAL |
1109 | |
1258 | |
|
|
1259 | #endif |
|
|
1260 | |
|
|
1261 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
|
|
1262 | ALIAS: |
|
|
1263 | idle_ns = 1 |
|
|
1264 | CODE: |
|
|
1265 | RETVAL = e_new (sizeof (ev_idle), cb, ST (0)); |
|
|
1266 | ev_idle_set (RETVAL); |
|
|
1267 | if (!ix) START (idle, RETVAL); |
|
|
1268 | OUTPUT: |
|
|
1269 | RETVAL |
|
|
1270 | |
|
|
1271 | ev_prepare *prepare (struct ev_loop *loop, SV *cb) |
|
|
1272 | ALIAS: |
|
|
1273 | prepare_ns = 1 |
|
|
1274 | CODE: |
|
|
1275 | RETVAL = e_new (sizeof (ev_prepare), cb, ST (0)); |
|
|
1276 | ev_prepare_set (RETVAL); |
|
|
1277 | if (!ix) START (prepare, RETVAL); |
|
|
1278 | OUTPUT: |
|
|
1279 | RETVAL |
|
|
1280 | |
|
|
1281 | ev_check *check (struct ev_loop *loop, SV *cb) |
|
|
1282 | ALIAS: |
|
|
1283 | check_ns = 1 |
|
|
1284 | CODE: |
|
|
1285 | RETVAL = e_new (sizeof (ev_check), cb, ST (0)); |
|
|
1286 | ev_check_set (RETVAL); |
|
|
1287 | if (!ix) START (check, RETVAL); |
|
|
1288 | OUTPUT: |
|
|
1289 | RETVAL |
|
|
1290 | |
|
|
1291 | ev_fork *fork (struct ev_loop *loop, SV *cb) |
|
|
1292 | ALIAS: |
|
|
1293 | fork_ns = 1 |
|
|
1294 | CODE: |
|
|
1295 | RETVAL = e_new (sizeof (ev_fork), cb, ST (0)); |
|
|
1296 | ev_fork_set (RETVAL); |
|
|
1297 | if (!ix) START (fork, RETVAL); |
|
|
1298 | OUTPUT: |
|
|
1299 | RETVAL |
|
|
1300 | |
|
|
1301 | ev_child *child (struct ev_loop *loop, int pid, SV *cb) |
|
|
1302 | ALIAS: |
|
|
1303 | child_ns = 1 |
|
|
1304 | CODE: |
|
|
1305 | RETVAL = e_new (sizeof (ev_child), cb, ST (0)); |
|
|
1306 | ev_child_set (RETVAL, pid); |
|
|
1307 | if (!ix) START (child, RETVAL); |
|
|
1308 | OUTPUT: |
|
|
1309 | RETVAL |
|
|
1310 | |
|
|
1311 | ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) |
|
|
1312 | ALIAS: |
|
|
1313 | stat_ns = 1 |
|
|
1314 | CODE: |
|
|
1315 | RETVAL = e_new (sizeof (ev_stat), cb, ST (0)); |
|
|
1316 | RETVAL->fh = newSVsv (path); |
|
|
1317 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
|
|
1318 | if (!ix) START (stat, RETVAL); |
|
|
1319 | OUTPUT: |
|
|
1320 | RETVAL |
|
|
1321 | |
|
|
1322 | ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef) |
|
|
1323 | ALIAS: |
|
|
1324 | embed_ns = 1 |
|
|
1325 | CODE: |
|
|
1326 | { |
|
|
1327 | if (!(ev_backend (other) & ev_embeddable_backends ())) |
|
|
1328 | croak ("passed loop is not embeddable via EV::embed,"); |
|
|
1329 | |
|
|
1330 | RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); |
|
|
1331 | RETVAL->fh = newSVsv (ST (1)); |
|
|
1332 | ev_embed_set (RETVAL, other); |
|
|
1333 | |
|
|
1334 | if (!SvOK (cb)) ev_set_cb (RETVAL, 0); |
|
|
1335 | |
|
|
1336 | if (!ix) START (embed, RETVAL); |
|
|
1337 | } |
|
|
1338 | OUTPUT: |
|
|
1339 | RETVAL |
|
|
1340 | |
|
|
1341 | void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) |
|
|
1342 | CODE: |
|
|
1343 | ev_once ( |
|
|
1344 | loop, |
|
|
1345 | sv_fileno (fh), events, |
|
|
1346 | SvOK (timeout) ? SvNV (timeout) : -1., |
|
|
1347 | e_once_cb, |
|
|
1348 | newSVsv (cb) |
|
|
1349 | ); |
|
|
1350 | |