… | |
… | |
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; |
|
|
406 | evapi.stat_stop = ev_stat_stop; |
|
|
407 | evapi.stat_stat = ev_stat_stat; |
|
|
408 | evapi.clear_pending = ev_clear_pending; |
449 | evapi.unref = ev_unref; |
409 | evapi.invoke = ev_invoke; |
450 | |
410 | |
451 | sv_setiv (sv, (IV)&evapi); |
411 | sv_setiv (sv, (IV)&evapi); |
452 | SvREADONLY_on (sv); |
412 | SvREADONLY_on (sv); |
453 | } |
413 | } |
454 | #ifndef _WIN32 |
414 | #ifndef _WIN32 |
… | |
… | |
462 | |
422 | |
463 | NV ev_time () |
423 | NV ev_time () |
464 | |
424 | |
465 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
425 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
466 | |
426 | |
|
|
427 | unsigned int ev_loop_count () |
|
|
428 | |
467 | void ev_loop (int flags = 0) |
429 | void ev_loop (int flags = 0) |
468 | |
430 | |
469 | void ev_unloop (int how = 1) |
431 | void ev_unloop (int how = 1) |
|
|
432 | |
|
|
433 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
|
|
434 | |
|
|
435 | void ev_feed_signal_event (SV *signal) |
|
|
436 | CODE: |
|
|
437 | { |
|
|
438 | Signal signum = sv_signum (signal); |
|
|
439 | CHECK_SIG (signal, signum); |
|
|
440 | |
|
|
441 | ev_feed_signal_event (EV_DEFAULT_ signum); |
|
|
442 | } |
470 | |
443 | |
471 | ev_io *io (SV *fh, int events, SV *cb) |
444 | ev_io *io (SV *fh, int events, SV *cb) |
472 | ALIAS: |
445 | ALIAS: |
473 | io_ns = 1 |
446 | io_ns = 1 |
474 | CODE: |
447 | CODE: |
… | |
… | |
511 | if (!ix) START (periodic, w); |
484 | if (!ix) START (periodic, w); |
512 | } |
485 | } |
513 | OUTPUT: |
486 | OUTPUT: |
514 | RETVAL |
487 | RETVAL |
515 | |
488 | |
516 | ev_signal *signal (Signal signum, SV *cb) |
489 | ev_signal *signal (SV *signal, SV *cb) |
517 | ALIAS: |
490 | ALIAS: |
518 | signal_ns = 1 |
491 | signal_ns = 1 |
519 | CODE: |
492 | CODE: |
|
|
493 | { |
|
|
494 | Signal signum = sv_signum (signal); |
|
|
495 | CHECK_SIG (signal, signum); |
|
|
496 | |
520 | RETVAL = e_new (sizeof (ev_signal), cb); |
497 | RETVAL = e_new (sizeof (ev_signal), cb); |
521 | ev_signal_set (RETVAL, signum); |
498 | ev_signal_set (RETVAL, signum); |
522 | if (!ix) START (signal, RETVAL); |
499 | if (!ix) START (signal, RETVAL); |
|
|
500 | } |
523 | OUTPUT: |
501 | OUTPUT: |
524 | RETVAL |
502 | RETVAL |
525 | |
503 | |
526 | ev_idle *idle (SV *cb) |
504 | ev_idle *idle (SV *cb) |
527 | ALIAS: |
505 | ALIAS: |
… | |
… | |
558 | child_ns = 1 |
536 | child_ns = 1 |
559 | CODE: |
537 | CODE: |
560 | RETVAL = e_new (sizeof (ev_child), cb); |
538 | RETVAL = e_new (sizeof (ev_child), cb); |
561 | ev_child_set (RETVAL, pid); |
539 | ev_child_set (RETVAL, pid); |
562 | if (!ix) START (child, RETVAL); |
540 | if (!ix) START (child, RETVAL); |
|
|
541 | OUTPUT: |
|
|
542 | RETVAL |
|
|
543 | |
|
|
544 | ev_stat *stat (SV *path, NV interval, SV *cb) |
|
|
545 | ALIAS: |
|
|
546 | stat_ns = 1 |
|
|
547 | CODE: |
|
|
548 | RETVAL = e_new (sizeof (ev_stat), cb); |
|
|
549 | RETVAL->fh = newSVsv (path); |
|
|
550 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
|
|
551 | if (!ix) START (stat, RETVAL); |
563 | OUTPUT: |
552 | OUTPUT: |
564 | RETVAL |
553 | RETVAL |
565 | |
554 | |
566 | void once (SV *fh, int events, SV *timeout, SV *cb) |
555 | void once (SV *fh, int events, SV *timeout, SV *cb) |
567 | CODE: |
556 | CODE: |
… | |
… | |
578 | |
567 | |
579 | int ev_is_active (ev_watcher *w) |
568 | int ev_is_active (ev_watcher *w) |
580 | |
569 | |
581 | int ev_is_pending (ev_watcher *w) |
570 | int ev_is_pending (ev_watcher *w) |
582 | |
571 | |
|
|
572 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
|
|
573 | |
|
|
574 | int ev_clear_pending (ev_watcher *w) |
|
|
575 | |
|
|
576 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
|
|
577 | |
583 | int keepalive (ev_watcher *w, int new_value = 0) |
578 | int keepalive (ev_watcher *w, int new_value = 0) |
584 | CODE: |
579 | CODE: |
585 | { |
580 | { |
586 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
581 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
587 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
582 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
… | |
… | |
609 | |
604 | |
610 | SV *data (ev_watcher *w, SV *new_data = 0) |
605 | SV *data (ev_watcher *w, SV *new_data = 0) |
611 | CODE: |
606 | CODE: |
612 | { |
607 | { |
613 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
608 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
614 | } |
|
|
615 | OUTPUT: |
|
|
616 | RETVAL |
|
|
617 | |
609 | |
618 | void trigger (ev_watcher *w, int revents = EV_NONE) |
610 | if (items > 1) |
619 | CODE: |
611 | { |
620 | w->cb (w, revents); |
612 | SvREFCNT_dec (w->data); |
|
|
613 | w->data = newSVsv (new_data); |
|
|
614 | } |
|
|
615 | } |
|
|
616 | OUTPUT: |
|
|
617 | RETVAL |
621 | |
618 | |
622 | int priority (ev_watcher *w, int new_priority = 0) |
619 | int priority (ev_watcher *w, int new_priority = 0) |
623 | CODE: |
620 | CODE: |
624 | { |
621 | { |
625 | RETVAL = w->priority; |
622 | RETVAL = w->priority; |
626 | |
623 | |
627 | if (items > 1) |
624 | if (items > 1) |
628 | { |
625 | { |
629 | int active = ev_is_active (w); |
626 | int active = ev_is_active (w); |
630 | |
|
|
631 | if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI) |
|
|
632 | croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI); |
|
|
633 | |
627 | |
634 | if (active) |
628 | if (active) |
635 | { |
629 | { |
636 | /* grrr. */ |
630 | /* grrr. */ |
637 | PUSHMARK (SP); |
631 | PUSHMARK (SP); |
638 | XPUSHs (ST (0)); |
632 | XPUSHs (ST (0)); |
|
|
633 | PUTBACK; |
639 | call_method ("stop", G_DISCARD | G_VOID); |
634 | call_method ("stop", G_DISCARD | G_VOID); |
640 | } |
635 | } |
641 | |
636 | |
642 | ev_set_priority (w, new_priority); |
637 | ev_set_priority (w, new_priority); |
643 | |
638 | |
644 | if (active) |
639 | if (active) |
645 | { |
640 | { |
646 | PUSHMARK (SP); |
641 | PUSHMARK (SP); |
647 | XPUSHs (ST (0)); |
642 | XPUSHs (ST (0)); |
|
|
643 | PUTBACK; |
648 | call_method ("start", G_DISCARD | G_VOID); |
644 | call_method ("start", G_DISCARD | G_VOID); |
649 | } |
645 | } |
650 | } |
646 | } |
651 | } |
647 | } |
652 | OUTPUT: |
648 | OUTPUT: |
… | |
… | |
668 | e_destroy (w); |
664 | e_destroy (w); |
669 | |
665 | |
670 | void set (ev_io *w, SV *fh, int events) |
666 | void set (ev_io *w, SV *fh, int events) |
671 | CODE: |
667 | CODE: |
672 | { |
668 | { |
673 | int active = ev_is_active (w); |
|
|
674 | int fd = sv_fileno (fh); |
669 | int fd = sv_fileno (fh); |
675 | CHECK_FD (fh, fd); |
670 | CHECK_FD (fh, fd); |
676 | |
671 | |
677 | if (active) STOP (io, w); |
|
|
678 | |
|
|
679 | sv_setsv (w->fh, fh); |
672 | sv_setsv (w->fh, fh); |
680 | ev_io_set (w, fd, events); |
673 | RESET (io, w, (w, fd, events)); |
681 | |
|
|
682 | if (active) START (io, w); |
|
|
683 | } |
674 | } |
684 | |
675 | |
685 | SV *fh (ev_io *w, SV *new_fh = 0) |
676 | SV *fh (ev_io *w, SV *new_fh = 0) |
686 | CODE: |
677 | CODE: |
687 | { |
678 | { |
688 | RETVAL = newSVsv (w->fh); |
|
|
689 | |
|
|
690 | if (items > 1) |
679 | if (items > 1) |
691 | { |
680 | { |
692 | int active = ev_is_active (w); |
681 | int fd = sv_fileno (new_fh); |
693 | if (active) STOP (io, w); |
682 | CHECK_FD (new_fh, fd); |
694 | |
683 | |
695 | sv_setsv (w->fh, new_fh); |
684 | RETVAL = w->fh; |
696 | ev_io_set (w, sv_fileno (w->fh), w->events); |
685 | w->fh = newSVsv (new_fh); |
697 | |
686 | |
698 | if (active) START (io, w); |
687 | RESET (io, w, (w, fd, w->events)); |
699 | } |
688 | } |
|
|
689 | else |
|
|
690 | RETVAL = newSVsv (w->fh); |
700 | } |
691 | } |
701 | OUTPUT: |
692 | OUTPUT: |
702 | RETVAL |
693 | RETVAL |
703 | |
694 | |
704 | int events (ev_io *w, int new_events = EV_UNDEF) |
695 | int events (ev_io *w, int new_events = EV_UNDEF) |
705 | CODE: |
696 | CODE: |
706 | { |
697 | { |
707 | RETVAL = w->events; |
698 | RETVAL = w->events; |
|
|
699 | |
|
|
700 | if (items > 1) |
|
|
701 | RESET (io, w, (w, w->fd, new_events)); |
|
|
702 | } |
|
|
703 | OUTPUT: |
|
|
704 | RETVAL |
|
|
705 | |
|
|
706 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
|
|
707 | |
|
|
708 | void ev_signal_start (ev_signal *w) |
|
|
709 | CODE: |
|
|
710 | START (signal, w); |
|
|
711 | |
|
|
712 | void ev_signal_stop (ev_signal *w) |
|
|
713 | CODE: |
|
|
714 | STOP (signal, w); |
|
|
715 | |
|
|
716 | void DESTROY (ev_signal *w) |
|
|
717 | CODE: |
|
|
718 | STOP (signal, w); |
|
|
719 | e_destroy (w); |
|
|
720 | |
|
|
721 | void set (ev_signal *w, SV *signal) |
|
|
722 | CODE: |
|
|
723 | { |
|
|
724 | Signal signum = sv_signum (signal); |
|
|
725 | CHECK_SIG (signal, signum); |
|
|
726 | |
|
|
727 | RESET (signal, w, (w, signum)); |
|
|
728 | } |
|
|
729 | |
|
|
730 | int signal (ev_signal *w, SV *new_signal = 0) |
|
|
731 | CODE: |
|
|
732 | { |
|
|
733 | RETVAL = w->signum; |
708 | |
734 | |
709 | if (items > 1) |
735 | if (items > 1) |
710 | { |
736 | { |
711 | int active = ev_is_active (w); |
|
|
712 | if (active) STOP (io, w); |
|
|
713 | |
|
|
714 | ev_io_set (w, w->fd, new_events); |
|
|
715 | |
|
|
716 | if (active) START (io, w); |
|
|
717 | } |
|
|
718 | } |
|
|
719 | OUTPUT: |
|
|
720 | RETVAL |
|
|
721 | |
|
|
722 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
|
|
723 | |
|
|
724 | void ev_signal_start (ev_signal *w) |
|
|
725 | CODE: |
|
|
726 | START (signal, w); |
|
|
727 | |
|
|
728 | void ev_signal_stop (ev_signal *w) |
|
|
729 | CODE: |
|
|
730 | STOP (signal, w); |
|
|
731 | |
|
|
732 | void DESTROY (ev_signal *w) |
|
|
733 | CODE: |
|
|
734 | STOP (signal, w); |
|
|
735 | e_destroy (w); |
|
|
736 | |
|
|
737 | void set (ev_signal *w, SV *signal) |
|
|
738 | CODE: |
|
|
739 | { |
|
|
740 | Signal signum = sv_signum (signal); /* may croak here */ |
|
|
741 | int active = ev_is_active (w); |
|
|
742 | |
|
|
743 | if (active) STOP (signal, w); |
|
|
744 | |
|
|
745 | ev_signal_set (w, signum); |
|
|
746 | |
|
|
747 | if (active) START (signal, w); |
|
|
748 | } |
|
|
749 | |
|
|
750 | int signal (ev_signal *w, SV *new_signal = 0) |
|
|
751 | CODE: |
|
|
752 | { |
|
|
753 | RETVAL = w->signum; |
|
|
754 | |
|
|
755 | if (items > 1) |
|
|
756 | { |
|
|
757 | Signal signum = sv_signum (new_signal); /* may croak here */ |
737 | Signal signum = sv_signum (new_signal); |
758 | int active = ev_is_active (w); |
738 | CHECK_SIG (new_signal, signum); |
759 | if (active) STOP (signal, w); |
|
|
760 | |
739 | |
761 | ev_signal_set (w, signum); |
740 | RESET (signal, w, (w, signum)); |
762 | |
|
|
763 | if (active) START (signal, w); |
|
|
764 | } |
741 | } |
765 | } |
742 | } |
766 | OUTPUT: |
743 | OUTPUT: |
767 | RETVAL |
744 | RETVAL |
768 | |
745 | |
… | |
… | |
793 | |
770 | |
794 | void set (ev_timer *w, NV after, NV repeat = 0.) |
771 | void set (ev_timer *w, NV after, NV repeat = 0.) |
795 | INIT: |
772 | INIT: |
796 | CHECK_REPEAT (repeat); |
773 | CHECK_REPEAT (repeat); |
797 | CODE: |
774 | CODE: |
798 | { |
|
|
799 | int active = ev_is_active (w); |
|
|
800 | if (active) STOP (timer, w); |
|
|
801 | ev_timer_set (w, after, repeat); |
775 | RESET (timer, w, (w, after, repeat)); |
802 | if (active) START (timer, w); |
|
|
803 | } |
|
|
804 | |
776 | |
805 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
777 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
806 | |
778 | |
807 | void ev_periodic_start (ev_periodic *w) |
779 | void ev_periodic_start (ev_periodic *w) |
808 | INIT: |
780 | INIT: |
… | |
… | |
828 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
800 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
829 | INIT: |
801 | INIT: |
830 | CHECK_REPEAT (interval); |
802 | CHECK_REPEAT (interval); |
831 | CODE: |
803 | CODE: |
832 | { |
804 | { |
833 | int active = ev_is_active (w); |
|
|
834 | if (active) STOP (periodic, w); |
|
|
835 | |
|
|
836 | SvREFCNT_dec (w->fh); |
805 | SvREFCNT_dec (w->fh); |
837 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
806 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
807 | |
838 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
808 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
839 | |
|
|
840 | if (active) START (periodic, w); |
|
|
841 | } |
809 | } |
842 | |
810 | |
843 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
811 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
844 | |
812 | |
845 | void ev_idle_start (ev_idle *w) |
813 | void ev_idle_start (ev_idle *w) |
… | |
… | |
900 | STOP (child, w); |
868 | STOP (child, w); |
901 | e_destroy (w); |
869 | e_destroy (w); |
902 | |
870 | |
903 | void set (ev_child *w, int pid) |
871 | void set (ev_child *w, int pid) |
904 | CODE: |
872 | CODE: |
905 | { |
873 | RESET (child, w, (w, pid)); |
906 | int active = ev_is_active (w); |
|
|
907 | if (active) STOP (child, w); |
|
|
908 | |
|
|
909 | ev_child_set (w, pid); |
|
|
910 | |
|
|
911 | if (active) START (child, w); |
|
|
912 | } |
|
|
913 | |
874 | |
914 | int pid (ev_child *w, int new_pid = 0) |
875 | int pid (ev_child *w, int new_pid = 0) |
915 | CODE: |
876 | CODE: |
916 | { |
877 | { |
917 | RETVAL = w->pid; |
878 | RETVAL = w->pid; |
918 | |
879 | |
919 | if (items > 1) |
880 | if (items > 1) |
920 | { |
881 | RESET (child, w, (w, new_pid)); |
921 | int active = ev_is_active (w); |
|
|
922 | if (active) STOP (child, w); |
|
|
923 | |
|
|
924 | ev_child_set (w, new_pid); |
|
|
925 | |
|
|
926 | if (active) START (child, w); |
|
|
927 | } |
|
|
928 | } |
882 | } |
929 | OUTPUT: |
883 | OUTPUT: |
930 | RETVAL |
884 | RETVAL |
931 | |
885 | |
932 | |
886 | |
… | |
… | |
936 | CODE: |
890 | CODE: |
937 | RETVAL = ix ? w->rpid : w->rstatus; |
891 | RETVAL = ix ? w->rpid : w->rstatus; |
938 | OUTPUT: |
892 | OUTPUT: |
939 | RETVAL |
893 | RETVAL |
940 | |
894 | |
941 | #ifndef _WIN32 |
|
|
942 | |
|
|
943 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
895 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
944 | |
896 | |
945 | BOOT: |
897 | void ev_stat_start (ev_stat *w) |
946 | { |
898 | CODE: |
947 | HV *stash = gv_stashpv ("EV::DNS", 1); |
899 | START (stat, w); |
948 | |
900 | |
949 | static const struct { |
901 | void ev_stat_stop (ev_stat *w) |
950 | const char *name; |
902 | CODE: |
951 | IV iv; |
903 | STOP (stat, w); |
952 | } *civ, const_iv[] = { |
|
|
953 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
954 | const_iv (DNS_, ERR_NONE) |
|
|
955 | const_iv (DNS_, ERR_FORMAT) |
|
|
956 | const_iv (DNS_, ERR_SERVERFAILED) |
|
|
957 | const_iv (DNS_, ERR_NOTEXIST) |
|
|
958 | const_iv (DNS_, ERR_NOTIMPL) |
|
|
959 | const_iv (DNS_, ERR_REFUSED) |
|
|
960 | const_iv (DNS_, ERR_TRUNCATED) |
|
|
961 | const_iv (DNS_, ERR_UNKNOWN) |
|
|
962 | const_iv (DNS_, ERR_TIMEOUT) |
|
|
963 | const_iv (DNS_, ERR_SHUTDOWN) |
|
|
964 | const_iv (DNS_, IPv4_A) |
|
|
965 | const_iv (DNS_, PTR) |
|
|
966 | const_iv (DNS_, IPv6_AAAA) |
|
|
967 | const_iv (DNS_, QUERY_NO_SEARCH) |
|
|
968 | const_iv (DNS_, OPTION_SEARCH) |
|
|
969 | const_iv (DNS_, OPTION_NAMESERVERS) |
|
|
970 | const_iv (DNS_, OPTION_MISC) |
|
|
971 | const_iv (DNS_, OPTIONS_ALL) |
|
|
972 | const_iv (DNS_, NO_SEARCH) |
|
|
973 | }; |
|
|
974 | |
904 | |
975 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
905 | void DESTROY (ev_stat *w) |
976 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
906 | CODE: |
977 | } |
907 | STOP (stat, w); |
|
|
908 | e_destroy (w); |
978 | |
909 | |
979 | int evdns_init () |
910 | void set (ev_stat *w, SV *path, NV interval) |
|
|
911 | CODE: |
|
|
912 | { |
|
|
913 | sv_setsv (w->fh, path); |
|
|
914 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval)); |
|
|
915 | } |
980 | |
916 | |
981 | void evdns_shutdown (int fail_requests = 1) |
917 | SV *path (ev_stat *w, SV *new_path = 0) |
|
|
918 | CODE: |
|
|
919 | { |
|
|
920 | RETVAL = SvREFCNT_inc (w->fh); |
982 | |
921 | |
983 | const char *evdns_err_to_string (int err) |
922 | if (items > 1) |
|
|
923 | { |
|
|
924 | SvREFCNT_dec (w->fh); |
|
|
925 | w->fh = newSVsv (new_path); |
|
|
926 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval)); |
|
|
927 | } |
|
|
928 | } |
|
|
929 | OUTPUT: |
|
|
930 | RETVAL |
984 | |
931 | |
985 | int evdns_nameserver_add (U32 address) |
932 | NV interval (ev_stat *w, NV new_interval = 0.) |
|
|
933 | CODE: |
|
|
934 | { |
|
|
935 | RETVAL = w->interval; |
986 | |
936 | |
987 | int evdns_count_nameservers () |
937 | if (items > 1) |
|
|
938 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
|
|
939 | } |
|
|
940 | OUTPUT: |
|
|
941 | RETVAL |
988 | |
942 | |
989 | int evdns_clear_nameservers_and_suspend () |
943 | void prev (ev_stat *w) |
990 | |
|
|
991 | int evdns_resume () |
|
|
992 | |
|
|
993 | int evdns_nameserver_ip_add (char *ip_as_string) |
|
|
994 | |
|
|
995 | int evdns_resolve_ipv4 (const char *name, int flags, SV *cb) |
|
|
996 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
997 | |
|
|
998 | int evdns_resolve_ipv6 (const char *name, int flags, SV *cb) |
|
|
999 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1000 | |
|
|
1001 | int evdns_resolve_reverse (SV *addr, int flags, SV *cb) |
|
|
1002 | ALIAS: |
944 | ALIAS: |
1003 | evdns_resolve_reverse_ipv6 = 1 |
945 | stat = 1 |
1004 | CODE: |
946 | attr = 2 |
|
|
947 | PPCODE: |
1005 | { |
948 | { |
1006 | STRLEN len; |
949 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1007 | char *data = SvPVbyte (addr, len); |
|
|
1008 | if (len != (ix ? 16 : 4)) |
|
|
1009 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
|
|
1010 | |
950 | |
1011 | RETVAL = ix |
951 | if (ix == 1) |
1012 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
952 | ev_stat_stat (w); |
1013 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
953 | else if (!s->st_nlink) |
1014 | } |
954 | errno = ENOENT; |
1015 | OUTPUT: |
|
|
1016 | RETVAL |
|
|
1017 | |
955 | |
1018 | int evdns_set_option (char *option, char *val, int flags) |
956 | PL_statcache.st_dev = s->st_nlink; |
|
|
957 | PL_statcache.st_ino = s->st_ino; |
|
|
958 | PL_statcache.st_mode = s->st_mode; |
|
|
959 | PL_statcache.st_nlink = s->st_nlink; |
|
|
960 | PL_statcache.st_uid = s->st_uid; |
|
|
961 | PL_statcache.st_gid = s->st_gid; |
|
|
962 | PL_statcache.st_rdev = s->st_rdev; |
|
|
963 | PL_statcache.st_size = s->st_size; |
|
|
964 | PL_statcache.st_atime = s->st_atime; |
|
|
965 | PL_statcache.st_mtime = s->st_mtime; |
|
|
966 | PL_statcache.st_ctime = s->st_ctime; |
1019 | |
967 | |
1020 | int evdns_resolv_conf_parse (int flags, const char *filename) |
968 | if (GIMME_V == G_SCALAR) |
1021 | |
969 | XPUSHs (boolSV (s->st_nlink)); |
1022 | #ifdef _WIN32 |
970 | else if (GIMME_V == G_ARRAY && s->st_nlink) |
1023 | |
971 | { |
1024 | int evdns_config_windows_nameservers () |
972 | EXTEND (SP, 13); |
1025 | |
973 | PUSHs (sv_2mortal (newSViv (s->st_dev))); |
1026 | #endif |
974 | PUSHs (sv_2mortal (newSViv (s->st_ino))); |
1027 | |
975 | PUSHs (sv_2mortal (newSVuv (s->st_mode))); |
1028 | void evdns_search_clear () |
976 | PUSHs (sv_2mortal (newSVuv (s->st_nlink))); |
1029 | |
977 | PUSHs (sv_2mortal (newSViv (s->st_uid))); |
1030 | void evdns_search_add (char *domain) |
978 | PUSHs (sv_2mortal (newSViv (s->st_gid))); |
1031 | |
979 | PUSHs (sv_2mortal (newSViv (s->st_rdev))); |
1032 | void evdns_search_ndots_set (int ndots) |
980 | PUSHs (sv_2mortal (newSVnv ((NV)s->st_size))); |
|
|
981 | PUSHs (sv_2mortal (newSVnv (s->st_atime))); |
|
|
982 | PUSHs (sv_2mortal (newSVnv (s->st_mtime))); |
|
|
983 | PUSHs (sv_2mortal (newSVnv (s->st_ctime))); |
|
|
984 | PUSHs (sv_2mortal (newSVuv (4096))); |
|
|
985 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
|
|
986 | } |
|
|
987 | } |
1033 | |
988 | |
1034 | #if 0 |
989 | #if 0 |
1035 | |
990 | |
1036 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
991 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1037 | |
992 | |
… | |
… | |
1071 | |
1026 | |
1072 | #void DESTROY (struct evhttp_request *req); |
1027 | #void DESTROY (struct evhttp_request *req); |
1073 | |
1028 | |
1074 | #endif |
1029 | #endif |
1075 | |
1030 | |
1076 | #endif |
|
|
1077 | |
1031 | |
1078 | |
1032 | |
1079 | |
1033 | |
1080 | |
1034 | |
1081 | |
1035 | |