… | |
… | |
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 |
8 | #define EV_H <ev.h> |
9 | #define EV_H <ev.h> |
9 | #include "EV/EVAPI.h" |
10 | #include "EV/EVAPI.h" |
10 | |
11 | |
11 | /* fix perl api breakage */ |
12 | /* fix perl api breakage */ |
12 | #undef signal |
13 | #undef signal |
… | |
… | |
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)->e_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)->e_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->e_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; |
… | |
… | |
417 | evapi.embed_start = ev_embed_start; |
426 | evapi.embed_start = ev_embed_start; |
418 | evapi.embed_stop = ev_embed_stop; |
427 | evapi.embed_stop = ev_embed_stop; |
419 | evapi.embed_sweep = ev_embed_sweep; |
428 | evapi.embed_sweep = ev_embed_sweep; |
420 | evapi.fork_start = ev_fork_start; |
429 | evapi.fork_start = ev_fork_start; |
421 | evapi.fork_stop = ev_fork_stop; |
430 | evapi.fork_stop = ev_fork_stop; |
|
|
431 | evapi.async_start = ev_async_start; |
|
|
432 | evapi.async_stop = ev_async_stop; |
|
|
433 | evapi.async_send = ev_async_send; |
422 | evapi.clear_pending = ev_clear_pending; |
434 | evapi.clear_pending = ev_clear_pending; |
423 | evapi.invoke = ev_invoke; |
435 | evapi.invoke = ev_invoke; |
424 | |
436 | |
425 | sv_setiv (sv, (IV)&evapi); |
437 | sv_setiv (sv, (IV)&evapi); |
426 | SvREADONLY_on (sv); |
438 | SvREADONLY_on (sv); |
… | |
… | |
428 | #ifndef _WIN32 |
440 | #ifndef _WIN32 |
429 | pthread_atfork (0, 0, ev_default_fork); |
441 | pthread_atfork (0, 0, ev_default_fork); |
430 | #endif |
442 | #endif |
431 | } |
443 | } |
432 | |
444 | |
433 | SV *ev_default_loop (unsigned int flags = ev_supported_backends ()) |
445 | SV *ev_default_loop (unsigned int flags = 0) |
434 | CODE: |
446 | CODE: |
435 | { |
447 | { |
|
|
448 | if (!default_loop_sv) |
|
|
449 | { |
436 | evapi.default_loop = ev_default_loop (flags); |
450 | evapi.default_loop = ev_default_loop (flags); |
|
|
451 | |
437 | if (!evapi.default_loop) |
452 | if (!evapi.default_loop) |
438 | XSRETURN_UNDEF; |
453 | XSRETURN_UNDEF; |
439 | |
454 | |
440 | RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))), |
455 | default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop); |
441 | gv_stashpv ("EV::Loop::Default", 1)); |
456 | } |
|
|
457 | |
|
|
458 | RETVAL = newSVsv (default_loop_sv); |
442 | } |
459 | } |
443 | OUTPUT: |
460 | OUTPUT: |
444 | RETVAL |
461 | RETVAL |
|
|
462 | |
|
|
463 | void ev_default_destroy () |
|
|
464 | CODE: |
|
|
465 | ev_default_destroy (); |
|
|
466 | SvREFCNT_dec (default_loop_sv); |
|
|
467 | default_loop_sv = 0; |
|
|
468 | |
|
|
469 | unsigned int ev_supported_backends () |
|
|
470 | |
|
|
471 | unsigned int ev_recommended_backends () |
|
|
472 | |
|
|
473 | unsigned int ev_embeddable_backends () |
445 | |
474 | |
446 | NV ev_time () |
475 | NV ev_time () |
447 | |
476 | |
448 | NV ev_now () |
477 | NV ev_now () |
449 | C_ARGS: evapi.default_loop |
478 | C_ARGS: evapi.default_loop |
… | |
… | |
452 | C_ARGS: evapi.default_loop |
481 | C_ARGS: evapi.default_loop |
453 | |
482 | |
454 | unsigned int ev_loop_count () |
483 | unsigned int ev_loop_count () |
455 | C_ARGS: evapi.default_loop |
484 | C_ARGS: evapi.default_loop |
456 | |
485 | |
|
|
486 | void ev_set_io_collect_interval (NV interval) |
|
|
487 | C_ARGS: evapi.default_loop, interval |
|
|
488 | |
|
|
489 | void ev_set_timeout_collect_interval (NV interval) |
|
|
490 | C_ARGS: evapi.default_loop, interval |
|
|
491 | |
457 | void ev_loop (int flags = 0) |
492 | void ev_loop (int flags = 0) |
458 | C_ARGS: evapi.default_loop, flags |
493 | C_ARGS: evapi.default_loop, flags |
459 | |
494 | |
460 | void ev_unloop (int how = 1) |
495 | void ev_unloop (int how = EVUNLOOP_ONE) |
461 | C_ARGS: evapi.default_loop, how |
496 | C_ARGS: evapi.default_loop, how |
462 | |
497 | |
463 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
498 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
464 | C_ARGS: evapi.default_loop, fd, revents |
499 | C_ARGS: evapi.default_loop, fd, revents |
465 | |
500 | |
… | |
… | |
478 | CODE: |
513 | CODE: |
479 | { |
514 | { |
480 | int fd = sv_fileno (fh); |
515 | int fd = sv_fileno (fh); |
481 | CHECK_FD (fh, fd); |
516 | CHECK_FD (fh, fd); |
482 | |
517 | |
483 | RETVAL = e_new (sizeof (ev_io), cb); |
518 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
484 | RETVAL->fh = newSVsv (fh); |
519 | RETVAL->fh = newSVsv (fh); |
485 | ev_io_set (RETVAL, fd, events); |
520 | ev_io_set (RETVAL, fd, events); |
486 | if (!ix) START (io, RETVAL); |
521 | if (!ix) START (io, RETVAL); |
487 | } |
522 | } |
488 | OUTPUT: |
523 | OUTPUT: |
… | |
… | |
492 | ALIAS: |
527 | ALIAS: |
493 | timer_ns = 1 |
528 | timer_ns = 1 |
494 | INIT: |
529 | INIT: |
495 | CHECK_REPEAT (repeat); |
530 | CHECK_REPEAT (repeat); |
496 | CODE: |
531 | CODE: |
497 | RETVAL = e_new (sizeof (ev_timer), cb); |
532 | RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv); |
498 | ev_timer_set (RETVAL, after, repeat); |
533 | ev_timer_set (RETVAL, after, repeat); |
499 | if (!ix) START (timer, RETVAL); |
534 | if (!ix) START (timer, RETVAL); |
500 | OUTPUT: |
535 | OUTPUT: |
501 | RETVAL |
536 | RETVAL |
502 | |
537 | |
… | |
… | |
506 | INIT: |
541 | INIT: |
507 | CHECK_REPEAT (interval); |
542 | CHECK_REPEAT (interval); |
508 | CODE: |
543 | CODE: |
509 | { |
544 | { |
510 | ev_periodic *w; |
545 | ev_periodic *w; |
511 | w = e_new (sizeof (ev_periodic), cb); |
546 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
512 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
547 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
513 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
548 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
514 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
549 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
515 | if (!ix) START (periodic, w); |
550 | if (!ix) START (periodic, w); |
516 | } |
551 | } |
… | |
… | |
523 | CODE: |
558 | CODE: |
524 | { |
559 | { |
525 | Signal signum = sv_signum (signal); |
560 | Signal signum = sv_signum (signal); |
526 | CHECK_SIG (signal, signum); |
561 | CHECK_SIG (signal, signum); |
527 | |
562 | |
528 | RETVAL = e_new (sizeof (ev_signal), cb); |
563 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
529 | ev_signal_set (RETVAL, signum); |
564 | ev_signal_set (RETVAL, signum); |
530 | if (!ix) START (signal, RETVAL); |
565 | if (!ix) START (signal, RETVAL); |
531 | } |
566 | } |
532 | OUTPUT: |
567 | OUTPUT: |
533 | RETVAL |
568 | RETVAL |
534 | |
569 | |
535 | ev_idle *idle (SV *cb) |
570 | ev_idle *idle (SV *cb) |
536 | ALIAS: |
571 | ALIAS: |
537 | idle_ns = 1 |
572 | idle_ns = 1 |
538 | CODE: |
573 | CODE: |
539 | RETVAL = e_new (sizeof (ev_idle), cb); |
574 | RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv); |
540 | ev_idle_set (RETVAL); |
575 | ev_idle_set (RETVAL); |
541 | if (!ix) START (idle, RETVAL); |
576 | if (!ix) START (idle, RETVAL); |
542 | OUTPUT: |
577 | OUTPUT: |
543 | RETVAL |
578 | RETVAL |
544 | |
579 | |
545 | ev_prepare *prepare (SV *cb) |
580 | ev_prepare *prepare (SV *cb) |
546 | ALIAS: |
581 | ALIAS: |
547 | prepare_ns = 1 |
582 | prepare_ns = 1 |
548 | CODE: |
583 | CODE: |
549 | RETVAL = e_new (sizeof (ev_prepare), cb); |
584 | RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv); |
550 | ev_prepare_set (RETVAL); |
585 | ev_prepare_set (RETVAL); |
551 | if (!ix) START (prepare, RETVAL); |
586 | if (!ix) START (prepare, RETVAL); |
552 | OUTPUT: |
587 | OUTPUT: |
553 | RETVAL |
588 | RETVAL |
554 | |
589 | |
555 | ev_check *check (SV *cb) |
590 | ev_check *check (SV *cb) |
556 | ALIAS: |
591 | ALIAS: |
557 | check_ns = 1 |
592 | check_ns = 1 |
558 | CODE: |
593 | CODE: |
559 | RETVAL = e_new (sizeof (ev_check), cb); |
594 | RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv); |
560 | ev_check_set (RETVAL); |
595 | ev_check_set (RETVAL); |
561 | if (!ix) START (check, RETVAL); |
596 | if (!ix) START (check, RETVAL); |
562 | OUTPUT: |
597 | OUTPUT: |
563 | RETVAL |
598 | RETVAL |
564 | |
599 | |
565 | ev_fork *fork (SV *cb) |
600 | ev_fork *fork (SV *cb) |
566 | ALIAS: |
601 | ALIAS: |
567 | fork_ns = 1 |
602 | fork_ns = 1 |
568 | CODE: |
603 | CODE: |
569 | RETVAL = e_new (sizeof (ev_fork), cb); |
604 | RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv); |
570 | ev_fork_set (RETVAL); |
605 | ev_fork_set (RETVAL); |
571 | if (!ix) START (fork, RETVAL); |
606 | if (!ix) START (fork, RETVAL); |
572 | OUTPUT: |
607 | OUTPUT: |
573 | RETVAL |
608 | RETVAL |
574 | |
609 | |
575 | ev_child *child (int pid, SV *cb) |
610 | ev_child *child (int pid, int trace, SV *cb) |
576 | ALIAS: |
611 | ALIAS: |
577 | child_ns = 1 |
612 | child_ns = 1 |
578 | CODE: |
613 | CODE: |
579 | RETVAL = e_new (sizeof (ev_child), cb); |
614 | RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); |
580 | ev_child_set (RETVAL, pid); |
615 | ev_child_set (RETVAL, pid, trace); |
581 | if (!ix) START (child, RETVAL); |
616 | if (!ix) START (child, RETVAL); |
582 | OUTPUT: |
617 | OUTPUT: |
583 | RETVAL |
618 | RETVAL |
584 | |
619 | |
585 | ev_stat *stat (SV *path, NV interval, SV *cb) |
620 | ev_stat *stat (SV *path, NV interval, SV *cb) |
586 | ALIAS: |
621 | ALIAS: |
587 | stat_ns = 1 |
622 | stat_ns = 1 |
588 | CODE: |
623 | CODE: |
589 | RETVAL = e_new (sizeof (ev_stat), cb); |
624 | RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv); |
590 | RETVAL->fh = newSVsv (path); |
625 | RETVAL->fh = newSVsv (path); |
591 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
626 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
592 | if (!ix) START (stat, RETVAL); |
627 | if (!ix) START (stat, RETVAL); |
|
|
628 | OUTPUT: |
|
|
629 | RETVAL |
|
|
630 | |
|
|
631 | ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef) |
|
|
632 | ALIAS: |
|
|
633 | embed_ns = 1 |
|
|
634 | CODE: |
|
|
635 | { |
|
|
636 | if (!(ev_backend (loop) & ev_embeddable_backends ())) |
|
|
637 | croak ("passed loop is not embeddable via EV::embed,"); |
|
|
638 | |
|
|
639 | RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); |
|
|
640 | RETVAL->fh = newSVsv (ST (0)); |
|
|
641 | ev_embed_set (RETVAL, loop); |
|
|
642 | |
|
|
643 | if (!SvOK (cb)) ev_set_cb (RETVAL, 0); |
|
|
644 | |
|
|
645 | if (!ix) START (embed, RETVAL); |
|
|
646 | } |
593 | OUTPUT: |
647 | OUTPUT: |
594 | RETVAL |
648 | RETVAL |
595 | |
649 | |
596 | void once (SV *fh, int events, SV *timeout, SV *cb) |
650 | void once (SV *fh, int events, SV *timeout, SV *cb) |
597 | CODE: |
651 | CODE: |
… | |
… | |
610 | int ev_is_active (ev_watcher *w) |
664 | int ev_is_active (ev_watcher *w) |
611 | |
665 | |
612 | int ev_is_pending (ev_watcher *w) |
666 | int ev_is_pending (ev_watcher *w) |
613 | |
667 | |
614 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
668 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
615 | C_ARGS: w->loop, w, revents |
669 | C_ARGS: e_loop (w), w, revents |
616 | |
670 | |
617 | int ev_clear_pending (ev_watcher *w) |
671 | int ev_clear_pending (ev_watcher *w) |
618 | C_ARGS: w->loop, w |
672 | C_ARGS: e_loop (w), w |
619 | |
673 | |
620 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
674 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
621 | C_ARGS: w->loop, w, revents |
675 | C_ARGS: e_loop (w), w, revents |
622 | |
676 | |
623 | int keepalive (ev_watcher *w, int new_value = 0) |
677 | int keepalive (ev_watcher *w, int new_value = 0) |
624 | CODE: |
678 | CODE: |
625 | { |
679 | { |
626 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
680 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
627 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
681 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
628 | |
682 | |
629 | if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) |
683 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
630 | { |
684 | { |
631 | REF (w); |
685 | REF (w); |
632 | w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; |
686 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
633 | UNREF (w); |
687 | UNREF (w); |
634 | } |
688 | } |
635 | } |
689 | } |
636 | OUTPUT: |
690 | OUTPUT: |
637 | RETVAL |
691 | RETVAL |
… | |
… | |
656 | { |
710 | { |
657 | SvREFCNT_dec (w->data); |
711 | SvREFCNT_dec (w->data); |
658 | w->data = newSVsv (new_data); |
712 | w->data = newSVsv (new_data); |
659 | } |
713 | } |
660 | } |
714 | } |
|
|
715 | OUTPUT: |
|
|
716 | RETVAL |
|
|
717 | |
|
|
718 | SV *loop (ev_watcher *w) |
|
|
719 | CODE: |
|
|
720 | RETVAL = newRV_inc (w->loop); |
661 | OUTPUT: |
721 | OUTPUT: |
662 | RETVAL |
722 | RETVAL |
663 | |
723 | |
664 | int priority (ev_watcher *w, int new_priority = 0) |
724 | int priority (ev_watcher *w, int new_priority = 0) |
665 | CODE: |
725 | CODE: |
… | |
… | |
803 | void ev_timer_again (ev_timer *w) |
863 | void ev_timer_again (ev_timer *w) |
804 | INIT: |
864 | INIT: |
805 | CHECK_REPEAT (w->repeat); |
865 | CHECK_REPEAT (w->repeat); |
806 | CODE: |
866 | CODE: |
807 | REF (w); |
867 | REF (w); |
808 | ev_timer_again (w->loop, w); |
868 | ev_timer_again (e_loop (w), w); |
809 | UNREF (w); |
869 | UNREF (w); |
810 | |
870 | |
811 | void DESTROY (ev_timer *w) |
871 | void DESTROY (ev_timer *w) |
812 | CODE: |
872 | CODE: |
813 | STOP (timer, w); |
873 | STOP (timer, w); |
… | |
… | |
838 | STOP (periodic, w); |
898 | STOP (periodic, w); |
839 | |
899 | |
840 | void ev_periodic_again (ev_periodic *w) |
900 | void ev_periodic_again (ev_periodic *w) |
841 | CODE: |
901 | CODE: |
842 | REF (w); |
902 | REF (w); |
843 | ev_periodic_again (w->loop, w); |
903 | ev_periodic_again (e_loop (w), w); |
844 | UNREF (w); |
904 | UNREF (w); |
845 | |
905 | |
846 | void DESTROY (ev_periodic *w) |
906 | void DESTROY (ev_periodic *w) |
847 | CODE: |
907 | CODE: |
848 | STOP (periodic, w); |
908 | STOP (periodic, w); |
… | |
… | |
878 | void DESTROY (ev_idle *w) |
938 | void DESTROY (ev_idle *w) |
879 | CODE: |
939 | CODE: |
880 | STOP (idle, w); |
940 | STOP (idle, w); |
881 | e_destroy (w); |
941 | e_destroy (w); |
882 | |
942 | |
883 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ |
943 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_ |
884 | |
944 | |
885 | void ev_prepare_start (ev_prepare *w) |
945 | void ev_prepare_start (ev_prepare *w) |
886 | CODE: |
946 | CODE: |
887 | START (prepare, w); |
947 | START (prepare, w); |
888 | |
948 | |
… | |
… | |
938 | void DESTROY (ev_child *w) |
998 | void DESTROY (ev_child *w) |
939 | CODE: |
999 | CODE: |
940 | STOP (child, w); |
1000 | STOP (child, w); |
941 | e_destroy (w); |
1001 | e_destroy (w); |
942 | |
1002 | |
943 | void set (ev_child *w, int pid) |
1003 | void set (ev_child *w, int pid, int trace) |
944 | CODE: |
1004 | CODE: |
945 | RESET (child, w, (w, pid)); |
1005 | RESET (child, w, (w, pid, trace)); |
946 | |
1006 | |
947 | int pid (ev_child *w, int new_pid = 0) |
|
|
948 | CODE: |
|
|
949 | { |
|
|
950 | RETVAL = w->pid; |
|
|
951 | |
|
|
952 | if (items > 1) |
|
|
953 | RESET (child, w, (w, new_pid)); |
|
|
954 | } |
|
|
955 | OUTPUT: |
|
|
956 | RETVAL |
|
|
957 | |
|
|
958 | |
|
|
959 | int rstatus (ev_child *w) |
1007 | int pid (ev_child *w) |
960 | ALIAS: |
1008 | ALIAS: |
961 | rpid = 1 |
1009 | rpid = 1 |
|
|
1010 | rstatus = 2 |
962 | CODE: |
1011 | CODE: |
963 | RETVAL = ix ? w->rpid : w->rstatus; |
1012 | RETVAL = ix == 0 ? w->pid |
|
|
1013 | : ix == 1 ? w->rpid |
|
|
1014 | : w->rstatus; |
964 | OUTPUT: |
1015 | OUTPUT: |
965 | RETVAL |
1016 | RETVAL |
966 | |
1017 | |
967 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
1018 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
968 | |
1019 | |
… | |
… | |
1019 | PPCODE: |
1070 | PPCODE: |
1020 | { |
1071 | { |
1021 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1072 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1022 | |
1073 | |
1023 | if (ix == 1) |
1074 | if (ix == 1) |
1024 | ev_stat_stat (w->loop, w); |
1075 | ev_stat_stat (e_loop (w), w); |
1025 | else if (!s->st_nlink) |
1076 | else if (!s->st_nlink) |
1026 | errno = ENOENT; |
1077 | errno = ENOENT; |
1027 | |
1078 | |
1028 | PL_statcache.st_dev = s->st_nlink; |
1079 | PL_statcache.st_dev = s->st_nlink; |
1029 | PL_statcache.st_ino = s->st_ino; |
1080 | PL_statcache.st_ino = s->st_ino; |
… | |
… | |
1056 | PUSHs (sv_2mortal (newSVuv (4096))); |
1107 | PUSHs (sv_2mortal (newSVuv (4096))); |
1057 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
1108 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
1058 | } |
1109 | } |
1059 | } |
1110 | } |
1060 | |
1111 | |
|
|
1112 | MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_ |
|
|
1113 | |
|
|
1114 | void ev_embed_start (ev_embed *w) |
|
|
1115 | CODE: |
|
|
1116 | START (embed, w); |
|
|
1117 | |
|
|
1118 | void ev_embed_stop (ev_embed *w) |
|
|
1119 | CODE: |
|
|
1120 | STOP (embed, w); |
|
|
1121 | |
|
|
1122 | void DESTROY (ev_embed *w) |
|
|
1123 | CODE: |
|
|
1124 | STOP (embed, w); |
|
|
1125 | e_destroy (w); |
|
|
1126 | |
|
|
1127 | void set (ev_embed *w, struct ev_loop *loop) |
|
|
1128 | CODE: |
|
|
1129 | { |
|
|
1130 | sv_setsv (w->fh, ST (1)); |
|
|
1131 | RESET (embed, w, (w, loop)); |
|
|
1132 | } |
|
|
1133 | |
|
|
1134 | SV *other (ev_embed *w) |
|
|
1135 | CODE: |
|
|
1136 | RETVAL = newSVsv (w->fh); |
|
|
1137 | OUTPUT: |
|
|
1138 | RETVAL |
|
|
1139 | |
|
|
1140 | MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ |
|
|
1141 | |
|
|
1142 | SV *new (SV *klass, unsigned int flags = 0) |
|
|
1143 | CODE: |
|
|
1144 | { |
|
|
1145 | struct ev_loop *loop = ev_loop_new (flags); |
|
|
1146 | |
|
|
1147 | if (!loop) |
|
|
1148 | XSRETURN_UNDEF; |
|
|
1149 | |
|
|
1150 | RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop); |
|
|
1151 | } |
|
|
1152 | OUTPUT: |
|
|
1153 | RETVAL |
|
|
1154 | |
|
|
1155 | void DESTROY (struct ev_loop *loop) |
|
|
1156 | CODE: |
|
|
1157 | if (loop != evapi.default_loop) /* global destruction sucks */ |
|
|
1158 | ev_loop_destroy (loop); |
|
|
1159 | |
|
|
1160 | void ev_loop_fork (struct ev_loop *loop) |
|
|
1161 | |
|
|
1162 | NV ev_now (struct ev_loop *loop) |
|
|
1163 | |
|
|
1164 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1165 | |
|
|
1166 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1167 | |
|
|
1168 | unsigned int ev_backend (struct ev_loop *loop) |
|
|
1169 | |
|
|
1170 | unsigned int ev_loop_count (struct ev_loop *loop) |
|
|
1171 | |
|
|
1172 | void ev_loop (struct ev_loop *loop, int flags = 0) |
|
|
1173 | |
|
|
1174 | void ev_unloop (struct ev_loop *loop, int how = 1) |
|
|
1175 | |
|
|
1176 | void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) |
|
|
1177 | |
1061 | #if 0 |
1178 | #if 0 |
1062 | |
1179 | |
1063 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1180 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1064 | |
1181 | CODE: |
1065 | BOOT: |
|
|
1066 | { |
1182 | { |
1067 | HV *stash = gv_stashpv ("EV::HTTP", 1); |
1183 | Signal signum = sv_signum (signal); |
|
|
1184 | CHECK_SIG (signal, signum); |
1068 | |
1185 | |
1069 | static const struct { |
1186 | 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 | } |
1187 | } |
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 | |
1188 | |
1101 | #endif |
1189 | #endif |
1102 | |
1190 | |
|
|
1191 | ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) |
|
|
1192 | ALIAS: |
|
|
1193 | io_ns = 1 |
|
|
1194 | CODE: |
|
|
1195 | { |
|
|
1196 | int fd = sv_fileno (fh); |
|
|
1197 | CHECK_FD (fh, fd); |
1103 | |
1198 | |
|
|
1199 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
|
|
1200 | RETVAL->fh = newSVsv (fh); |
|
|
1201 | ev_io_set (RETVAL, fd, events); |
|
|
1202 | if (!ix) START (io, RETVAL); |
|
|
1203 | } |
|
|
1204 | OUTPUT: |
|
|
1205 | RETVAL |
1104 | |
1206 | |
|
|
1207 | ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb) |
|
|
1208 | ALIAS: |
|
|
1209 | timer_ns = 1 |
|
|
1210 | INIT: |
|
|
1211 | CHECK_REPEAT (repeat); |
|
|
1212 | CODE: |
|
|
1213 | RETVAL = e_new (sizeof (ev_timer), cb, ST (0)); |
|
|
1214 | ev_timer_set (RETVAL, after, repeat); |
|
|
1215 | if (!ix) START (timer, RETVAL); |
|
|
1216 | OUTPUT: |
|
|
1217 | RETVAL |
1105 | |
1218 | |
|
|
1219 | SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb) |
|
|
1220 | ALIAS: |
|
|
1221 | periodic_ns = 1 |
|
|
1222 | INIT: |
|
|
1223 | CHECK_REPEAT (interval); |
|
|
1224 | CODE: |
|
|
1225 | { |
|
|
1226 | ev_periodic *w; |
|
|
1227 | w = e_new (sizeof (ev_periodic), cb, ST (0)); |
|
|
1228 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
1229 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
|
|
1230 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
|
|
1231 | if (!ix) START (periodic, w); |
|
|
1232 | } |
|
|
1233 | OUTPUT: |
|
|
1234 | RETVAL |
1106 | |
1235 | |
|
|
1236 | #if 0 |
1107 | |
1237 | |
|
|
1238 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
|
|
1239 | ALIAS: |
|
|
1240 | signal_ns = 1 |
|
|
1241 | CODE: |
|
|
1242 | { |
|
|
1243 | Signal signum = sv_signum (signal); |
|
|
1244 | CHECK_SIG (signal, signum); |
1108 | |
1245 | |
|
|
1246 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
|
|
1247 | ev_signal_set (RETVAL, signum); |
|
|
1248 | if (!ix) START (signal, RETVAL); |
|
|
1249 | } |
|
|
1250 | OUTPUT: |
|
|
1251 | RETVAL |
1109 | |
1252 | |
|
|
1253 | #endif |
|
|
1254 | |
|
|
1255 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
|
|
1256 | ALIAS: |
|
|
1257 | idle_ns = 1 |
|
|
1258 | CODE: |
|
|
1259 | RETVAL = e_new (sizeof (ev_idle), cb, ST (0)); |
|
|
1260 | ev_idle_set (RETVAL); |
|
|
1261 | if (!ix) START (idle, RETVAL); |
|
|
1262 | OUTPUT: |
|
|
1263 | RETVAL |
|
|
1264 | |
|
|
1265 | ev_prepare *prepare (struct ev_loop *loop, SV *cb) |
|
|
1266 | ALIAS: |
|
|
1267 | prepare_ns = 1 |
|
|
1268 | CODE: |
|
|
1269 | RETVAL = e_new (sizeof (ev_prepare), cb, ST (0)); |
|
|
1270 | ev_prepare_set (RETVAL); |
|
|
1271 | if (!ix) START (prepare, RETVAL); |
|
|
1272 | OUTPUT: |
|
|
1273 | RETVAL |
|
|
1274 | |
|
|
1275 | ev_check *check (struct ev_loop *loop, SV *cb) |
|
|
1276 | ALIAS: |
|
|
1277 | check_ns = 1 |
|
|
1278 | CODE: |
|
|
1279 | RETVAL = e_new (sizeof (ev_check), cb, ST (0)); |
|
|
1280 | ev_check_set (RETVAL); |
|
|
1281 | if (!ix) START (check, RETVAL); |
|
|
1282 | OUTPUT: |
|
|
1283 | RETVAL |
|
|
1284 | |
|
|
1285 | ev_fork *fork (struct ev_loop *loop, SV *cb) |
|
|
1286 | ALIAS: |
|
|
1287 | fork_ns = 1 |
|
|
1288 | CODE: |
|
|
1289 | RETVAL = e_new (sizeof (ev_fork), cb, ST (0)); |
|
|
1290 | ev_fork_set (RETVAL); |
|
|
1291 | if (!ix) START (fork, RETVAL); |
|
|
1292 | OUTPUT: |
|
|
1293 | RETVAL |
|
|
1294 | |
|
|
1295 | ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) |
|
|
1296 | ALIAS: |
|
|
1297 | child_ns = 1 |
|
|
1298 | CODE: |
|
|
1299 | RETVAL = e_new (sizeof (ev_child), cb, ST (0)); |
|
|
1300 | ev_child_set (RETVAL, pid, trace); |
|
|
1301 | if (!ix) START (child, RETVAL); |
|
|
1302 | OUTPUT: |
|
|
1303 | RETVAL |
|
|
1304 | |
|
|
1305 | ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) |
|
|
1306 | ALIAS: |
|
|
1307 | stat_ns = 1 |
|
|
1308 | CODE: |
|
|
1309 | RETVAL = e_new (sizeof (ev_stat), cb, ST (0)); |
|
|
1310 | RETVAL->fh = newSVsv (path); |
|
|
1311 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
|
|
1312 | if (!ix) START (stat, RETVAL); |
|
|
1313 | OUTPUT: |
|
|
1314 | RETVAL |
|
|
1315 | |
|
|
1316 | ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef) |
|
|
1317 | ALIAS: |
|
|
1318 | embed_ns = 1 |
|
|
1319 | CODE: |
|
|
1320 | { |
|
|
1321 | if (!(ev_backend (other) & ev_embeddable_backends ())) |
|
|
1322 | croak ("passed loop is not embeddable via EV::embed,"); |
|
|
1323 | |
|
|
1324 | RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); |
|
|
1325 | RETVAL->fh = newSVsv (ST (1)); |
|
|
1326 | ev_embed_set (RETVAL, other); |
|
|
1327 | |
|
|
1328 | if (!SvOK (cb)) ev_set_cb (RETVAL, 0); |
|
|
1329 | |
|
|
1330 | if (!ix) START (embed, RETVAL); |
|
|
1331 | } |
|
|
1332 | OUTPUT: |
|
|
1333 | RETVAL |
|
|
1334 | |
|
|
1335 | void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) |
|
|
1336 | CODE: |
|
|
1337 | ev_once ( |
|
|
1338 | loop, |
|
|
1339 | sv_fileno (fh), events, |
|
|
1340 | SvOK (timeout) ? SvNV (timeout) : -1., |
|
|
1341 | e_once_cb, |
|
|
1342 | newSVsv (cb) |
|
|
1343 | ); |
|
|
1344 | |