ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
(Generate patch)

Comparing EV/EV.xs (file contents):
Revision 1.92 by root, Thu Dec 20 08:18:54 2007 UTC vs.
Revision 1.110 by root, Tue Apr 15 04:41:57 2008 UTC

2#include "perl.h" 2#include "perl.h"
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
8#define EV_H <ev.h>
9#include "EV/EVAPI.h"
10
11/* fix perl api breakage */ 7/* fix perl api breakage */
12#undef signal 8#undef signal
13#undef sigaction 9#undef sigaction
10
11#define EV_PROTOTYPES 1
12#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
13#define EV_H <ev.h>
14#include "EV/EVAPI.h"
14 15
15#define EV_SELECT_IS_WINSOCKET 0 16#define EV_SELECT_IS_WINSOCKET 0
16#ifdef _WIN32 17#ifdef _WIN32
17# define EV_SELECT_USE_FD_SET 0 18# define EV_SELECT_USE_FD_SET 0
18# define NFDBITS PERL_NFDBITS 19# define NFDBITS PERL_NFDBITS
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
60typedef int Signal; 63typedef int Signal;
61 64
65static SV *default_loop_sv;
66
62static struct EVAPI evapi; 67static struct EVAPI evapi;
63 68
64static HV 69static 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,
71 *stash_stat, 77 *stash_stat,
72 *stash_idle, 78 *stash_idle,
73 *stash_prepare, 79 *stash_prepare,
74 *stash_check, 80 *stash_check,
75 *stash_embed, 81 *stash_embed,
76 *stash_fork; 82 *stash_fork,
83 *stash_async;
77 84
78#ifndef SIG_SIZE 85#ifndef SIG_SIZE
79/* kudos to Slaven Rezic for the idea */ 86/* kudos to Slaven Rezic for the idea */
80static char sig_size [] = { SIG_NUM }; 87static char sig_size [] = { SIG_NUM };
81# define SIG_SIZE (sizeof (sig_size) + 1) 88# define SIG_SIZE (sizeof (sig_size) + 1)
121 128
122 return -1; 129 return -1;
123} 130}
124 131
125static void * 132static void *
126e_new (int size, SV *cb_sv) 133e_new (int size, SV *cb_sv, SV *loop)
127{ 134{
128 ev_watcher *w; 135 ev_watcher *w;
129 SV *self = NEWSV (0, size); 136 SV *self = NEWSV (0, size);
130 SvPOK_only (self); 137 SvPOK_only (self);
131 SvCUR_set (self, size); 138 SvCUR_set (self, size);
132 139
133 w = (ev_watcher *)SvPVX (self); 140 w = (ev_watcher *)SvPVX (self);
134 141
135 ev_init (w, e_cb); 142 ev_init (w, e_cb);
136 143
137 w->loop = EV_DEFAULT; 144 w->loop = SvREFCNT_inc (SvRV (loop));
138 w->flags = WFLAG_KEEPALIVE; 145 w->e_flags = WFLAG_KEEPALIVE;
139 w->data = 0; 146 w->data = 0;
140 w->fh = 0; 147 w->fh = 0;
141 w->cb_sv = newSVsv (cb_sv); 148 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv);
142 w->self = self; 149 w->self = self;
143 150
144 return (void *)w; 151 return (void *)w;
145} 152}
146 153
147static void 154static void
148e_destroy (void *w_) 155e_destroy (void *w_)
149{ 156{
150 ev_watcher *w = (ev_watcher *)w_; 157 ev_watcher *w = (ev_watcher *)w_;
151 158
159 SvREFCNT_dec (w->loop ); w->loop = 0;
152 SvREFCNT_dec (w->fh ); w->fh = 0; 160 SvREFCNT_dec (w->fh ); w->fh = 0;
153 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 161 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
154 SvREFCNT_dec (w->data ); w->data = 0; 162 SvREFCNT_dec (w->data ); w->data = 0;
155} 163}
156 164
355 }; 363 };
356 364
357 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 365 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
358 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 366 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
359 367
368 stash_loop = gv_stashpv ("EV::Loop" , 1);
360 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 369 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
361 stash_io = gv_stashpv ("EV::IO" , 1); 370 stash_io = gv_stashpv ("EV::IO" , 1);
362 stash_timer = gv_stashpv ("EV::Timer" , 1); 371 stash_timer = gv_stashpv ("EV::Timer" , 1);
363 stash_periodic = gv_stashpv ("EV::Periodic", 1); 372 stash_periodic = gv_stashpv ("EV::Periodic", 1);
364 stash_signal = gv_stashpv ("EV::Signal" , 1); 373 stash_signal = gv_stashpv ("EV::Signal" , 1);
367 stash_check = gv_stashpv ("EV::Check" , 1); 376 stash_check = gv_stashpv ("EV::Check" , 1);
368 stash_child = gv_stashpv ("EV::Child" , 1); 377 stash_child = gv_stashpv ("EV::Child" , 1);
369 stash_embed = gv_stashpv ("EV::Embed" , 1); 378 stash_embed = gv_stashpv ("EV::Embed" , 1);
370 stash_stat = gv_stashpv ("EV::Stat" , 1); 379 stash_stat = gv_stashpv ("EV::Stat" , 1);
371 stash_fork = gv_stashpv ("EV::Fork" , 1); 380 stash_fork = gv_stashpv ("EV::Fork" , 1);
381 stash_async = gv_stashpv ("EV::Async" , 1);
372 382
373 { 383 {
374 SV *sv = perl_get_sv ("EV::API", TRUE); 384 SV *sv = perl_get_sv ("EV::API", TRUE);
375 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 385 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
376 386
380 evapi.sv_fileno = sv_fileno; 390 evapi.sv_fileno = sv_fileno;
381 evapi.sv_signum = sv_signum; 391 evapi.sv_signum = sv_signum;
382 evapi.supported_backends = ev_supported_backends (); 392 evapi.supported_backends = ev_supported_backends ();
383 evapi.recommended_backends = ev_recommended_backends (); 393 evapi.recommended_backends = ev_recommended_backends ();
384 evapi.embeddable_backends = ev_embeddable_backends (); 394 evapi.embeddable_backends = ev_embeddable_backends ();
385 evapi.time = ev_time; 395 evapi.time_ = ev_time;
396 evapi.sleep_ = ev_sleep;
386 evapi.loop_new = ev_loop_new; 397 evapi.loop_new = ev_loop_new;
387 evapi.loop_destroy = ev_loop_destroy; 398 evapi.loop_destroy = ev_loop_destroy;
388 evapi.loop_fork = ev_loop_fork; 399 evapi.loop_fork = ev_loop_fork;
389 evapi.loop_count = ev_loop_count; 400 evapi.loop_count = ev_loop_count;
390 evapi.now = ev_now; 401 evapi.now = ev_now;
417 evapi.embed_start = ev_embed_start; 428 evapi.embed_start = ev_embed_start;
418 evapi.embed_stop = ev_embed_stop; 429 evapi.embed_stop = ev_embed_stop;
419 evapi.embed_sweep = ev_embed_sweep; 430 evapi.embed_sweep = ev_embed_sweep;
420 evapi.fork_start = ev_fork_start; 431 evapi.fork_start = ev_fork_start;
421 evapi.fork_stop = ev_fork_stop; 432 evapi.fork_stop = ev_fork_stop;
433 evapi.async_start = ev_async_start;
434 evapi.async_stop = ev_async_stop;
435 evapi.async_send = ev_async_send;
422 evapi.clear_pending = ev_clear_pending; 436 evapi.clear_pending = ev_clear_pending;
423 evapi.invoke = ev_invoke; 437 evapi.invoke = ev_invoke;
424 438
425 sv_setiv (sv, (IV)&evapi); 439 sv_setiv (sv, (IV)&evapi);
426 SvREADONLY_on (sv); 440 SvREADONLY_on (sv);
428#ifndef _WIN32 442#ifndef _WIN32
429 pthread_atfork (0, 0, ev_default_fork); 443 pthread_atfork (0, 0, ev_default_fork);
430#endif 444#endif
431} 445}
432 446
433SV *ev_default_loop (unsigned int flags = ev_supported_backends ()) 447SV *ev_default_loop (unsigned int flags = 0)
434 CODE: 448 CODE:
435{ 449{
450 if (!default_loop_sv)
451 {
436 evapi.default_loop = ev_default_loop (flags); 452 evapi.default_loop = ev_default_loop (flags);
453
437 if (!evapi.default_loop) 454 if (!evapi.default_loop)
438 XSRETURN_UNDEF; 455 XSRETURN_UNDEF;
439 456
440 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))), 457 default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
441 gv_stashpv ("EV::Loop::Default", 1)); 458 }
459
460 RETVAL = newSVsv (default_loop_sv);
442} 461}
443 OUTPUT: 462 OUTPUT:
444 RETVAL 463 RETVAL
464
465void ev_default_destroy ()
466 CODE:
467 ev_default_destroy ();
468 SvREFCNT_dec (default_loop_sv);
469 default_loop_sv = 0;
470
471unsigned int ev_supported_backends ()
472
473unsigned int ev_recommended_backends ()
474
475unsigned int ev_embeddable_backends ()
445 476
446NV ev_time () 477NV ev_time ()
447 478
448NV ev_now () 479NV ev_now ()
449 C_ARGS: evapi.default_loop 480 C_ARGS: evapi.default_loop
452 C_ARGS: evapi.default_loop 483 C_ARGS: evapi.default_loop
453 484
454unsigned int ev_loop_count () 485unsigned int ev_loop_count ()
455 C_ARGS: evapi.default_loop 486 C_ARGS: evapi.default_loop
456 487
488void ev_set_io_collect_interval (NV interval)
489 C_ARGS: evapi.default_loop, interval
490
491void ev_set_timeout_collect_interval (NV interval)
492 C_ARGS: evapi.default_loop, interval
493
457void ev_loop (int flags = 0) 494void ev_loop (int flags = 0)
458 C_ARGS: evapi.default_loop, flags 495 C_ARGS: evapi.default_loop, flags
459 496
460void ev_unloop (int how = 1) 497void ev_unloop (int how = EVUNLOOP_ONE)
461 C_ARGS: evapi.default_loop, how 498 C_ARGS: evapi.default_loop, how
462 499
463void ev_feed_fd_event (int fd, int revents = EV_NONE) 500void ev_feed_fd_event (int fd, int revents = EV_NONE)
464 C_ARGS: evapi.default_loop, fd, revents 501 C_ARGS: evapi.default_loop, fd, revents
465 502
478 CODE: 515 CODE:
479{ 516{
480 int fd = sv_fileno (fh); 517 int fd = sv_fileno (fh);
481 CHECK_FD (fh, fd); 518 CHECK_FD (fh, fd);
482 519
483 RETVAL = e_new (sizeof (ev_io), cb); 520 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
484 RETVAL->fh = newSVsv (fh); 521 RETVAL->fh = newSVsv (fh);
485 ev_io_set (RETVAL, fd, events); 522 ev_io_set (RETVAL, fd, events);
486 if (!ix) START (io, RETVAL); 523 if (!ix) START (io, RETVAL);
487} 524}
488 OUTPUT: 525 OUTPUT:
492 ALIAS: 529 ALIAS:
493 timer_ns = 1 530 timer_ns = 1
494 INIT: 531 INIT:
495 CHECK_REPEAT (repeat); 532 CHECK_REPEAT (repeat);
496 CODE: 533 CODE:
497 RETVAL = e_new (sizeof (ev_timer), cb); 534 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
498 ev_timer_set (RETVAL, after, repeat); 535 ev_timer_set (RETVAL, after, repeat);
499 if (!ix) START (timer, RETVAL); 536 if (!ix) START (timer, RETVAL);
500 OUTPUT: 537 OUTPUT:
501 RETVAL 538 RETVAL
502 539
506 INIT: 543 INIT:
507 CHECK_REPEAT (interval); 544 CHECK_REPEAT (interval);
508 CODE: 545 CODE:
509{ 546{
510 ev_periodic *w; 547 ev_periodic *w;
511 w = e_new (sizeof (ev_periodic), cb); 548 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
512 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 549 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
513 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 550 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
514 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 551 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
515 if (!ix) START (periodic, w); 552 if (!ix) START (periodic, w);
516} 553}
523 CODE: 560 CODE:
524{ 561{
525 Signal signum = sv_signum (signal); 562 Signal signum = sv_signum (signal);
526 CHECK_SIG (signal, signum); 563 CHECK_SIG (signal, signum);
527 564
528 RETVAL = e_new (sizeof (ev_signal), cb); 565 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
529 ev_signal_set (RETVAL, signum); 566 ev_signal_set (RETVAL, signum);
530 if (!ix) START (signal, RETVAL); 567 if (!ix) START (signal, RETVAL);
531} 568}
532 OUTPUT: 569 OUTPUT:
533 RETVAL 570 RETVAL
534 571
535ev_idle *idle (SV *cb) 572ev_idle *idle (SV *cb)
536 ALIAS: 573 ALIAS:
537 idle_ns = 1 574 idle_ns = 1
538 CODE: 575 CODE:
539 RETVAL = e_new (sizeof (ev_idle), cb); 576 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
540 ev_idle_set (RETVAL); 577 ev_idle_set (RETVAL);
541 if (!ix) START (idle, RETVAL); 578 if (!ix) START (idle, RETVAL);
542 OUTPUT: 579 OUTPUT:
543 RETVAL 580 RETVAL
544 581
545ev_prepare *prepare (SV *cb) 582ev_prepare *prepare (SV *cb)
546 ALIAS: 583 ALIAS:
547 prepare_ns = 1 584 prepare_ns = 1
548 CODE: 585 CODE:
549 RETVAL = e_new (sizeof (ev_prepare), cb); 586 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
550 ev_prepare_set (RETVAL); 587 ev_prepare_set (RETVAL);
551 if (!ix) START (prepare, RETVAL); 588 if (!ix) START (prepare, RETVAL);
552 OUTPUT: 589 OUTPUT:
553 RETVAL 590 RETVAL
554 591
555ev_check *check (SV *cb) 592ev_check *check (SV *cb)
556 ALIAS: 593 ALIAS:
557 check_ns = 1 594 check_ns = 1
558 CODE: 595 CODE:
559 RETVAL = e_new (sizeof (ev_check), cb); 596 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
560 ev_check_set (RETVAL); 597 ev_check_set (RETVAL);
561 if (!ix) START (check, RETVAL); 598 if (!ix) START (check, RETVAL);
562 OUTPUT: 599 OUTPUT:
563 RETVAL 600 RETVAL
564 601
565ev_fork *fork (SV *cb) 602ev_fork *fork (SV *cb)
566 ALIAS: 603 ALIAS:
567 fork_ns = 1 604 fork_ns = 1
568 CODE: 605 CODE:
569 RETVAL = e_new (sizeof (ev_fork), cb); 606 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
570 ev_fork_set (RETVAL); 607 ev_fork_set (RETVAL);
571 if (!ix) START (fork, RETVAL); 608 if (!ix) START (fork, RETVAL);
572 OUTPUT: 609 OUTPUT:
573 RETVAL 610 RETVAL
574 611
575ev_child *child (int pid, SV *cb) 612ev_child *child (int pid, int trace, SV *cb)
576 ALIAS: 613 ALIAS:
577 child_ns = 1 614 child_ns = 1
578 CODE: 615 CODE:
579 RETVAL = e_new (sizeof (ev_child), cb); 616 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
580 ev_child_set (RETVAL, pid); 617 ev_child_set (RETVAL, pid, trace);
581 if (!ix) START (child, RETVAL); 618 if (!ix) START (child, RETVAL);
582 OUTPUT: 619 OUTPUT:
583 RETVAL 620 RETVAL
584 621
585ev_stat *stat (SV *path, NV interval, SV *cb) 622ev_stat *stat (SV *path, NV interval, SV *cb)
586 ALIAS: 623 ALIAS:
587 stat_ns = 1 624 stat_ns = 1
588 CODE: 625 CODE:
589 RETVAL = e_new (sizeof (ev_stat), cb); 626 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
590 RETVAL->fh = newSVsv (path); 627 RETVAL->fh = newSVsv (path);
591 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 628 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
592 if (!ix) START (stat, RETVAL); 629 if (!ix) START (stat, RETVAL);
630 OUTPUT:
631 RETVAL
632
633ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef)
634 ALIAS:
635 embed_ns = 1
636 CODE:
637{
638 if (!(ev_backend (loop) & ev_embeddable_backends ()))
639 croak ("passed loop is not embeddable via EV::embed,");
640
641 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
642 RETVAL->fh = newSVsv (ST (0));
643 ev_embed_set (RETVAL, loop);
644
645 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
646
647 if (!ix) START (embed, RETVAL);
648}
649 OUTPUT:
650 RETVAL
651
652ev_async *async (SV *cb)
653 ALIAS:
654 async_ns = 1
655 CODE:
656 RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
657 ev_async_set (RETVAL);
658 if (!ix) START (async, RETVAL);
593 OUTPUT: 659 OUTPUT:
594 RETVAL 660 RETVAL
595 661
596void once (SV *fh, int events, SV *timeout, SV *cb) 662void once (SV *fh, int events, SV *timeout, SV *cb)
597 CODE: 663 CODE:
610int ev_is_active (ev_watcher *w) 676int ev_is_active (ev_watcher *w)
611 677
612int ev_is_pending (ev_watcher *w) 678int ev_is_pending (ev_watcher *w)
613 679
614void ev_invoke (ev_watcher *w, int revents = EV_NONE) 680void ev_invoke (ev_watcher *w, int revents = EV_NONE)
615 C_ARGS: w->loop, w, revents 681 C_ARGS: e_loop (w), w, revents
616 682
617int ev_clear_pending (ev_watcher *w) 683int ev_clear_pending (ev_watcher *w)
618 C_ARGS: w->loop, w 684 C_ARGS: e_loop (w), w
619 685
620void ev_feed_event (ev_watcher *w, int revents = EV_NONE) 686void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
621 C_ARGS: w->loop, w, revents 687 C_ARGS: e_loop (w), w, revents
622 688
623int keepalive (ev_watcher *w, int new_value = 0) 689int keepalive (ev_watcher *w, int new_value = 0)
624 CODE: 690 CODE:
625{ 691{
626 RETVAL = w->flags & WFLAG_KEEPALIVE; 692 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
627 new_value = new_value ? WFLAG_KEEPALIVE : 0; 693 new_value = new_value ? WFLAG_KEEPALIVE : 0;
628 694
629 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 695 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
630 { 696 {
631 REF (w); 697 REF (w);
632 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 698 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
633 UNREF (w); 699 UNREF (w);
634 } 700 }
635} 701}
636 OUTPUT: 702 OUTPUT:
637 RETVAL 703 RETVAL
656 { 722 {
657 SvREFCNT_dec (w->data); 723 SvREFCNT_dec (w->data);
658 w->data = newSVsv (new_data); 724 w->data = newSVsv (new_data);
659 } 725 }
660} 726}
727 OUTPUT:
728 RETVAL
729
730SV *loop (ev_watcher *w)
731 CODE:
732 RETVAL = newRV_inc (w->loop);
661 OUTPUT: 733 OUTPUT:
662 RETVAL 734 RETVAL
663 735
664int priority (ev_watcher *w, int new_priority = 0) 736int priority (ev_watcher *w, int new_priority = 0)
665 CODE: 737 CODE:
803void ev_timer_again (ev_timer *w) 875void ev_timer_again (ev_timer *w)
804 INIT: 876 INIT:
805 CHECK_REPEAT (w->repeat); 877 CHECK_REPEAT (w->repeat);
806 CODE: 878 CODE:
807 REF (w); 879 REF (w);
808 ev_timer_again (w->loop, w); 880 ev_timer_again (e_loop (w), w);
809 UNREF (w); 881 UNREF (w);
810 882
811void DESTROY (ev_timer *w) 883void DESTROY (ev_timer *w)
812 CODE: 884 CODE:
813 STOP (timer, w); 885 STOP (timer, w);
838 STOP (periodic, w); 910 STOP (periodic, w);
839 911
840void ev_periodic_again (ev_periodic *w) 912void ev_periodic_again (ev_periodic *w)
841 CODE: 913 CODE:
842 REF (w); 914 REF (w);
843 ev_periodic_again (w->loop, w); 915 ev_periodic_again (e_loop (w), w);
844 UNREF (w); 916 UNREF (w);
845 917
846void DESTROY (ev_periodic *w) 918void DESTROY (ev_periodic *w)
847 CODE: 919 CODE:
848 STOP (periodic, w); 920 STOP (periodic, w);
878void DESTROY (ev_idle *w) 950void DESTROY (ev_idle *w)
879 CODE: 951 CODE:
880 STOP (idle, w); 952 STOP (idle, w);
881 e_destroy (w); 953 e_destroy (w);
882 954
883MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 955MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
884 956
885void ev_prepare_start (ev_prepare *w) 957void ev_prepare_start (ev_prepare *w)
886 CODE: 958 CODE:
887 START (prepare, w); 959 START (prepare, w);
888 960
938void DESTROY (ev_child *w) 1010void DESTROY (ev_child *w)
939 CODE: 1011 CODE:
940 STOP (child, w); 1012 STOP (child, w);
941 e_destroy (w); 1013 e_destroy (w);
942 1014
943void set (ev_child *w, int pid) 1015void set (ev_child *w, int pid, int trace)
944 CODE: 1016 CODE:
945 RESET (child, w, (w, pid)); 1017 RESET (child, w, (w, pid, trace));
946 1018
947int 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
959int rstatus (ev_child *w) 1019int pid (ev_child *w)
960 ALIAS: 1020 ALIAS:
961 rpid = 1 1021 rpid = 1
1022 rstatus = 2
962 CODE: 1023 CODE:
963 RETVAL = ix ? w->rpid : w->rstatus; 1024 RETVAL = ix == 0 ? w->pid
1025 : ix == 1 ? w->rpid
1026 : w->rstatus;
964 OUTPUT: 1027 OUTPUT:
965 RETVAL 1028 RETVAL
966 1029
967MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1030MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
968 1031
1019 PPCODE: 1082 PPCODE:
1020{ 1083{
1021 ev_statdata *s = ix ? &w->attr : &w->prev; 1084 ev_statdata *s = ix ? &w->attr : &w->prev;
1022 1085
1023 if (ix == 1) 1086 if (ix == 1)
1024 ev_stat_stat (w->loop, w); 1087 ev_stat_stat (e_loop (w), w);
1025 else if (!s->st_nlink) 1088 else if (!s->st_nlink)
1026 errno = ENOENT; 1089 errno = ENOENT;
1027 1090
1028 PL_statcache.st_dev = s->st_nlink; 1091 PL_statcache.st_dev = s->st_nlink;
1029 PL_statcache.st_ino = s->st_ino; 1092 PL_statcache.st_ino = s->st_ino;
1056 PUSHs (sv_2mortal (newSVuv (4096))); 1119 PUSHs (sv_2mortal (newSVuv (4096)));
1057 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 1120 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1058 } 1121 }
1059} 1122}
1060 1123
1124MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1125
1126void ev_embed_start (ev_embed *w)
1127 CODE:
1128 START (embed, w);
1129
1130void ev_embed_stop (ev_embed *w)
1131 CODE:
1132 STOP (embed, w);
1133
1134void DESTROY (ev_embed *w)
1135 CODE:
1136 STOP (embed, w);
1137 e_destroy (w);
1138
1139void set (ev_embed *w, struct ev_loop *loop)
1140 CODE:
1141{
1142 sv_setsv (w->fh, ST (1));
1143 RESET (embed, w, (w, loop));
1144}
1145
1146SV *other (ev_embed *w)
1147 CODE:
1148 RETVAL = newSVsv (w->fh);
1149 OUTPUT:
1150 RETVAL
1151
1152void ev_embed_sweep (ev_embed *w)
1153 C_ARGS: e_loop (w), w
1154
1155MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1156
1157void ev_async_start (ev_async *w)
1158 CODE:
1159 START (async, w);
1160
1161void ev_async_stop (ev_async *w)
1162 CODE:
1163 STOP (async, w);
1164
1165void DESTROY (ev_async *w)
1166 CODE:
1167 STOP (async, w);
1168 e_destroy (w);
1169
1170void ev_async_send (ev_async *w)
1171 C_ARGS: e_loop (w), w
1172
1173SV *ev_async_async_pending (ev_async *w)
1174 CODE:
1175 RETVAL = boolSV (ev_async_pending (w));
1176 OUTPUT:
1177 RETVAL
1178
1179MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1180
1181SV *new (SV *klass, unsigned int flags = 0)
1182 CODE:
1183{
1184 struct ev_loop *loop = ev_loop_new (flags);
1185
1186 if (!loop)
1187 XSRETURN_UNDEF;
1188
1189 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1190}
1191 OUTPUT:
1192 RETVAL
1193
1194void DESTROY (struct ev_loop *loop)
1195 CODE:
1196 if (loop != evapi.default_loop) /* global destruction sucks */
1197 ev_loop_destroy (loop);
1198
1199void ev_loop_fork (struct ev_loop *loop)
1200
1201NV ev_now (struct ev_loop *loop)
1202
1203void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1204
1205void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1206
1207unsigned int ev_backend (struct ev_loop *loop)
1208
1209unsigned int ev_loop_count (struct ev_loop *loop)
1210
1211void ev_loop (struct ev_loop *loop, int flags = 0)
1212
1213void ev_unloop (struct ev_loop *loop, int how = 1)
1214
1215void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1216
1061#if 0 1217#if 0
1062 1218
1063MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1219void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1064 1220 CODE:
1065BOOT:
1066{ 1221{
1067 HV *stash = gv_stashpv ("EV::HTTP", 1); 1222 Signal signum = sv_signum (signal);
1223 CHECK_SIG (signal, signum);
1068 1224
1069 static const struct { 1225 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} 1226}
1094
1095MODULE = 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 1227
1101#endif 1228#endif
1102 1229
1230ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1231 ALIAS:
1232 io_ns = 1
1233 CODE:
1234{
1235 int fd = sv_fileno (fh);
1236 CHECK_FD (fh, fd);
1103 1237
1238 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1239 RETVAL->fh = newSVsv (fh);
1240 ev_io_set (RETVAL, fd, events);
1241 if (!ix) START (io, RETVAL);
1242}
1243 OUTPUT:
1244 RETVAL
1104 1245
1246ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1247 ALIAS:
1248 timer_ns = 1
1249 INIT:
1250 CHECK_REPEAT (repeat);
1251 CODE:
1252 RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1253 ev_timer_set (RETVAL, after, repeat);
1254 if (!ix) START (timer, RETVAL);
1255 OUTPUT:
1256 RETVAL
1105 1257
1258SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1259 ALIAS:
1260 periodic_ns = 1
1261 INIT:
1262 CHECK_REPEAT (interval);
1263 CODE:
1264{
1265 ev_periodic *w;
1266 w = e_new (sizeof (ev_periodic), cb, ST (0));
1267 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1268 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
1269 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1270 if (!ix) START (periodic, w);
1271}
1272 OUTPUT:
1273 RETVAL
1106 1274
1275#if 0
1107 1276
1277ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1278 ALIAS:
1279 signal_ns = 1
1280 CODE:
1281{
1282 Signal signum = sv_signum (signal);
1283 CHECK_SIG (signal, signum);
1108 1284
1285 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1286 ev_signal_set (RETVAL, signum);
1287 if (!ix) START (signal, RETVAL);
1288}
1289 OUTPUT:
1290 RETVAL
1109 1291
1292#endif
1293
1294ev_idle *idle (struct ev_loop *loop, SV *cb)
1295 ALIAS:
1296 idle_ns = 1
1297 CODE:
1298 RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1299 ev_idle_set (RETVAL);
1300 if (!ix) START (idle, RETVAL);
1301 OUTPUT:
1302 RETVAL
1303
1304ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1305 ALIAS:
1306 prepare_ns = 1
1307 CODE:
1308 RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1309 ev_prepare_set (RETVAL);
1310 if (!ix) START (prepare, RETVAL);
1311 OUTPUT:
1312 RETVAL
1313
1314ev_check *check (struct ev_loop *loop, SV *cb)
1315 ALIAS:
1316 check_ns = 1
1317 CODE:
1318 RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1319 ev_check_set (RETVAL);
1320 if (!ix) START (check, RETVAL);
1321 OUTPUT:
1322 RETVAL
1323
1324ev_fork *fork (struct ev_loop *loop, SV *cb)
1325 ALIAS:
1326 fork_ns = 1
1327 CODE:
1328 RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1329 ev_fork_set (RETVAL);
1330 if (!ix) START (fork, RETVAL);
1331 OUTPUT:
1332 RETVAL
1333
1334ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1335 ALIAS:
1336 child_ns = 1
1337 CODE:
1338 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1339 ev_child_set (RETVAL, pid, trace);
1340 if (!ix) START (child, RETVAL);
1341 OUTPUT:
1342 RETVAL
1343
1344ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1345 ALIAS:
1346 stat_ns = 1
1347 CODE:
1348 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1349 RETVAL->fh = newSVsv (path);
1350 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1351 if (!ix) START (stat, RETVAL);
1352 OUTPUT:
1353 RETVAL
1354
1355ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef)
1356 ALIAS:
1357 embed_ns = 1
1358 CODE:
1359{
1360 if (!(ev_backend (other) & ev_embeddable_backends ()))
1361 croak ("passed loop is not embeddable via EV::embed,");
1362
1363 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1364 RETVAL->fh = newSVsv (ST (1));
1365 ev_embed_set (RETVAL, other);
1366
1367 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1368
1369 if (!ix) START (embed, RETVAL);
1370}
1371 OUTPUT:
1372 RETVAL
1373
1374ev_async *async (struct ev_loop *loop, SV *cb)
1375 ALIAS:
1376 async_ns = 1
1377 CODE:
1378 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1379 ev_async_set (RETVAL);
1380 if (!ix) START (async, RETVAL);
1381 OUTPUT:
1382 RETVAL
1383
1384void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1385 CODE:
1386 ev_once (
1387 loop,
1388 sv_fileno (fh), events,
1389 SvOK (timeout) ? SvNV (timeout) : -1.,
1390 e_once_cb,
1391 newSVsv (cb)
1392 );
1393

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines