… | |
… | |
20 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
20 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
21 | #include "libev/ev.c" |
21 | #include "libev/ev.c" |
22 | #include "event.c" |
22 | #include "event.c" |
23 | |
23 | |
24 | #ifndef _WIN32 |
24 | #ifndef _WIN32 |
25 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
|
|
26 | #if !defined (WIN32) && !defined(__CYGWIN__) |
|
|
27 | # define HAVE_STRUCT_IN6_ADDR 1 |
|
|
28 | #endif |
|
|
29 | #undef HAVE_STRTOK_R |
|
|
30 | #undef strtok_r |
|
|
31 | #define strtok_r fake_strtok_r |
|
|
32 | #include "evdns.h" |
|
|
33 | #include "evdns.c" |
|
|
34 | #endif |
|
|
35 | |
|
|
36 | #ifndef _WIN32 |
|
|
37 | # include <pthread.h> |
25 | # include <pthread.h> |
38 | #endif |
26 | #endif |
39 | |
27 | |
40 | #define WFLAG_KEEPALIVE 1 |
28 | #define WFLAG_KEEPALIVE 1 |
41 | |
29 | |
… | |
… | |
58 | #define STOP(type,w) \ |
46 | #define STOP(type,w) \ |
59 | do { \ |
47 | do { \ |
60 | REF (w); \ |
48 | REF (w); \ |
61 | ev_ ## type ## _stop (w); \ |
49 | ev_ ## type ## _stop (w); \ |
62 | } while (0) |
50 | } while (0) |
|
|
51 | |
|
|
52 | #define RESET(type,w,seta) \ |
|
|
53 | do { \ |
|
|
54 | int active = ev_is_active (w); \ |
|
|
55 | if (active) STOP (type, w); \ |
|
|
56 | ev_ ## type ## _set seta; \ |
|
|
57 | if (active) START (type, w); \ |
|
|
58 | } while (0) |
63 | |
59 | |
64 | typedef int Signal; |
60 | typedef int Signal; |
65 | |
61 | |
66 | static struct EVAPI evapi; |
62 | static struct EVAPI evapi; |
67 | |
63 | |
… | |
… | |
69 | *stash_watcher, |
65 | *stash_watcher, |
70 | *stash_io, |
66 | *stash_io, |
71 | *stash_timer, |
67 | *stash_timer, |
72 | *stash_periodic, |
68 | *stash_periodic, |
73 | *stash_signal, |
69 | *stash_signal, |
|
|
70 | *stash_child, |
|
|
71 | *stash_stat, |
74 | *stash_idle, |
72 | *stash_idle, |
75 | *stash_prepare, |
73 | *stash_prepare, |
76 | *stash_check, |
74 | *stash_check, |
77 | *stash_child; |
75 | *stash_embed, |
|
|
76 | *stash_fork; |
78 | |
77 | |
79 | #ifndef SIG_SIZE |
78 | #ifndef SIG_SIZE |
80 | /* kudos to Slaven Rezic for the idea */ |
79 | /* kudos to Slaven Rezic for the idea */ |
81 | static char sig_size [] = { SIG_NUM }; |
80 | static char sig_size [] = { SIG_NUM }; |
82 | # define SIG_SIZE (sizeof (sig_size) + 1) |
81 | # define SIG_SIZE (sizeof (sig_size) + 1) |
83 | #endif |
82 | #endif |
84 | |
83 | |
85 | static int |
84 | static Signal |
86 | sv_signum (SV *sig) |
85 | sv_signum (SV *sig) |
87 | { |
86 | { |
88 | int signum; |
87 | Signal signum; |
89 | |
88 | |
90 | SvGETMAGIC (sig); |
89 | SvGETMAGIC (sig); |
91 | |
90 | |
92 | for (signum = 1; signum < SIG_SIZE; ++signum) |
91 | for (signum = 1; signum < SIG_SIZE; ++signum) |
93 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
92 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
94 | return signum; |
93 | return signum; |
95 | |
94 | |
96 | if (SvIV (sig) > 0) |
95 | signum = SvIV (sig); |
|
|
96 | |
|
|
97 | if (signum > 0 && signum < SIG_SIZE) |
97 | return SvIV (sig); |
98 | return signum; |
98 | |
99 | |
99 | return -1; |
100 | return -1; |
100 | } |
101 | } |
101 | |
102 | |
102 | ///////////////////////////////////////////////////////////////////////////// |
103 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
203 | else |
204 | else |
204 | sv_events_cache = sv_events; |
205 | sv_events_cache = sv_events; |
205 | |
206 | |
206 | if (SvTRUE (ERRSV)) |
207 | if (SvTRUE (ERRSV)) |
207 | { |
208 | { |
|
|
209 | SPAGAIN; |
208 | PUSHMARK (SP); |
210 | PUSHMARK (SP); |
209 | PUTBACK; |
211 | PUTBACK; |
210 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
212 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
211 | } |
213 | } |
212 | |
214 | |
… | |
… | |
242 | else |
244 | else |
243 | sv_events_cache = sv_events; |
245 | sv_events_cache = sv_events; |
244 | |
246 | |
245 | if (SvTRUE (ERRSV)) |
247 | if (SvTRUE (ERRSV)) |
246 | { |
248 | { |
|
|
249 | SPAGAIN; |
247 | PUSHMARK (SP); |
250 | PUSHMARK (SP); |
248 | PUTBACK; |
251 | PUTBACK; |
249 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
252 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
250 | } |
253 | } |
251 | |
254 | |
… | |
… | |
294 | LEAVE; |
297 | LEAVE; |
295 | |
298 | |
296 | return retval; |
299 | return retval; |
297 | } |
300 | } |
298 | |
301 | |
299 | ///////////////////////////////////////////////////////////////////////////// |
|
|
300 | // DNS |
|
|
301 | |
|
|
302 | #ifndef _WIN32 |
|
|
303 | static void |
|
|
304 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
|
|
305 | { |
|
|
306 | dSP; |
|
|
307 | SV *cb = (SV *)arg; |
|
|
308 | |
|
|
309 | ENTER; |
|
|
310 | SAVETMPS; |
|
|
311 | PUSHMARK (SP); |
|
|
312 | EXTEND (SP, count + 3); |
|
|
313 | PUSHs (sv_2mortal (newSViv (result))); |
|
|
314 | |
|
|
315 | if (result == DNS_ERR_NONE && ttl >= 0) |
|
|
316 | { |
|
|
317 | int i; |
|
|
318 | |
|
|
319 | PUSHs (sv_2mortal (newSViv (type))); |
|
|
320 | PUSHs (sv_2mortal (newSViv (ttl))); |
|
|
321 | |
|
|
322 | for (i = 0; i < count; ++i) |
|
|
323 | switch (type) |
|
|
324 | { |
|
|
325 | case DNS_IPv6_AAAA: |
|
|
326 | PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16))); |
|
|
327 | break; |
|
|
328 | case DNS_IPv4_A: |
|
|
329 | PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4))); |
|
|
330 | break; |
|
|
331 | case DNS_PTR: |
|
|
332 | PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0))); |
|
|
333 | break; |
|
|
334 | } |
|
|
335 | } |
|
|
336 | |
|
|
337 | PUTBACK; |
|
|
338 | call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); |
|
|
339 | |
|
|
340 | FREETMPS; |
|
|
341 | |
|
|
342 | if (SvTRUE (ERRSV)) |
|
|
343 | { |
|
|
344 | PUSHMARK (SP); |
|
|
345 | PUTBACK; |
|
|
346 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
347 | } |
|
|
348 | |
|
|
349 | LEAVE; |
|
|
350 | } |
|
|
351 | #endif |
|
|
352 | |
|
|
353 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
302 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
354 | croak (# repeat " value must be >= 0"); |
303 | croak (# repeat " value must be >= 0"); |
355 | |
304 | |
356 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
305 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
357 | croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); |
306 | croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); |
|
|
307 | |
|
|
308 | #define CHECK_SIG(sv,num) if ((num) < 0) \ |
|
|
309 | croak ("illegal signal number or name: %s", SvPV_nolen (sv)); |
358 | |
310 | |
359 | ///////////////////////////////////////////////////////////////////////////// |
311 | ///////////////////////////////////////////////////////////////////////////// |
360 | // XS interface functions |
312 | // XS interface functions |
361 | |
313 | |
362 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
314 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
… | |
… | |
396 | const_iv (EV, BACKEND_KQUEUE) |
348 | const_iv (EV, BACKEND_KQUEUE) |
397 | const_iv (EV, BACKEND_DEVPOLL) |
349 | const_iv (EV, BACKEND_DEVPOLL) |
398 | const_iv (EV, BACKEND_PORT) |
350 | const_iv (EV, BACKEND_PORT) |
399 | const_iv (EV, FLAG_AUTO) |
351 | const_iv (EV, FLAG_AUTO) |
400 | const_iv (EV, FLAG_NOENV) |
352 | const_iv (EV, FLAG_NOENV) |
|
|
353 | const_iv (EV, FLAG_FORKCHECK) |
401 | }; |
354 | }; |
402 | |
355 | |
403 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
356 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
404 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
357 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
405 | |
358 | |
… | |
… | |
410 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
363 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
411 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
364 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
412 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
365 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
413 | stash_check = gv_stashpv ("EV::Check" , 1); |
366 | stash_check = gv_stashpv ("EV::Check" , 1); |
414 | stash_child = gv_stashpv ("EV::Child" , 1); |
367 | stash_child = gv_stashpv ("EV::Child" , 1); |
|
|
368 | stash_embed = gv_stashpv ("EV::Embed" , 1); |
|
|
369 | stash_stat = gv_stashpv ("EV::Stat" , 1); |
415 | |
370 | |
416 | { |
371 | { |
417 | SV *sv = perl_get_sv ("EV::API", TRUE); |
372 | SV *sv = perl_get_sv ("EV::API", TRUE); |
418 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
373 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
419 | |
374 | |
… | |
… | |
423 | evapi.sv_fileno = sv_fileno; |
378 | evapi.sv_fileno = sv_fileno; |
424 | evapi.sv_signum = sv_signum; |
379 | evapi.sv_signum = sv_signum; |
425 | evapi.now = ev_now; |
380 | evapi.now = ev_now; |
426 | evapi.backend = ev_backend; |
381 | evapi.backend = ev_backend; |
427 | evapi.unloop = ev_unloop; |
382 | evapi.unloop = ev_unloop; |
|
|
383 | evapi.ref = ev_ref; |
|
|
384 | evapi.unref = ev_unref; |
428 | evapi.time = ev_time; |
385 | evapi.time = ev_time; |
429 | evapi.loop = ev_loop; |
386 | evapi.loop = ev_loop; |
430 | evapi.once = ev_once; |
387 | evapi.once = ev_once; |
431 | evapi.io_start = ev_io_start; |
388 | evapi.io_start = ev_io_start; |
432 | evapi.io_stop = ev_io_stop; |
389 | evapi.io_stop = ev_io_stop; |
… | |
… | |
443 | evapi.prepare_stop = ev_prepare_stop; |
400 | evapi.prepare_stop = ev_prepare_stop; |
444 | evapi.check_start = ev_check_start; |
401 | evapi.check_start = ev_check_start; |
445 | evapi.check_stop = ev_check_stop; |
402 | evapi.check_stop = ev_check_stop; |
446 | evapi.child_start = ev_child_start; |
403 | evapi.child_start = ev_child_start; |
447 | evapi.child_stop = ev_child_stop; |
404 | evapi.child_stop = ev_child_stop; |
448 | evapi.ref = ev_ref; |
405 | evapi.stat_start = ev_stat_start; |
449 | evapi.unref = ev_unref; |
406 | evapi.stat_stop = ev_stat_stop; |
|
|
407 | evapi.stat_stat = ev_stat_stat; |
|
|
408 | evapi.clear_pending = ev_clear_pending; |
450 | |
409 | |
451 | sv_setiv (sv, (IV)&evapi); |
410 | sv_setiv (sv, (IV)&evapi); |
452 | SvREADONLY_on (sv); |
411 | SvREADONLY_on (sv); |
453 | } |
412 | } |
454 | #ifndef _WIN32 |
413 | #ifndef _WIN32 |
… | |
… | |
462 | |
421 | |
463 | NV ev_time () |
422 | NV ev_time () |
464 | |
423 | |
465 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
424 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
466 | |
425 | |
|
|
426 | unsigned int ev_loop_count () |
|
|
427 | |
467 | void ev_loop (int flags = 0) |
428 | void ev_loop (int flags = 0) |
468 | |
429 | |
469 | void ev_unloop (int how = 1) |
430 | void ev_unloop (int how = 1) |
470 | |
431 | |
471 | ev_io *io (SV *fh, int events, SV *cb) |
432 | ev_io *io (SV *fh, int events, SV *cb) |
… | |
… | |
511 | if (!ix) START (periodic, w); |
472 | if (!ix) START (periodic, w); |
512 | } |
473 | } |
513 | OUTPUT: |
474 | OUTPUT: |
514 | RETVAL |
475 | RETVAL |
515 | |
476 | |
516 | ev_signal *signal (Signal signum, SV *cb) |
477 | ev_signal *signal (SV *signal, SV *cb) |
517 | ALIAS: |
478 | ALIAS: |
518 | signal_ns = 1 |
479 | signal_ns = 1 |
519 | CODE: |
480 | CODE: |
|
|
481 | { |
|
|
482 | Signal signum = sv_signum (signal); |
|
|
483 | CHECK_SIG (signal, signum); |
|
|
484 | |
520 | RETVAL = e_new (sizeof (ev_signal), cb); |
485 | RETVAL = e_new (sizeof (ev_signal), cb); |
521 | ev_signal_set (RETVAL, signum); |
486 | ev_signal_set (RETVAL, signum); |
522 | if (!ix) START (signal, RETVAL); |
487 | if (!ix) START (signal, RETVAL); |
|
|
488 | } |
523 | OUTPUT: |
489 | OUTPUT: |
524 | RETVAL |
490 | RETVAL |
525 | |
491 | |
526 | ev_idle *idle (SV *cb) |
492 | ev_idle *idle (SV *cb) |
527 | ALIAS: |
493 | ALIAS: |
… | |
… | |
558 | child_ns = 1 |
524 | child_ns = 1 |
559 | CODE: |
525 | CODE: |
560 | RETVAL = e_new (sizeof (ev_child), cb); |
526 | RETVAL = e_new (sizeof (ev_child), cb); |
561 | ev_child_set (RETVAL, pid); |
527 | ev_child_set (RETVAL, pid); |
562 | if (!ix) START (child, RETVAL); |
528 | if (!ix) START (child, RETVAL); |
|
|
529 | OUTPUT: |
|
|
530 | RETVAL |
|
|
531 | |
|
|
532 | ev_stat *stat (SV *path, NV interval, SV *cb) |
|
|
533 | ALIAS: |
|
|
534 | stat_ns = 1 |
|
|
535 | CODE: |
|
|
536 | RETVAL = e_new (sizeof (ev_stat), cb); |
|
|
537 | RETVAL->fh = newSVsv (path); |
|
|
538 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
|
|
539 | if (!ix) START (stat, RETVAL); |
563 | OUTPUT: |
540 | OUTPUT: |
564 | RETVAL |
541 | RETVAL |
565 | |
542 | |
566 | void once (SV *fh, int events, SV *timeout, SV *cb) |
543 | void once (SV *fh, int events, SV *timeout, SV *cb) |
567 | CODE: |
544 | CODE: |
… | |
… | |
632 | |
609 | |
633 | if (items > 1) |
610 | if (items > 1) |
634 | { |
611 | { |
635 | int active = ev_is_active (w); |
612 | int active = ev_is_active (w); |
636 | |
613 | |
637 | if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI) |
|
|
638 | croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI); |
|
|
639 | |
|
|
640 | if (active) |
614 | if (active) |
641 | { |
615 | { |
642 | /* grrr. */ |
616 | /* grrr. */ |
643 | PUSHMARK (SP); |
617 | PUSHMARK (SP); |
644 | XPUSHs (ST (0)); |
618 | XPUSHs (ST (0)); |
|
|
619 | PUTBACK; |
645 | call_method ("stop", G_DISCARD | G_VOID); |
620 | call_method ("stop", G_DISCARD | G_VOID); |
646 | } |
621 | } |
647 | |
622 | |
648 | ev_set_priority (w, new_priority); |
623 | ev_set_priority (w, new_priority); |
649 | |
624 | |
650 | if (active) |
625 | if (active) |
651 | { |
626 | { |
652 | PUSHMARK (SP); |
627 | PUSHMARK (SP); |
653 | XPUSHs (ST (0)); |
628 | XPUSHs (ST (0)); |
|
|
629 | PUTBACK; |
654 | call_method ("start", G_DISCARD | G_VOID); |
630 | call_method ("start", G_DISCARD | G_VOID); |
655 | } |
631 | } |
656 | } |
632 | } |
657 | } |
633 | } |
658 | OUTPUT: |
634 | OUTPUT: |
… | |
… | |
674 | e_destroy (w); |
650 | e_destroy (w); |
675 | |
651 | |
676 | void set (ev_io *w, SV *fh, int events) |
652 | void set (ev_io *w, SV *fh, int events) |
677 | CODE: |
653 | CODE: |
678 | { |
654 | { |
679 | int active = ev_is_active (w); |
|
|
680 | int fd = sv_fileno (fh); |
655 | int fd = sv_fileno (fh); |
681 | CHECK_FD (fh, fd); |
656 | CHECK_FD (fh, fd); |
682 | |
657 | |
683 | if (active) STOP (io, w); |
|
|
684 | |
|
|
685 | sv_setsv (w->fh, fh); |
658 | sv_setsv (w->fh, fh); |
686 | ev_io_set (w, fd, events); |
659 | RESET (io, w, (w, fd, events)); |
687 | |
|
|
688 | if (active) START (io, w); |
|
|
689 | } |
660 | } |
690 | |
661 | |
691 | SV *fh (ev_io *w, SV *new_fh = 0) |
662 | SV *fh (ev_io *w, SV *new_fh = 0) |
692 | CODE: |
663 | CODE: |
693 | { |
664 | { |
694 | RETVAL = newSVsv (w->fh); |
|
|
695 | |
|
|
696 | if (items > 1) |
665 | if (items > 1) |
697 | { |
666 | { |
698 | int active = ev_is_active (w); |
667 | int fd = sv_fileno (new_fh); |
699 | if (active) STOP (io, w); |
668 | CHECK_FD (new_fh, fd); |
700 | |
669 | |
701 | sv_setsv (w->fh, new_fh); |
670 | RETVAL = w->fh; |
702 | ev_io_set (w, sv_fileno (w->fh), w->events); |
671 | w->fh = newSVsv (new_fh); |
703 | |
672 | |
704 | if (active) START (io, w); |
673 | RESET (io, w, (w, fd, w->events)); |
705 | } |
674 | } |
|
|
675 | else |
|
|
676 | RETVAL = newSVsv (w->fh); |
706 | } |
677 | } |
707 | OUTPUT: |
678 | OUTPUT: |
708 | RETVAL |
679 | RETVAL |
709 | |
680 | |
710 | int events (ev_io *w, int new_events = EV_UNDEF) |
681 | int events (ev_io *w, int new_events = EV_UNDEF) |
711 | CODE: |
682 | CODE: |
712 | { |
683 | { |
713 | RETVAL = w->events; |
684 | RETVAL = w->events; |
|
|
685 | |
|
|
686 | if (items > 1) |
|
|
687 | RESET (io, w, (w, w->fd, new_events)); |
|
|
688 | } |
|
|
689 | OUTPUT: |
|
|
690 | RETVAL |
|
|
691 | |
|
|
692 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
|
|
693 | |
|
|
694 | void ev_signal_start (ev_signal *w) |
|
|
695 | CODE: |
|
|
696 | START (signal, w); |
|
|
697 | |
|
|
698 | void ev_signal_stop (ev_signal *w) |
|
|
699 | CODE: |
|
|
700 | STOP (signal, w); |
|
|
701 | |
|
|
702 | void DESTROY (ev_signal *w) |
|
|
703 | CODE: |
|
|
704 | STOP (signal, w); |
|
|
705 | e_destroy (w); |
|
|
706 | |
|
|
707 | void set (ev_signal *w, SV *signal) |
|
|
708 | CODE: |
|
|
709 | { |
|
|
710 | Signal signum = sv_signum (signal); |
|
|
711 | CHECK_SIG (signal, signum); |
|
|
712 | |
|
|
713 | RESET (signal, w, (w, signum)); |
|
|
714 | } |
|
|
715 | |
|
|
716 | int signal (ev_signal *w, SV *new_signal = 0) |
|
|
717 | CODE: |
|
|
718 | { |
|
|
719 | RETVAL = w->signum; |
714 | |
720 | |
715 | if (items > 1) |
721 | if (items > 1) |
716 | { |
722 | { |
717 | int active = ev_is_active (w); |
|
|
718 | if (active) STOP (io, w); |
|
|
719 | |
|
|
720 | ev_io_set (w, w->fd, new_events); |
|
|
721 | |
|
|
722 | if (active) START (io, w); |
|
|
723 | } |
|
|
724 | } |
|
|
725 | OUTPUT: |
|
|
726 | RETVAL |
|
|
727 | |
|
|
728 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
|
|
729 | |
|
|
730 | void ev_signal_start (ev_signal *w) |
|
|
731 | CODE: |
|
|
732 | START (signal, w); |
|
|
733 | |
|
|
734 | void ev_signal_stop (ev_signal *w) |
|
|
735 | CODE: |
|
|
736 | STOP (signal, w); |
|
|
737 | |
|
|
738 | void DESTROY (ev_signal *w) |
|
|
739 | CODE: |
|
|
740 | STOP (signal, w); |
|
|
741 | e_destroy (w); |
|
|
742 | |
|
|
743 | void set (ev_signal *w, SV *signal) |
|
|
744 | CODE: |
|
|
745 | { |
|
|
746 | Signal signum = sv_signum (signal); /* may croak here */ |
|
|
747 | int active = ev_is_active (w); |
|
|
748 | |
|
|
749 | if (active) STOP (signal, w); |
|
|
750 | |
|
|
751 | ev_signal_set (w, signum); |
|
|
752 | |
|
|
753 | if (active) START (signal, w); |
|
|
754 | } |
|
|
755 | |
|
|
756 | int signal (ev_signal *w, SV *new_signal = 0) |
|
|
757 | CODE: |
|
|
758 | { |
|
|
759 | RETVAL = w->signum; |
|
|
760 | |
|
|
761 | if (items > 1) |
|
|
762 | { |
|
|
763 | Signal signum = sv_signum (new_signal); /* may croak here */ |
723 | Signal signum = sv_signum (new_signal); |
764 | int active = ev_is_active (w); |
724 | CHECK_SIG (new_signal, signum); |
765 | if (active) STOP (signal, w); |
|
|
766 | |
725 | |
767 | ev_signal_set (w, signum); |
726 | RESET (signal, w, (w, signum)); |
768 | |
|
|
769 | if (active) START (signal, w); |
|
|
770 | } |
727 | } |
771 | } |
728 | } |
772 | OUTPUT: |
729 | OUTPUT: |
773 | RETVAL |
730 | RETVAL |
774 | |
731 | |
… | |
… | |
799 | |
756 | |
800 | void set (ev_timer *w, NV after, NV repeat = 0.) |
757 | void set (ev_timer *w, NV after, NV repeat = 0.) |
801 | INIT: |
758 | INIT: |
802 | CHECK_REPEAT (repeat); |
759 | CHECK_REPEAT (repeat); |
803 | CODE: |
760 | CODE: |
804 | { |
|
|
805 | int active = ev_is_active (w); |
|
|
806 | if (active) STOP (timer, w); |
|
|
807 | ev_timer_set (w, after, repeat); |
761 | RESET (timer, w, (w, after, repeat)); |
808 | if (active) START (timer, w); |
|
|
809 | } |
|
|
810 | |
762 | |
811 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
763 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
812 | |
764 | |
813 | void ev_periodic_start (ev_periodic *w) |
765 | void ev_periodic_start (ev_periodic *w) |
814 | INIT: |
766 | INIT: |
… | |
… | |
834 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
786 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
835 | INIT: |
787 | INIT: |
836 | CHECK_REPEAT (interval); |
788 | CHECK_REPEAT (interval); |
837 | CODE: |
789 | CODE: |
838 | { |
790 | { |
839 | int active = ev_is_active (w); |
|
|
840 | if (active) STOP (periodic, w); |
|
|
841 | |
|
|
842 | SvREFCNT_dec (w->fh); |
791 | SvREFCNT_dec (w->fh); |
843 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
792 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
793 | |
844 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
794 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
845 | |
|
|
846 | if (active) START (periodic, w); |
|
|
847 | } |
795 | } |
848 | |
796 | |
849 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
797 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
850 | |
798 | |
851 | void ev_idle_start (ev_idle *w) |
799 | void ev_idle_start (ev_idle *w) |
… | |
… | |
906 | STOP (child, w); |
854 | STOP (child, w); |
907 | e_destroy (w); |
855 | e_destroy (w); |
908 | |
856 | |
909 | void set (ev_child *w, int pid) |
857 | void set (ev_child *w, int pid) |
910 | CODE: |
858 | CODE: |
911 | { |
859 | RESET (child, w, (w, pid)); |
912 | int active = ev_is_active (w); |
|
|
913 | if (active) STOP (child, w); |
|
|
914 | |
|
|
915 | ev_child_set (w, pid); |
|
|
916 | |
|
|
917 | if (active) START (child, w); |
|
|
918 | } |
|
|
919 | |
860 | |
920 | int pid (ev_child *w, int new_pid = 0) |
861 | int pid (ev_child *w, int new_pid = 0) |
921 | CODE: |
862 | CODE: |
922 | { |
863 | { |
923 | RETVAL = w->pid; |
864 | RETVAL = w->pid; |
924 | |
865 | |
925 | if (items > 1) |
866 | if (items > 1) |
926 | { |
867 | RESET (child, w, (w, new_pid)); |
927 | int active = ev_is_active (w); |
|
|
928 | if (active) STOP (child, w); |
|
|
929 | |
|
|
930 | ev_child_set (w, new_pid); |
|
|
931 | |
|
|
932 | if (active) START (child, w); |
|
|
933 | } |
|
|
934 | } |
868 | } |
935 | OUTPUT: |
869 | OUTPUT: |
936 | RETVAL |
870 | RETVAL |
937 | |
871 | |
938 | |
872 | |
… | |
… | |
942 | CODE: |
876 | CODE: |
943 | RETVAL = ix ? w->rpid : w->rstatus; |
877 | RETVAL = ix ? w->rpid : w->rstatus; |
944 | OUTPUT: |
878 | OUTPUT: |
945 | RETVAL |
879 | RETVAL |
946 | |
880 | |
947 | #ifndef _WIN32 |
|
|
948 | |
|
|
949 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
881 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
950 | |
882 | |
951 | BOOT: |
883 | void ev_stat_start (ev_stat *w) |
952 | { |
884 | CODE: |
953 | HV *stash = gv_stashpv ("EV::DNS", 1); |
885 | START (stat, w); |
954 | |
886 | |
955 | static const struct { |
887 | void ev_stat_stop (ev_stat *w) |
956 | const char *name; |
888 | CODE: |
957 | IV iv; |
889 | STOP (stat, w); |
958 | } *civ, const_iv[] = { |
|
|
959 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
960 | const_iv (DNS_, ERR_NONE) |
|
|
961 | const_iv (DNS_, ERR_FORMAT) |
|
|
962 | const_iv (DNS_, ERR_SERVERFAILED) |
|
|
963 | const_iv (DNS_, ERR_NOTEXIST) |
|
|
964 | const_iv (DNS_, ERR_NOTIMPL) |
|
|
965 | const_iv (DNS_, ERR_REFUSED) |
|
|
966 | const_iv (DNS_, ERR_TRUNCATED) |
|
|
967 | const_iv (DNS_, ERR_UNKNOWN) |
|
|
968 | const_iv (DNS_, ERR_TIMEOUT) |
|
|
969 | const_iv (DNS_, ERR_SHUTDOWN) |
|
|
970 | const_iv (DNS_, IPv4_A) |
|
|
971 | const_iv (DNS_, PTR) |
|
|
972 | const_iv (DNS_, IPv6_AAAA) |
|
|
973 | const_iv (DNS_, QUERY_NO_SEARCH) |
|
|
974 | const_iv (DNS_, OPTION_SEARCH) |
|
|
975 | const_iv (DNS_, OPTION_NAMESERVERS) |
|
|
976 | const_iv (DNS_, OPTION_MISC) |
|
|
977 | const_iv (DNS_, OPTIONS_ALL) |
|
|
978 | const_iv (DNS_, NO_SEARCH) |
|
|
979 | }; |
|
|
980 | |
890 | |
981 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
891 | void DESTROY (ev_stat *w) |
982 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
892 | CODE: |
983 | } |
893 | STOP (stat, w); |
|
|
894 | e_destroy (w); |
984 | |
895 | |
985 | int evdns_init () |
896 | void set (ev_stat *w, SV *path, NV interval) |
|
|
897 | CODE: |
|
|
898 | { |
|
|
899 | sv_setsv (w->fh, path); |
|
|
900 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval)); |
|
|
901 | } |
986 | |
902 | |
987 | void evdns_shutdown (int fail_requests = 1) |
903 | SV *path (ev_stat *w, SV *new_path = 0) |
|
|
904 | CODE: |
|
|
905 | { |
|
|
906 | RETVAL = SvREFCNT_inc (w->fh); |
988 | |
907 | |
989 | const char *evdns_err_to_string (int err) |
908 | if (items > 1) |
|
|
909 | { |
|
|
910 | SvREFCNT_dec (w->fh); |
|
|
911 | w->fh = newSVsv (new_path); |
|
|
912 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval)); |
|
|
913 | } |
|
|
914 | } |
|
|
915 | OUTPUT: |
|
|
916 | RETVAL |
990 | |
917 | |
991 | int evdns_nameserver_add (U32 address) |
918 | NV interval (ev_stat *w, NV new_interval = 0.) |
|
|
919 | CODE: |
|
|
920 | { |
|
|
921 | RETVAL = w->interval; |
992 | |
922 | |
993 | int evdns_count_nameservers () |
923 | if (items > 1) |
|
|
924 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
|
|
925 | } |
|
|
926 | OUTPUT: |
|
|
927 | RETVAL |
994 | |
928 | |
995 | int evdns_clear_nameservers_and_suspend () |
929 | void prev (ev_stat *w) |
996 | |
|
|
997 | int evdns_resume () |
|
|
998 | |
|
|
999 | int evdns_nameserver_ip_add (char *ip_as_string) |
|
|
1000 | |
|
|
1001 | int evdns_resolve_ipv4 (const char *name, int flags, SV *cb) |
|
|
1002 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1003 | |
|
|
1004 | int evdns_resolve_ipv6 (const char *name, int flags, SV *cb) |
|
|
1005 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1006 | |
|
|
1007 | int evdns_resolve_reverse (SV *addr, int flags, SV *cb) |
|
|
1008 | ALIAS: |
930 | ALIAS: |
1009 | evdns_resolve_reverse_ipv6 = 1 |
931 | stat = 1 |
1010 | CODE: |
932 | attr = 2 |
|
|
933 | PPCODE: |
1011 | { |
934 | { |
1012 | STRLEN len; |
935 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1013 | char *data = SvPVbyte (addr, len); |
|
|
1014 | if (len != (ix ? 16 : 4)) |
|
|
1015 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
|
|
1016 | |
936 | |
1017 | RETVAL = ix |
937 | if (ix == 1) |
1018 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
938 | ev_stat_stat (w); |
1019 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
939 | else if (!s->st_nlink) |
1020 | } |
940 | errno = ENOENT; |
1021 | OUTPUT: |
|
|
1022 | RETVAL |
|
|
1023 | |
941 | |
1024 | int evdns_set_option (char *option, char *val, int flags) |
942 | PL_statcache.st_dev = s->st_nlink; |
|
|
943 | PL_statcache.st_ino = s->st_ino; |
|
|
944 | PL_statcache.st_mode = s->st_mode; |
|
|
945 | PL_statcache.st_nlink = s->st_nlink; |
|
|
946 | PL_statcache.st_uid = s->st_uid; |
|
|
947 | PL_statcache.st_gid = s->st_gid; |
|
|
948 | PL_statcache.st_rdev = s->st_rdev; |
|
|
949 | PL_statcache.st_size = s->st_size; |
|
|
950 | PL_statcache.st_atime = s->st_atime; |
|
|
951 | PL_statcache.st_mtime = s->st_mtime; |
|
|
952 | PL_statcache.st_ctime = s->st_ctime; |
1025 | |
953 | |
1026 | int evdns_resolv_conf_parse (int flags, const char *filename) |
954 | if (GIMME_V == G_SCALAR) |
1027 | |
955 | XPUSHs (boolSV (s->st_nlink)); |
1028 | #ifdef _WIN32 |
956 | else if (GIMME_V == G_ARRAY && s->st_nlink) |
1029 | |
957 | { |
1030 | int evdns_config_windows_nameservers () |
958 | EXTEND (SP, 13); |
1031 | |
959 | PUSHs (sv_2mortal (newSViv (s->st_dev))); |
1032 | #endif |
960 | PUSHs (sv_2mortal (newSViv (s->st_ino))); |
1033 | |
961 | PUSHs (sv_2mortal (newSVuv (s->st_mode))); |
1034 | void evdns_search_clear () |
962 | PUSHs (sv_2mortal (newSVuv (s->st_nlink))); |
1035 | |
963 | PUSHs (sv_2mortal (newSViv (s->st_uid))); |
1036 | void evdns_search_add (char *domain) |
964 | PUSHs (sv_2mortal (newSViv (s->st_gid))); |
1037 | |
965 | PUSHs (sv_2mortal (newSViv (s->st_rdev))); |
1038 | void evdns_search_ndots_set (int ndots) |
966 | PUSHs (sv_2mortal (newSVnv ((NV)s->st_size))); |
|
|
967 | PUSHs (sv_2mortal (newSVnv (s->st_atime))); |
|
|
968 | PUSHs (sv_2mortal (newSVnv (s->st_mtime))); |
|
|
969 | PUSHs (sv_2mortal (newSVnv (s->st_ctime))); |
|
|
970 | PUSHs (sv_2mortal (newSVuv (4096))); |
|
|
971 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
|
|
972 | } |
|
|
973 | } |
1039 | |
974 | |
1040 | #if 0 |
975 | #if 0 |
1041 | |
976 | |
1042 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
977 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1043 | |
978 | |
… | |
… | |
1077 | |
1012 | |
1078 | #void DESTROY (struct evhttp_request *req); |
1013 | #void DESTROY (struct evhttp_request *req); |
1079 | |
1014 | |
1080 | #endif |
1015 | #endif |
1081 | |
1016 | |
1082 | #endif |
|
|
1083 | |
1017 | |
1084 | |
1018 | |
1085 | |
1019 | |
1086 | |
1020 | |
1087 | |
1021 | |