… | |
… | |
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 |
7 | #define TIMEOUT_NONE HUGE_VAL |
8 | #define HAVE_EPOLL 0 |
8 | #define HAVE_EPOLL 1 |
9 | |
9 | |
10 | #define EV_PROTOTYPES 1 |
10 | #define EV_PROTOTYPES 1 |
11 | #include "EV/EVAPI.h" |
11 | #include "EV/EVAPI.h" |
12 | |
12 | |
13 | #include "libev/ev.c" |
13 | #include "libev/ev.c" |
… | |
… | |
22 | *stash_time, |
22 | *stash_time, |
23 | *stash_timer, |
23 | *stash_timer, |
24 | *stash_periodic, |
24 | *stash_periodic, |
25 | *stash_signal, |
25 | *stash_signal, |
26 | *stash_idle, |
26 | *stash_idle, |
|
|
27 | *stash_prepare, |
27 | *stash_check; |
28 | *stash_check, |
|
|
29 | *stash_child; |
28 | |
30 | |
29 | static int |
31 | static int |
30 | sv_signum (SV *sig) |
32 | sv_signum (SV *sig) |
31 | { |
33 | { |
32 | int signum; |
34 | int signum; |
… | |
… | |
102 | static void |
104 | static void |
103 | e_cb (struct ev_watcher *w, int revents) |
105 | e_cb (struct ev_watcher *w, int revents) |
104 | { |
106 | { |
105 | dSP; |
107 | dSP; |
106 | I32 mark = SP - PL_stack_base; |
108 | I32 mark = SP - PL_stack_base; |
107 | SV *sv_self, *sv_events; |
109 | SV *sv_self, *sv_events, *sv_status = 0; |
108 | static SV *sv_events_cache; |
110 | static SV *sv_events_cache; |
109 | |
111 | |
110 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
112 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
111 | |
113 | |
112 | if (sv_events_cache) |
114 | if (sv_events_cache) |
… | |
… | |
119 | |
121 | |
120 | PUSHMARK (SP); |
122 | PUSHMARK (SP); |
121 | EXTEND (SP, 2); |
123 | EXTEND (SP, 2); |
122 | PUSHs (sv_self); |
124 | PUSHs (sv_self); |
123 | PUSHs (sv_events); |
125 | PUSHs (sv_events); |
|
|
126 | |
|
|
127 | if (revents & EV_CHILD) |
|
|
128 | XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status)); |
|
|
129 | |
124 | PUTBACK; |
130 | PUTBACK; |
125 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
131 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
126 | SP = PL_stack_base + mark; PUTBACK; |
132 | SP = PL_stack_base + mark; PUTBACK; |
127 | |
133 | |
128 | SvREFCNT_dec (sv_self); |
134 | SvREFCNT_dec (sv_self); |
|
|
135 | SvREFCNT_dec (sv_status); |
129 | |
136 | |
130 | if (sv_events_cache) |
137 | if (sv_events_cache) |
131 | SvREFCNT_dec (sv_events); |
138 | SvREFCNT_dec (sv_events); |
132 | else |
139 | else |
133 | sv_events_cache = sv_events; |
140 | sv_events_cache = sv_events; |
… | |
… | |
241 | stash_time = gv_stashpv ("EV::Time" , 1); |
248 | stash_time = gv_stashpv ("EV::Time" , 1); |
242 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
249 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
243 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
250 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
244 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
251 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
245 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
252 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
|
|
253 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
246 | stash_check = gv_stashpv ("EV::Check" , 1); |
254 | stash_check = gv_stashpv ("EV::Check" , 1); |
|
|
255 | stash_child = gv_stashpv ("EV::Child" , 1); |
247 | |
256 | |
248 | { |
257 | { |
249 | SV *sv = perl_get_sv ("EV::API", TRUE); |
258 | SV *sv = perl_get_sv ("EV::API", TRUE); |
250 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
259 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
251 | |
260 | |
… | |
… | |
269 | evapi.periodic_stop = evperiodic_stop; |
278 | evapi.periodic_stop = evperiodic_stop; |
270 | evapi.signal_start = evsignal_start; |
279 | evapi.signal_start = evsignal_start; |
271 | evapi.signal_stop = evsignal_stop; |
280 | evapi.signal_stop = evsignal_stop; |
272 | evapi.idle_start = evidle_start; |
281 | evapi.idle_start = evidle_start; |
273 | evapi.idle_stop = evidle_stop; |
282 | evapi.idle_stop = evidle_stop; |
|
|
283 | evapi.prepare_start = evprepare_start; |
|
|
284 | evapi.prepare_stop = evprepare_stop; |
274 | evapi.check_start = evcheck_start; |
285 | evapi.check_start = evcheck_start; |
275 | evapi.check_stop = evcheck_stop; |
286 | evapi.check_stop = evcheck_stop; |
|
|
287 | evapi.child_start = evchild_start; |
|
|
288 | evapi.child_stop = evchild_stop; |
276 | |
289 | |
277 | sv_setiv (sv, (IV)&evapi); |
290 | sv_setiv (sv, (IV)&evapi); |
278 | SvREADONLY_on (sv); |
291 | SvREADONLY_on (sv); |
279 | } |
292 | } |
280 | } |
293 | } |
… | |
… | |
354 | evidle_set (RETVAL); |
367 | evidle_set (RETVAL); |
355 | if (!ix) evidle_start (RETVAL); |
368 | if (!ix) evidle_start (RETVAL); |
356 | OUTPUT: |
369 | OUTPUT: |
357 | RETVAL |
370 | RETVAL |
358 | |
371 | |
|
|
372 | struct ev_prepare *prepare (SV *cb) |
|
|
373 | ALIAS: |
|
|
374 | prepare_ns = 1 |
|
|
375 | CODE: |
|
|
376 | RETVAL = e_new (sizeof (struct ev_prepare), cb); |
|
|
377 | evprepare_set (RETVAL); |
|
|
378 | if (!ix) evprepare_start (RETVAL); |
|
|
379 | OUTPUT: |
|
|
380 | RETVAL |
|
|
381 | |
359 | struct ev_check *check (SV *cb) |
382 | struct ev_check *check (SV *cb) |
360 | ALIAS: |
383 | ALIAS: |
361 | check_ns = 1 |
384 | check_ns = 1 |
362 | CODE: |
385 | CODE: |
363 | RETVAL = e_new (sizeof (struct ev_check), cb); |
386 | RETVAL = e_new (sizeof (struct ev_check), cb); |
364 | evcheck_set (RETVAL); |
387 | evcheck_set (RETVAL); |
365 | if (!ix) evcheck_start (RETVAL); |
388 | if (!ix) evcheck_start (RETVAL); |
366 | OUTPUT: |
389 | OUTPUT: |
367 | RETVAL |
390 | RETVAL |
368 | |
391 | |
|
|
392 | struct ev_child *child (int pid, SV *cb) |
|
|
393 | ALIAS: |
|
|
394 | check_ns = 1 |
|
|
395 | CODE: |
|
|
396 | RETVAL = e_new (sizeof (struct ev_check), cb); |
|
|
397 | evchild_set (RETVAL, pid); |
|
|
398 | if (!ix) evchild_start (RETVAL); |
|
|
399 | OUTPUT: |
|
|
400 | RETVAL |
|
|
401 | |
369 | |
402 | |
370 | PROTOTYPES: DISABLE |
403 | PROTOTYPES: DISABLE |
371 | |
404 | |
372 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
405 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
373 | |
406 | |
… | |
… | |
387 | MODULE = EV PACKAGE = EV::IO PREFIX = evio_ |
420 | MODULE = EV PACKAGE = EV::IO PREFIX = evio_ |
388 | |
421 | |
389 | void evio_start (struct ev_io *w) |
422 | void evio_start (struct ev_io *w) |
390 | |
423 | |
391 | void evio_stop (struct ev_io *w) |
424 | void evio_stop (struct ev_io *w) |
|
|
425 | |
|
|
426 | void DESTROY (struct ev_io *w) |
|
|
427 | CODE: |
|
|
428 | evio_stop (w); |
392 | |
429 | |
393 | void set (struct ev_io *w, SV *fh, int events) |
430 | void set (struct ev_io *w, SV *fh, int events) |
394 | CODE: |
431 | CODE: |
395 | { |
432 | { |
396 | int active = w->active; |
433 | int active = w->active; |
… | |
… | |
443 | |
480 | |
444 | void evsignal_start (struct ev_signal *w) |
481 | void evsignal_start (struct ev_signal *w) |
445 | |
482 | |
446 | void evsignal_stop (struct ev_signal *w) |
483 | void evsignal_stop (struct ev_signal *w) |
447 | |
484 | |
|
|
485 | void DESTROY (struct ev_signal *w) |
|
|
486 | CODE: |
|
|
487 | evsignal_stop (w); |
|
|
488 | |
448 | void set (struct ev_signal *w, SV *signal = 0) |
489 | void set (struct ev_signal *w, SV *signal = 0) |
449 | CODE: |
490 | CODE: |
450 | { |
491 | { |
451 | Signal signum = sv_signum (signal); /* may croak here */ |
492 | Signal signum = sv_signum (signal); /* may croak here */ |
452 | int active = w->active; |
493 | int active = w->active; |
… | |
… | |
467 | void evtimer_stop (struct ev_timer *w) |
508 | void evtimer_stop (struct ev_timer *w) |
468 | |
509 | |
469 | void evtimer_again (struct ev_timer *w) |
510 | void evtimer_again (struct ev_timer *w) |
470 | INIT: |
511 | INIT: |
471 | CHECK_REPEAT (w->repeat); |
512 | CHECK_REPEAT (w->repeat); |
|
|
513 | |
|
|
514 | void DESTROY (struct ev_timer *w) |
|
|
515 | CODE: |
|
|
516 | evtimer_stop (w); |
472 | |
517 | |
473 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
518 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
474 | INIT: |
519 | INIT: |
475 | CHECK_REPEAT (repeat); |
520 | CHECK_REPEAT (repeat); |
476 | CODE: |
521 | CODE: |
… | |
… | |
487 | INIT: |
532 | INIT: |
488 | CHECK_REPEAT (w->interval); |
533 | CHECK_REPEAT (w->interval); |
489 | |
534 | |
490 | void evperiodic_stop (struct ev_periodic *w) |
535 | void evperiodic_stop (struct ev_periodic *w) |
491 | |
536 | |
|
|
537 | void DESTROY (struct ev_periodic *w) |
|
|
538 | CODE: |
|
|
539 | evperiodic_stop (w); |
|
|
540 | |
492 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
541 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
493 | INIT: |
542 | INIT: |
494 | CHECK_REPEAT (interval); |
543 | CHECK_REPEAT (interval); |
495 | CODE: |
544 | CODE: |
496 | { |
545 | { |
… | |
… | |
504 | |
553 | |
505 | void evidle_start (struct ev_idle *w) |
554 | void evidle_start (struct ev_idle *w) |
506 | |
555 | |
507 | void evidle_stop (struct ev_idle *w) |
556 | void evidle_stop (struct ev_idle *w) |
508 | |
557 | |
|
|
558 | void DESTROY (struct ev_idle *w) |
|
|
559 | CODE: |
|
|
560 | evidle_stop (w); |
|
|
561 | |
|
|
562 | MODULE = EV PACKAGE = EV::Prepare PREFIX = evcheck_ |
|
|
563 | |
|
|
564 | void evprepare_start (struct ev_prepare *w) |
|
|
565 | |
|
|
566 | void evprepare_stop (struct ev_prepare *w) |
|
|
567 | |
|
|
568 | void DESTROY (struct ev_prepare *w) |
|
|
569 | CODE: |
|
|
570 | evprepare_stop (w); |
|
|
571 | |
509 | MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ |
572 | MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ |
510 | |
573 | |
511 | void evcheck_start (struct ev_check *w) |
574 | void evcheck_start (struct ev_check *w) |
512 | |
575 | |
513 | void evcheck_stop (struct ev_check *w) |
576 | void evcheck_stop (struct ev_check *w) |
|
|
577 | |
|
|
578 | void DESTROY (struct ev_check *w) |
|
|
579 | CODE: |
|
|
580 | evcheck_stop (w); |
|
|
581 | |
|
|
582 | MODULE = EV PACKAGE = EV::Child PREFIX = evchild_ |
|
|
583 | |
|
|
584 | void evchild_start (struct ev_child *w) |
|
|
585 | |
|
|
586 | void evchild_stop (struct ev_child *w) |
|
|
587 | |
|
|
588 | void DESTROY (struct ev_child *w) |
|
|
589 | CODE: |
|
|
590 | evchild_stop (w); |
|
|
591 | |
|
|
592 | void set (struct ev_child *w, int pid) |
|
|
593 | CODE: |
|
|
594 | { |
|
|
595 | int active = w->active; |
|
|
596 | if (active) evchild_stop (w); |
|
|
597 | evchild_set (w, pid); |
|
|
598 | if (active) evchild_start (w); |
|
|
599 | } |
|
|
600 | |
|
|
601 | int status (struct ev_child *w) |
|
|
602 | CODE: |
|
|
603 | RETVAL = w->status; |
|
|
604 | OUTPUT: |
|
|
605 | RETVAL |
514 | |
606 | |
515 | #if 0 |
607 | #if 0 |
516 | |
608 | |
517 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
609 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
518 | |
610 | |