… | |
… | |
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; |
… | |
… | |
235 | |
242 | |
236 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
243 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
237 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
244 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
238 | |
245 | |
239 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
246 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
240 | stash_io = gv_stashpv ("EV::IO" , 1); |
247 | stash_io = gv_stashpv ("EV::Io" , 1); |
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 | |
… | |
… | |
382 | sv_setsv (w->cb_sv, new_cb); |
415 | sv_setsv (w->cb_sv, new_cb); |
383 | } |
416 | } |
384 | OUTPUT: |
417 | OUTPUT: |
385 | RETVAL |
418 | RETVAL |
386 | |
419 | |
|
|
420 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
|
|
421 | CODE: |
|
|
422 | w->cb (w, revents); |
|
|
423 | |
387 | MODULE = EV PACKAGE = EV::IO PREFIX = evio_ |
424 | MODULE = EV PACKAGE = EV::Io PREFIX = evio_ |
388 | |
425 | |
389 | void evio_start (struct ev_io *w) |
426 | void evio_start (struct ev_io *w) |
390 | |
427 | |
391 | void evio_stop (struct ev_io *w) |
428 | void evio_stop (struct ev_io *w) |
|
|
429 | |
|
|
430 | void DESTROY (struct ev_io *w) |
|
|
431 | CODE: |
|
|
432 | evio_stop (w); |
392 | |
433 | |
393 | void set (struct ev_io *w, SV *fh, int events) |
434 | void set (struct ev_io *w, SV *fh, int events) |
394 | CODE: |
435 | CODE: |
395 | { |
436 | { |
396 | int active = w->active; |
437 | int active = w->active; |
… | |
… | |
443 | |
484 | |
444 | void evsignal_start (struct ev_signal *w) |
485 | void evsignal_start (struct ev_signal *w) |
445 | |
486 | |
446 | void evsignal_stop (struct ev_signal *w) |
487 | void evsignal_stop (struct ev_signal *w) |
447 | |
488 | |
|
|
489 | void DESTROY (struct ev_signal *w) |
|
|
490 | CODE: |
|
|
491 | evsignal_stop (w); |
|
|
492 | |
448 | void set (struct ev_signal *w, SV *signal = 0) |
493 | void set (struct ev_signal *w, SV *signal = 0) |
449 | CODE: |
494 | CODE: |
450 | { |
495 | { |
451 | Signal signum = sv_signum (signal); /* may croak here */ |
496 | Signal signum = sv_signum (signal); /* may croak here */ |
452 | int active = w->active; |
497 | int active = w->active; |
… | |
… | |
467 | void evtimer_stop (struct ev_timer *w) |
512 | void evtimer_stop (struct ev_timer *w) |
468 | |
513 | |
469 | void evtimer_again (struct ev_timer *w) |
514 | void evtimer_again (struct ev_timer *w) |
470 | INIT: |
515 | INIT: |
471 | CHECK_REPEAT (w->repeat); |
516 | CHECK_REPEAT (w->repeat); |
|
|
517 | |
|
|
518 | void DESTROY (struct ev_timer *w) |
|
|
519 | CODE: |
|
|
520 | evtimer_stop (w); |
472 | |
521 | |
473 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
522 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
474 | INIT: |
523 | INIT: |
475 | CHECK_REPEAT (repeat); |
524 | CHECK_REPEAT (repeat); |
476 | CODE: |
525 | CODE: |
… | |
… | |
487 | INIT: |
536 | INIT: |
488 | CHECK_REPEAT (w->interval); |
537 | CHECK_REPEAT (w->interval); |
489 | |
538 | |
490 | void evperiodic_stop (struct ev_periodic *w) |
539 | void evperiodic_stop (struct ev_periodic *w) |
491 | |
540 | |
|
|
541 | void DESTROY (struct ev_periodic *w) |
|
|
542 | CODE: |
|
|
543 | evperiodic_stop (w); |
|
|
544 | |
492 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
545 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
493 | INIT: |
546 | INIT: |
494 | CHECK_REPEAT (interval); |
547 | CHECK_REPEAT (interval); |
495 | CODE: |
548 | CODE: |
496 | { |
549 | { |
… | |
… | |
504 | |
557 | |
505 | void evidle_start (struct ev_idle *w) |
558 | void evidle_start (struct ev_idle *w) |
506 | |
559 | |
507 | void evidle_stop (struct ev_idle *w) |
560 | void evidle_stop (struct ev_idle *w) |
508 | |
561 | |
|
|
562 | void DESTROY (struct ev_idle *w) |
|
|
563 | CODE: |
|
|
564 | evidle_stop (w); |
|
|
565 | |
|
|
566 | MODULE = EV PACKAGE = EV::Prepare PREFIX = evcheck_ |
|
|
567 | |
|
|
568 | void evprepare_start (struct ev_prepare *w) |
|
|
569 | |
|
|
570 | void evprepare_stop (struct ev_prepare *w) |
|
|
571 | |
|
|
572 | void DESTROY (struct ev_prepare *w) |
|
|
573 | CODE: |
|
|
574 | evprepare_stop (w); |
|
|
575 | |
509 | MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ |
576 | MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ |
510 | |
577 | |
511 | void evcheck_start (struct ev_check *w) |
578 | void evcheck_start (struct ev_check *w) |
512 | |
579 | |
513 | void evcheck_stop (struct ev_check *w) |
580 | void evcheck_stop (struct ev_check *w) |
|
|
581 | |
|
|
582 | void DESTROY (struct ev_check *w) |
|
|
583 | CODE: |
|
|
584 | evcheck_stop (w); |
|
|
585 | |
|
|
586 | MODULE = EV PACKAGE = EV::Child PREFIX = evchild_ |
|
|
587 | |
|
|
588 | void evchild_start (struct ev_child *w) |
|
|
589 | |
|
|
590 | void evchild_stop (struct ev_child *w) |
|
|
591 | |
|
|
592 | void DESTROY (struct ev_child *w) |
|
|
593 | CODE: |
|
|
594 | evchild_stop (w); |
|
|
595 | |
|
|
596 | void set (struct ev_child *w, int pid) |
|
|
597 | CODE: |
|
|
598 | { |
|
|
599 | int active = w->active; |
|
|
600 | if (active) evchild_stop (w); |
|
|
601 | evchild_set (w, pid); |
|
|
602 | if (active) evchild_start (w); |
|
|
603 | } |
|
|
604 | |
|
|
605 | int status (struct ev_child *w) |
|
|
606 | CODE: |
|
|
607 | RETVAL = w->status; |
|
|
608 | OUTPUT: |
|
|
609 | RETVAL |
514 | |
610 | |
515 | #if 0 |
611 | #if 0 |
516 | |
612 | |
517 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
613 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
518 | |
614 | |