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.104 by root, Fri Jan 25 15:45:08 2008 UTC

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 7#define EV_PROTOTYPES 1
8#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
8#define EV_H <ev.h> 9#define EV_H <ev.h>
9#include "EV/EVAPI.h" 10#include "EV/EVAPI.h"
10 11
11/* fix perl api breakage */ 12/* fix perl api breakage */
12#undef signal 13#undef signal
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,
121 127
122 return -1; 128 return -1;
123} 129}
124 130
125static void * 131static void *
126e_new (int size, SV *cb_sv) 132e_new (int size, SV *cb_sv, SV *loop)
127{ 133{
128 ev_watcher *w; 134 ev_watcher *w;
129 SV *self = NEWSV (0, size); 135 SV *self = NEWSV (0, size);
130 SvPOK_only (self); 136 SvPOK_only (self);
131 SvCUR_set (self, size); 137 SvCUR_set (self, size);
132 138
133 w = (ev_watcher *)SvPVX (self); 139 w = (ev_watcher *)SvPVX (self);
134 140
135 ev_init (w, e_cb); 141 ev_init (w, e_cb);
136 142
137 w->loop = EV_DEFAULT; 143 w->loop = SvREFCNT_inc (SvRV (loop));
138 w->flags = WFLAG_KEEPALIVE; 144 w->e_flags = WFLAG_KEEPALIVE;
139 w->data = 0; 145 w->data = 0;
140 w->fh = 0; 146 w->fh = 0;
141 w->cb_sv = newSVsv (cb_sv); 147 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv);
142 w->self = self; 148 w->self = self;
143 149
144 return (void *)w; 150 return (void *)w;
145} 151}
146 152
147static void 153static void
148e_destroy (void *w_) 154e_destroy (void *w_)
149{ 155{
150 ev_watcher *w = (ev_watcher *)w_; 156 ev_watcher *w = (ev_watcher *)w_;
151 157
158 SvREFCNT_dec (w->loop ); w->loop = 0;
152 SvREFCNT_dec (w->fh ); w->fh = 0; 159 SvREFCNT_dec (w->fh ); w->fh = 0;
153 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 160 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
154 SvREFCNT_dec (w->data ); w->data = 0; 161 SvREFCNT_dec (w->data ); w->data = 0;
155} 162}
156 163
355 }; 362 };
356 363
357 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 364 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
358 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 365 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
359 366
367 stash_loop = gv_stashpv ("EV::Loop" , 1);
360 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 368 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
361 stash_io = gv_stashpv ("EV::IO" , 1); 369 stash_io = gv_stashpv ("EV::IO" , 1);
362 stash_timer = gv_stashpv ("EV::Timer" , 1); 370 stash_timer = gv_stashpv ("EV::Timer" , 1);
363 stash_periodic = gv_stashpv ("EV::Periodic", 1); 371 stash_periodic = gv_stashpv ("EV::Periodic", 1);
364 stash_signal = gv_stashpv ("EV::Signal" , 1); 372 stash_signal = gv_stashpv ("EV::Signal" , 1);
381 evapi.sv_signum = sv_signum; 389 evapi.sv_signum = sv_signum;
382 evapi.supported_backends = ev_supported_backends (); 390 evapi.supported_backends = ev_supported_backends ();
383 evapi.recommended_backends = ev_recommended_backends (); 391 evapi.recommended_backends = ev_recommended_backends ();
384 evapi.embeddable_backends = ev_embeddable_backends (); 392 evapi.embeddable_backends = ev_embeddable_backends ();
385 evapi.time = ev_time; 393 evapi.time = ev_time;
394 evapi.sleep = ev_sleep;
386 evapi.loop_new = ev_loop_new; 395 evapi.loop_new = ev_loop_new;
387 evapi.loop_destroy = ev_loop_destroy; 396 evapi.loop_destroy = ev_loop_destroy;
388 evapi.loop_fork = ev_loop_fork; 397 evapi.loop_fork = ev_loop_fork;
389 evapi.loop_count = ev_loop_count; 398 evapi.loop_count = ev_loop_count;
390 evapi.now = ev_now; 399 evapi.now = ev_now;
428#ifndef _WIN32 437#ifndef _WIN32
429 pthread_atfork (0, 0, ev_default_fork); 438 pthread_atfork (0, 0, ev_default_fork);
430#endif 439#endif
431} 440}
432 441
433SV *ev_default_loop (unsigned int flags = ev_supported_backends ()) 442SV *ev_default_loop (unsigned int flags = 0)
434 CODE: 443 CODE:
435{ 444{
445 if (!default_loop_sv)
446 {
436 evapi.default_loop = ev_default_loop (flags); 447 evapi.default_loop = ev_default_loop (flags);
448
437 if (!evapi.default_loop) 449 if (!evapi.default_loop)
438 XSRETURN_UNDEF; 450 XSRETURN_UNDEF;
439 451
440 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))), 452 default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
441 gv_stashpv ("EV::Loop::Default", 1)); 453 }
454
455 RETVAL = newSVsv (default_loop_sv);
442} 456}
443 OUTPUT: 457 OUTPUT:
444 RETVAL 458 RETVAL
459
460void ev_default_destroy ()
461 CODE:
462 ev_default_destroy ();
463 SvREFCNT_dec (default_loop_sv);
464 default_loop_sv = 0;
465
466unsigned int ev_supported_backends ()
467
468unsigned int ev_recommended_backends ()
469
470unsigned int ev_embeddable_backends ()
445 471
446NV ev_time () 472NV ev_time ()
447 473
448NV ev_now () 474NV ev_now ()
449 C_ARGS: evapi.default_loop 475 C_ARGS: evapi.default_loop
452 C_ARGS: evapi.default_loop 478 C_ARGS: evapi.default_loop
453 479
454unsigned int ev_loop_count () 480unsigned int ev_loop_count ()
455 C_ARGS: evapi.default_loop 481 C_ARGS: evapi.default_loop
456 482
483void ev_set_io_collect_interval (NV interval)
484 C_ARGS: evapi.default_loop, interval
485
486void ev_set_timeout_collect_interval (NV interval)
487 C_ARGS: evapi.default_loop, interval
488
457void ev_loop (int flags = 0) 489void ev_loop (int flags = 0)
458 C_ARGS: evapi.default_loop, flags 490 C_ARGS: evapi.default_loop, flags
459 491
460void ev_unloop (int how = 1) 492void ev_unloop (int how = EVUNLOOP_ONE)
461 C_ARGS: evapi.default_loop, how 493 C_ARGS: evapi.default_loop, how
462 494
463void ev_feed_fd_event (int fd, int revents = EV_NONE) 495void ev_feed_fd_event (int fd, int revents = EV_NONE)
464 C_ARGS: evapi.default_loop, fd, revents 496 C_ARGS: evapi.default_loop, fd, revents
465 497
478 CODE: 510 CODE:
479{ 511{
480 int fd = sv_fileno (fh); 512 int fd = sv_fileno (fh);
481 CHECK_FD (fh, fd); 513 CHECK_FD (fh, fd);
482 514
483 RETVAL = e_new (sizeof (ev_io), cb); 515 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
484 RETVAL->fh = newSVsv (fh); 516 RETVAL->fh = newSVsv (fh);
485 ev_io_set (RETVAL, fd, events); 517 ev_io_set (RETVAL, fd, events);
486 if (!ix) START (io, RETVAL); 518 if (!ix) START (io, RETVAL);
487} 519}
488 OUTPUT: 520 OUTPUT:
492 ALIAS: 524 ALIAS:
493 timer_ns = 1 525 timer_ns = 1
494 INIT: 526 INIT:
495 CHECK_REPEAT (repeat); 527 CHECK_REPEAT (repeat);
496 CODE: 528 CODE:
497 RETVAL = e_new (sizeof (ev_timer), cb); 529 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
498 ev_timer_set (RETVAL, after, repeat); 530 ev_timer_set (RETVAL, after, repeat);
499 if (!ix) START (timer, RETVAL); 531 if (!ix) START (timer, RETVAL);
500 OUTPUT: 532 OUTPUT:
501 RETVAL 533 RETVAL
502 534
506 INIT: 538 INIT:
507 CHECK_REPEAT (interval); 539 CHECK_REPEAT (interval);
508 CODE: 540 CODE:
509{ 541{
510 ev_periodic *w; 542 ev_periodic *w;
511 w = e_new (sizeof (ev_periodic), cb); 543 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
512 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 544 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
513 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 545 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
514 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 546 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
515 if (!ix) START (periodic, w); 547 if (!ix) START (periodic, w);
516} 548}
523 CODE: 555 CODE:
524{ 556{
525 Signal signum = sv_signum (signal); 557 Signal signum = sv_signum (signal);
526 CHECK_SIG (signal, signum); 558 CHECK_SIG (signal, signum);
527 559
528 RETVAL = e_new (sizeof (ev_signal), cb); 560 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
529 ev_signal_set (RETVAL, signum); 561 ev_signal_set (RETVAL, signum);
530 if (!ix) START (signal, RETVAL); 562 if (!ix) START (signal, RETVAL);
531} 563}
532 OUTPUT: 564 OUTPUT:
533 RETVAL 565 RETVAL
534 566
535ev_idle *idle (SV *cb) 567ev_idle *idle (SV *cb)
536 ALIAS: 568 ALIAS:
537 idle_ns = 1 569 idle_ns = 1
538 CODE: 570 CODE:
539 RETVAL = e_new (sizeof (ev_idle), cb); 571 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
540 ev_idle_set (RETVAL); 572 ev_idle_set (RETVAL);
541 if (!ix) START (idle, RETVAL); 573 if (!ix) START (idle, RETVAL);
542 OUTPUT: 574 OUTPUT:
543 RETVAL 575 RETVAL
544 576
545ev_prepare *prepare (SV *cb) 577ev_prepare *prepare (SV *cb)
546 ALIAS: 578 ALIAS:
547 prepare_ns = 1 579 prepare_ns = 1
548 CODE: 580 CODE:
549 RETVAL = e_new (sizeof (ev_prepare), cb); 581 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
550 ev_prepare_set (RETVAL); 582 ev_prepare_set (RETVAL);
551 if (!ix) START (prepare, RETVAL); 583 if (!ix) START (prepare, RETVAL);
552 OUTPUT: 584 OUTPUT:
553 RETVAL 585 RETVAL
554 586
555ev_check *check (SV *cb) 587ev_check *check (SV *cb)
556 ALIAS: 588 ALIAS:
557 check_ns = 1 589 check_ns = 1
558 CODE: 590 CODE:
559 RETVAL = e_new (sizeof (ev_check), cb); 591 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
560 ev_check_set (RETVAL); 592 ev_check_set (RETVAL);
561 if (!ix) START (check, RETVAL); 593 if (!ix) START (check, RETVAL);
562 OUTPUT: 594 OUTPUT:
563 RETVAL 595 RETVAL
564 596
565ev_fork *fork (SV *cb) 597ev_fork *fork (SV *cb)
566 ALIAS: 598 ALIAS:
567 fork_ns = 1 599 fork_ns = 1
568 CODE: 600 CODE:
569 RETVAL = e_new (sizeof (ev_fork), cb); 601 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
570 ev_fork_set (RETVAL); 602 ev_fork_set (RETVAL);
571 if (!ix) START (fork, RETVAL); 603 if (!ix) START (fork, RETVAL);
572 OUTPUT: 604 OUTPUT:
573 RETVAL 605 RETVAL
574 606
575ev_child *child (int pid, SV *cb) 607ev_child *child (int pid, int trace, SV *cb)
576 ALIAS: 608 ALIAS:
577 child_ns = 1 609 child_ns = 1
578 CODE: 610 CODE:
579 RETVAL = e_new (sizeof (ev_child), cb); 611 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
580 ev_child_set (RETVAL, pid); 612 ev_child_set (RETVAL, pid, trace);
581 if (!ix) START (child, RETVAL); 613 if (!ix) START (child, RETVAL);
582 OUTPUT: 614 OUTPUT:
583 RETVAL 615 RETVAL
584 616
585ev_stat *stat (SV *path, NV interval, SV *cb) 617ev_stat *stat (SV *path, NV interval, SV *cb)
586 ALIAS: 618 ALIAS:
587 stat_ns = 1 619 stat_ns = 1
588 CODE: 620 CODE:
589 RETVAL = e_new (sizeof (ev_stat), cb); 621 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
590 RETVAL->fh = newSVsv (path); 622 RETVAL->fh = newSVsv (path);
591 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 623 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
592 if (!ix) START (stat, RETVAL); 624 if (!ix) START (stat, RETVAL);
625 OUTPUT:
626 RETVAL
627
628ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef)
629 ALIAS:
630 embed_ns = 1
631 CODE:
632{
633 if (!(ev_backend (loop) & ev_embeddable_backends ()))
634 croak ("passed loop is not embeddable via EV::embed,");
635
636 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
637 RETVAL->fh = newSVsv (ST (0));
638 ev_embed_set (RETVAL, loop);
639
640 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
641
642 if (!ix) START (embed, RETVAL);
643}
593 OUTPUT: 644 OUTPUT:
594 RETVAL 645 RETVAL
595 646
596void once (SV *fh, int events, SV *timeout, SV *cb) 647void once (SV *fh, int events, SV *timeout, SV *cb)
597 CODE: 648 CODE:
610int ev_is_active (ev_watcher *w) 661int ev_is_active (ev_watcher *w)
611 662
612int ev_is_pending (ev_watcher *w) 663int ev_is_pending (ev_watcher *w)
613 664
614void ev_invoke (ev_watcher *w, int revents = EV_NONE) 665void ev_invoke (ev_watcher *w, int revents = EV_NONE)
615 C_ARGS: w->loop, w, revents 666 C_ARGS: e_loop (w), w, revents
616 667
617int ev_clear_pending (ev_watcher *w) 668int ev_clear_pending (ev_watcher *w)
618 C_ARGS: w->loop, w 669 C_ARGS: e_loop (w), w
619 670
620void ev_feed_event (ev_watcher *w, int revents = EV_NONE) 671void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
621 C_ARGS: w->loop, w, revents 672 C_ARGS: e_loop (w), w, revents
622 673
623int keepalive (ev_watcher *w, int new_value = 0) 674int keepalive (ev_watcher *w, int new_value = 0)
624 CODE: 675 CODE:
625{ 676{
626 RETVAL = w->flags & WFLAG_KEEPALIVE; 677 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
627 new_value = new_value ? WFLAG_KEEPALIVE : 0; 678 new_value = new_value ? WFLAG_KEEPALIVE : 0;
628 679
629 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 680 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
630 { 681 {
631 REF (w); 682 REF (w);
632 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 683 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
633 UNREF (w); 684 UNREF (w);
634 } 685 }
635} 686}
636 OUTPUT: 687 OUTPUT:
637 RETVAL 688 RETVAL
656 { 707 {
657 SvREFCNT_dec (w->data); 708 SvREFCNT_dec (w->data);
658 w->data = newSVsv (new_data); 709 w->data = newSVsv (new_data);
659 } 710 }
660} 711}
712 OUTPUT:
713 RETVAL
714
715SV *loop (ev_watcher *w)
716 CODE:
717 RETVAL = newRV_inc (w->loop);
661 OUTPUT: 718 OUTPUT:
662 RETVAL 719 RETVAL
663 720
664int priority (ev_watcher *w, int new_priority = 0) 721int priority (ev_watcher *w, int new_priority = 0)
665 CODE: 722 CODE:
803void ev_timer_again (ev_timer *w) 860void ev_timer_again (ev_timer *w)
804 INIT: 861 INIT:
805 CHECK_REPEAT (w->repeat); 862 CHECK_REPEAT (w->repeat);
806 CODE: 863 CODE:
807 REF (w); 864 REF (w);
808 ev_timer_again (w->loop, w); 865 ev_timer_again (e_loop (w), w);
809 UNREF (w); 866 UNREF (w);
810 867
811void DESTROY (ev_timer *w) 868void DESTROY (ev_timer *w)
812 CODE: 869 CODE:
813 STOP (timer, w); 870 STOP (timer, w);
838 STOP (periodic, w); 895 STOP (periodic, w);
839 896
840void ev_periodic_again (ev_periodic *w) 897void ev_periodic_again (ev_periodic *w)
841 CODE: 898 CODE:
842 REF (w); 899 REF (w);
843 ev_periodic_again (w->loop, w); 900 ev_periodic_again (e_loop (w), w);
844 UNREF (w); 901 UNREF (w);
845 902
846void DESTROY (ev_periodic *w) 903void DESTROY (ev_periodic *w)
847 CODE: 904 CODE:
848 STOP (periodic, w); 905 STOP (periodic, w);
878void DESTROY (ev_idle *w) 935void DESTROY (ev_idle *w)
879 CODE: 936 CODE:
880 STOP (idle, w); 937 STOP (idle, w);
881 e_destroy (w); 938 e_destroy (w);
882 939
883MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 940MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
884 941
885void ev_prepare_start (ev_prepare *w) 942void ev_prepare_start (ev_prepare *w)
886 CODE: 943 CODE:
887 START (prepare, w); 944 START (prepare, w);
888 945
938void DESTROY (ev_child *w) 995void DESTROY (ev_child *w)
939 CODE: 996 CODE:
940 STOP (child, w); 997 STOP (child, w);
941 e_destroy (w); 998 e_destroy (w);
942 999
943void set (ev_child *w, int pid) 1000void set (ev_child *w, int pid, int trace)
944 CODE: 1001 CODE:
945 RESET (child, w, (w, pid)); 1002 RESET (child, w, (w, pid, trace));
946 1003
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) 1004int pid (ev_child *w)
960 ALIAS: 1005 ALIAS:
961 rpid = 1 1006 rpid = 1
1007 rstatus = 2
962 CODE: 1008 CODE:
963 RETVAL = ix ? w->rpid : w->rstatus; 1009 RETVAL = ix == 0 ? w->pid
1010 : ix == 1 ? w->rpid
1011 : w->rstatus;
964 OUTPUT: 1012 OUTPUT:
965 RETVAL 1013 RETVAL
966 1014
967MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1015MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
968 1016
1019 PPCODE: 1067 PPCODE:
1020{ 1068{
1021 ev_statdata *s = ix ? &w->attr : &w->prev; 1069 ev_statdata *s = ix ? &w->attr : &w->prev;
1022 1070
1023 if (ix == 1) 1071 if (ix == 1)
1024 ev_stat_stat (w->loop, w); 1072 ev_stat_stat (e_loop (w), w);
1025 else if (!s->st_nlink) 1073 else if (!s->st_nlink)
1026 errno = ENOENT; 1074 errno = ENOENT;
1027 1075
1028 PL_statcache.st_dev = s->st_nlink; 1076 PL_statcache.st_dev = s->st_nlink;
1029 PL_statcache.st_ino = s->st_ino; 1077 PL_statcache.st_ino = s->st_ino;
1056 PUSHs (sv_2mortal (newSVuv (4096))); 1104 PUSHs (sv_2mortal (newSVuv (4096)));
1057 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 1105 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1058 } 1106 }
1059} 1107}
1060 1108
1109MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1110
1111void ev_embed_start (ev_embed *w)
1112 CODE:
1113 START (embed, w);
1114
1115void ev_embed_stop (ev_embed *w)
1116 CODE:
1117 STOP (embed, w);
1118
1119void DESTROY (ev_embed *w)
1120 CODE:
1121 STOP (embed, w);
1122 e_destroy (w);
1123
1124void set (ev_embed *w, struct ev_loop *loop)
1125 CODE:
1126{
1127 sv_setsv (w->fh, ST (1));
1128 RESET (embed, w, (w, loop));
1129}
1130
1131SV *other (ev_embed *w)
1132 CODE:
1133 RETVAL = newSVsv (w->fh);
1134 OUTPUT:
1135 RETVAL
1136
1137MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1138
1139SV *new (SV *klass, unsigned int flags = 0)
1140 CODE:
1141{
1142 struct ev_loop *loop = ev_loop_new (flags);
1143
1144 if (!loop)
1145 XSRETURN_UNDEF;
1146
1147 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1148}
1149 OUTPUT:
1150 RETVAL
1151
1152void DESTROY (struct ev_loop *loop)
1153 CODE:
1154 if (loop != evapi.default_loop) /* global destruction sucks */
1155 ev_loop_destroy (loop);
1156
1157void ev_loop_fork (struct ev_loop *loop)
1158
1159NV ev_now (struct ev_loop *loop)
1160
1161void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1162
1163void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1164
1165unsigned int ev_backend (struct ev_loop *loop)
1166
1167unsigned int ev_loop_count (struct ev_loop *loop)
1168
1169void ev_loop (struct ev_loop *loop, int flags = 0)
1170
1171void ev_unloop (struct ev_loop *loop, int how = 1)
1172
1173void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1174
1061#if 0 1175#if 0
1062 1176
1063MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1177void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1064 1178 CODE:
1065BOOT:
1066{ 1179{
1067 HV *stash = gv_stashpv ("EV::HTTP", 1); 1180 Signal signum = sv_signum (signal);
1181 CHECK_SIG (signal, signum);
1068 1182
1069 static const struct { 1183 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} 1184}
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 1185
1101#endif 1186#endif
1102 1187
1188ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1189 ALIAS:
1190 io_ns = 1
1191 CODE:
1192{
1193 int fd = sv_fileno (fh);
1194 CHECK_FD (fh, fd);
1103 1195
1196 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1197 RETVAL->fh = newSVsv (fh);
1198 ev_io_set (RETVAL, fd, events);
1199 if (!ix) START (io, RETVAL);
1200}
1201 OUTPUT:
1202 RETVAL
1104 1203
1204ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1205 ALIAS:
1206 timer_ns = 1
1207 INIT:
1208 CHECK_REPEAT (repeat);
1209 CODE:
1210 RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1211 ev_timer_set (RETVAL, after, repeat);
1212 if (!ix) START (timer, RETVAL);
1213 OUTPUT:
1214 RETVAL
1105 1215
1216SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1217 ALIAS:
1218 periodic_ns = 1
1219 INIT:
1220 CHECK_REPEAT (interval);
1221 CODE:
1222{
1223 ev_periodic *w;
1224 w = e_new (sizeof (ev_periodic), cb, ST (0));
1225 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1226 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
1227 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1228 if (!ix) START (periodic, w);
1229}
1230 OUTPUT:
1231 RETVAL
1106 1232
1233#if 0
1107 1234
1235ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1236 ALIAS:
1237 signal_ns = 1
1238 CODE:
1239{
1240 Signal signum = sv_signum (signal);
1241 CHECK_SIG (signal, signum);
1108 1242
1243 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1244 ev_signal_set (RETVAL, signum);
1245 if (!ix) START (signal, RETVAL);
1246}
1247 OUTPUT:
1248 RETVAL
1109 1249
1250#endif
1251
1252ev_idle *idle (struct ev_loop *loop, SV *cb)
1253 ALIAS:
1254 idle_ns = 1
1255 CODE:
1256 RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1257 ev_idle_set (RETVAL);
1258 if (!ix) START (idle, RETVAL);
1259 OUTPUT:
1260 RETVAL
1261
1262ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1263 ALIAS:
1264 prepare_ns = 1
1265 CODE:
1266 RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1267 ev_prepare_set (RETVAL);
1268 if (!ix) START (prepare, RETVAL);
1269 OUTPUT:
1270 RETVAL
1271
1272ev_check *check (struct ev_loop *loop, SV *cb)
1273 ALIAS:
1274 check_ns = 1
1275 CODE:
1276 RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1277 ev_check_set (RETVAL);
1278 if (!ix) START (check, RETVAL);
1279 OUTPUT:
1280 RETVAL
1281
1282ev_fork *fork (struct ev_loop *loop, SV *cb)
1283 ALIAS:
1284 fork_ns = 1
1285 CODE:
1286 RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1287 ev_fork_set (RETVAL);
1288 if (!ix) START (fork, RETVAL);
1289 OUTPUT:
1290 RETVAL
1291
1292ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1293 ALIAS:
1294 child_ns = 1
1295 CODE:
1296 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1297 ev_child_set (RETVAL, pid, trace);
1298 if (!ix) START (child, RETVAL);
1299 OUTPUT:
1300 RETVAL
1301
1302ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1303 ALIAS:
1304 stat_ns = 1
1305 CODE:
1306 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1307 RETVAL->fh = newSVsv (path);
1308 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1309 if (!ix) START (stat, RETVAL);
1310 OUTPUT:
1311 RETVAL
1312
1313ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef)
1314 ALIAS:
1315 embed_ns = 1
1316 CODE:
1317{
1318 if (!(ev_backend (other) & ev_embeddable_backends ()))
1319 croak ("passed loop is not embeddable via EV::embed,");
1320
1321 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1322 RETVAL->fh = newSVsv (ST (1));
1323 ev_embed_set (RETVAL, other);
1324
1325 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1326
1327 if (!ix) START (embed, RETVAL);
1328}
1329 OUTPUT:
1330 RETVAL
1331
1332void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1333 CODE:
1334 ev_once (
1335 loop,
1336 sv_fileno (fh), events,
1337 SvOK (timeout) ? SvNV (timeout) : -1.,
1338 e_once_cb,
1339 newSVsv (cb)
1340 );
1341

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines