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

Comparing EV/EV.xs (file contents):
Revision 1.85 by root, Sat Dec 1 22:51:34 2007 UTC vs.
Revision 1.91 by root, Thu Dec 20 07:12:57 2007 UTC

28#define WFLAG_KEEPALIVE 1 28#define WFLAG_KEEPALIVE 1
29 29
30#define UNREF(w) \ 30#define UNREF(w) \
31 if (!((w)->flags & WFLAG_KEEPALIVE) \ 31 if (!((w)->flags & WFLAG_KEEPALIVE) \
32 && !ev_is_active (w)) \ 32 && !ev_is_active (w)) \
33 ev_unref (); 33 ev_unref (w->loop);
34 34
35#define REF(w) \ 35#define REF(w) \
36 if (!((w)->flags & WFLAG_KEEPALIVE) \ 36 if (!((w)->flags & WFLAG_KEEPALIVE) \
37 && ev_is_active (w)) \ 37 && ev_is_active (w)) \
38 ev_ref (); 38 ev_ref (w->loop);
39 39
40#define START(type,w) \ 40#define START(type,w) \
41 do { \ 41 do { \
42 UNREF (w); \ 42 UNREF (w); \
43 ev_ ## type ## _start (w); \ 43 ev_ ## type ## _start (w->loop, w); \
44 } while (0) 44 } while (0)
45 45
46#define STOP(type,w) \ 46#define STOP(type,w) \
47 do { \ 47 do { \
48 REF (w); \ 48 REF (w); \
49 ev_ ## type ## _stop (w); \ 49 ev_ ## type ## _stop (w->loop, w); \
50 } while (0) 50 } while (0)
51 51
52#define RESET(type,w,seta) \ 52#define RESET(type,w,seta) \
53 do { \ 53 do { \
54 int active = ev_is_active (w); \ 54 int active = ev_is_active (w); \
101} 101}
102 102
103///////////////////////////////////////////////////////////////////////////// 103/////////////////////////////////////////////////////////////////////////////
104// Event 104// Event
105 105
106static void e_cb (ev_watcher *w, int revents); 106static void e_cb (EV_P_ ev_watcher *w, int revents);
107 107
108static int 108static int
109sv_fileno (SV *fh) 109sv_fileno (SV *fh)
110{ 110{
111 SvGETMAGIC (fh); 111 SvGETMAGIC (fh);
132 132
133 w = (ev_watcher *)SvPVX (self); 133 w = (ev_watcher *)SvPVX (self);
134 134
135 ev_init (w, e_cb); 135 ev_init (w, e_cb);
136 136
137 w->loop = EV_DEFAULT;
137 w->flags = WFLAG_KEEPALIVE; 138 w->flags = WFLAG_KEEPALIVE;
138 w->data = 0; 139 w->data = 0;
139 w->fh = 0; 140 w->fh = 0;
140 w->cb_sv = newSVsv (cb_sv); 141 w->cb_sv = newSVsv (cb_sv);
141 w->self = self; 142 w->self = self;
171} 172}
172 173
173static SV *sv_events_cache; 174static SV *sv_events_cache;
174 175
175static void 176static void
176e_cb (ev_watcher *w, int revents) 177e_cb (EV_P_ ev_watcher *w, int revents)
177{ 178{
178 dSP; 179 dSP;
179 I32 mark = SP - PL_stack_base; 180 I32 mark = SP - PL_stack_base;
180 SV *sv_self, *sv_events; 181 SV *sv_self, *sv_events;
181 182
244 else 245 else
245 sv_events_cache = sv_events; 246 sv_events_cache = sv_events;
246 247
247 if (SvTRUE (ERRSV)) 248 if (SvTRUE (ERRSV))
248 { 249 {
250 SPAGAIN;
249 PUSHMARK (SP); 251 PUSHMARK (SP);
250 PUTBACK; 252 PUTBACK;
251 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 253 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
252 } 254 }
253 255
364 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 366 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
365 stash_check = gv_stashpv ("EV::Check" , 1); 367 stash_check = gv_stashpv ("EV::Check" , 1);
366 stash_child = gv_stashpv ("EV::Child" , 1); 368 stash_child = gv_stashpv ("EV::Child" , 1);
367 stash_embed = gv_stashpv ("EV::Embed" , 1); 369 stash_embed = gv_stashpv ("EV::Embed" , 1);
368 stash_stat = gv_stashpv ("EV::Stat" , 1); 370 stash_stat = gv_stashpv ("EV::Stat" , 1);
371 stash_fork = gv_stashpv ("EV::Fork" , 1);
369 372
370 { 373 {
371 SV *sv = perl_get_sv ("EV::API", TRUE); 374 SV *sv = perl_get_sv ("EV::API", TRUE);
372 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 375 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
373 376
374 /* the poor man's shared library emulator */ 377 /* the poor man's shared library emulator */
375 evapi.ver = EV_API_VERSION; 378 evapi.ver = EV_API_VERSION;
376 evapi.rev = EV_API_REVISION; 379 evapi.rev = EV_API_REVISION;
377 evapi.sv_fileno = sv_fileno; 380 evapi.sv_fileno = sv_fileno;
378 evapi.sv_signum = sv_signum; 381 evapi.sv_signum = sv_signum;
382 evapi.supported_backends = ev_supported_backends ();
383 evapi.recommended_backends = ev_recommended_backends ();
384 evapi.embeddable_backends = ev_embeddable_backends ();
385 evapi.time = ev_time;
386 evapi.loop_new = ev_loop_new;
387 evapi.loop_destroy = ev_loop_destroy;
388 evapi.loop_fork = ev_loop_fork;
389 evapi.loop_count = ev_loop_count;
379 evapi.now = ev_now; 390 evapi.now = ev_now;
380 evapi.backend = ev_backend; 391 evapi.backend = ev_backend;
381 evapi.unloop = ev_unloop; 392 evapi.unloop = ev_unloop;
382 evapi.ref = ev_ref; 393 evapi.ref = ev_ref;
383 evapi.unref = ev_unref; 394 evapi.unref = ev_unref;
384 evapi.time = ev_time;
385 evapi.loop = ev_loop; 395 evapi.loop = ev_loop;
386 evapi.once = ev_once; 396 evapi.once = ev_once;
387 evapi.io_start = ev_io_start; 397 evapi.io_start = ev_io_start;
388 evapi.io_stop = ev_io_stop; 398 evapi.io_stop = ev_io_stop;
389 evapi.timer_start = ev_timer_start; 399 evapi.timer_start = ev_timer_start;
390 evapi.timer_stop = ev_timer_stop; 400 evapi.timer_stop = ev_timer_stop;
391 evapi.timer_again = ev_timer_again; 401 evapi.timer_again = ev_timer_again;
392 evapi.periodic_start = ev_periodic_start; 402 evapi.periodic_start = ev_periodic_start;
393 evapi.periodic_stop = ev_periodic_stop; 403 evapi.periodic_stop = ev_periodic_stop;
394 evapi.signal_start = ev_signal_start; 404 evapi.signal_start = ev_signal_start;
395 evapi.signal_stop = ev_signal_stop; 405 evapi.signal_stop = ev_signal_stop;
396 evapi.idle_start = ev_idle_start; 406 evapi.idle_start = ev_idle_start;
397 evapi.idle_stop = ev_idle_stop; 407 evapi.idle_stop = ev_idle_stop;
398 evapi.prepare_start = ev_prepare_start; 408 evapi.prepare_start = ev_prepare_start;
399 evapi.prepare_stop = ev_prepare_stop; 409 evapi.prepare_stop = ev_prepare_stop;
400 evapi.check_start = ev_check_start; 410 evapi.check_start = ev_check_start;
401 evapi.check_stop = ev_check_stop; 411 evapi.check_stop = ev_check_stop;
402 evapi.child_start = ev_child_start; 412 evapi.child_start = ev_child_start;
403 evapi.child_stop = ev_child_stop; 413 evapi.child_stop = ev_child_stop;
404 evapi.stat_start = ev_stat_start; 414 evapi.stat_start = ev_stat_start;
405 evapi.stat_stop = ev_stat_stop; 415 evapi.stat_stop = ev_stat_stop;
406 evapi.stat_stat = ev_stat_stat; 416 evapi.stat_stat = ev_stat_stat;
417 evapi.embed_start = ev_embed_start;
418 evapi.embed_stop = ev_embed_stop;
419 evapi.embed_sweep = ev_embed_sweep;
420 evapi.fork_start = ev_fork_start;
421 evapi.fork_stop = ev_fork_stop;
422 evapi.clear_pending = ev_clear_pending;
423 evapi.invoke = ev_invoke;
407 424
408 sv_setiv (sv, (IV)&evapi); 425 sv_setiv (sv, (IV)&evapi);
409 SvREADONLY_on (sv); 426 SvREADONLY_on (sv);
410 } 427 }
411#ifndef _WIN32 428#ifndef _WIN32
412 pthread_atfork (0, 0, ev_default_fork); 429 pthread_atfork (0, 0, ev_default_fork);
413#endif 430#endif
414} 431}
415 432
433SV *ev_default_loop (unsigned int flags = ev_supported_backends ())
434 CODE:
435{
436 evapi.default_loop = ev_default_loop (flags);
437 if (!evapi.default_loop)
438 XSRETURN_UNDEF;
439
440 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))),
441 gv_stashpv ("EV::Loop::Default", 1));
442}
443 OUTPUT:
444 RETVAL
445
446NV ev_time ()
447
416NV ev_now () 448NV ev_now ()
449 C_ARGS: evapi.default_loop
417 450
418unsigned int ev_backend () 451unsigned int ev_backend ()
452 C_ARGS: evapi.default_loop
419 453
420NV ev_time () 454unsigned int ev_loop_count ()
421 455 C_ARGS: evapi.default_loop
422unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
423 456
424void ev_loop (int flags = 0) 457void ev_loop (int flags = 0)
458 C_ARGS: evapi.default_loop, flags
425 459
426void ev_unloop (int how = 1) 460void ev_unloop (int how = 1)
461 C_ARGS: evapi.default_loop, how
462
463void ev_feed_fd_event (int fd, int revents = EV_NONE)
464 C_ARGS: evapi.default_loop, fd, revents
465
466void ev_feed_signal_event (SV *signal)
467 CODE:
468{
469 Signal signum = sv_signum (signal);
470 CHECK_SIG (signal, signum);
471
472 ev_feed_signal_event (evapi.default_loop, signum);
473}
427 474
428ev_io *io (SV *fh, int events, SV *cb) 475ev_io *io (SV *fh, int events, SV *cb)
429 ALIAS: 476 ALIAS:
430 io_ns = 1 477 io_ns = 1
431 CODE: 478 CODE:
513 ev_check_set (RETVAL); 560 ev_check_set (RETVAL);
514 if (!ix) START (check, RETVAL); 561 if (!ix) START (check, RETVAL);
515 OUTPUT: 562 OUTPUT:
516 RETVAL 563 RETVAL
517 564
565ev_fork *fork (SV *cb)
566 ALIAS:
567 fork_ns = 1
568 CODE:
569 RETVAL = e_new (sizeof (ev_fork), cb);
570 ev_fork_set (RETVAL);
571 if (!ix) START (fork, RETVAL);
572 OUTPUT:
573 RETVAL
574
518ev_child *child (int pid, SV *cb) 575ev_child *child (int pid, SV *cb)
519 ALIAS: 576 ALIAS:
520 child_ns = 1 577 child_ns = 1
521 CODE: 578 CODE:
522 RETVAL = e_new (sizeof (ev_child), cb); 579 RETVAL = e_new (sizeof (ev_child), cb);
537 RETVAL 594 RETVAL
538 595
539void once (SV *fh, int events, SV *timeout, SV *cb) 596void once (SV *fh, int events, SV *timeout, SV *cb)
540 CODE: 597 CODE:
541 ev_once ( 598 ev_once (
599 evapi.default_loop,
542 sv_fileno (fh), events, 600 sv_fileno (fh), events,
543 SvOK (timeout) ? SvNV (timeout) : -1., 601 SvOK (timeout) ? SvNV (timeout) : -1.,
544 e_once_cb, 602 e_once_cb,
545 newSVsv (cb) 603 newSVsv (cb)
546 ); 604 );
550MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 608MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
551 609
552int ev_is_active (ev_watcher *w) 610int ev_is_active (ev_watcher *w)
553 611
554int ev_is_pending (ev_watcher *w) 612int ev_is_pending (ev_watcher *w)
613
614void ev_invoke (ev_watcher *w, int revents = EV_NONE)
615 C_ARGS: w->loop, w, revents
616
617int ev_clear_pending (ev_watcher *w)
618 C_ARGS: w->loop, w
619
620void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
621 C_ARGS: w->loop, w, revents
555 622
556int keepalive (ev_watcher *w, int new_value = 0) 623int keepalive (ev_watcher *w, int new_value = 0)
557 CODE: 624 CODE:
558{ 625{
559 RETVAL = w->flags & WFLAG_KEEPALIVE; 626 RETVAL = w->flags & WFLAG_KEEPALIVE;
592 } 659 }
593} 660}
594 OUTPUT: 661 OUTPUT:
595 RETVAL 662 RETVAL
596 663
597void trigger (ev_watcher *w, int revents = EV_NONE)
598 CODE:
599 w->cb (w, revents);
600
601int priority (ev_watcher *w, int new_priority = 0) 664int priority (ev_watcher *w, int new_priority = 0)
602 CODE: 665 CODE:
603{ 666{
604 RETVAL = w->priority; 667 RETVAL = w->priority;
605 668
606 if (items > 1) 669 if (items > 1)
607 { 670 {
608 int active = ev_is_active (w); 671 int active = ev_is_active (w);
609
610 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
611 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
612 672
613 if (active) 673 if (active)
614 { 674 {
615 /* grrr. */ 675 /* grrr. */
616 PUSHMARK (SP); 676 PUSHMARK (SP);
617 XPUSHs (ST (0)); 677 XPUSHs (ST (0));
678 PUTBACK;
618 call_method ("stop", G_DISCARD | G_VOID); 679 call_method ("stop", G_DISCARD | G_VOID);
619 } 680 }
620 681
621 ev_set_priority (w, new_priority); 682 ev_set_priority (w, new_priority);
622 683
623 if (active) 684 if (active)
624 { 685 {
625 PUSHMARK (SP); 686 PUSHMARK (SP);
626 XPUSHs (ST (0)); 687 XPUSHs (ST (0));
688 PUTBACK;
627 call_method ("start", G_DISCARD | G_VOID); 689 call_method ("start", G_DISCARD | G_VOID);
628 } 690 }
629 } 691 }
630} 692}
631 OUTPUT: 693 OUTPUT:
741void ev_timer_again (ev_timer *w) 803void ev_timer_again (ev_timer *w)
742 INIT: 804 INIT:
743 CHECK_REPEAT (w->repeat); 805 CHECK_REPEAT (w->repeat);
744 CODE: 806 CODE:
745 REF (w); 807 REF (w);
746 ev_timer_again (w); 808 ev_timer_again (w->loop, w);
747 UNREF (w); 809 UNREF (w);
748 810
749void DESTROY (ev_timer *w) 811void DESTROY (ev_timer *w)
750 CODE: 812 CODE:
751 STOP (timer, w); 813 STOP (timer, w);
755 INIT: 817 INIT:
756 CHECK_REPEAT (repeat); 818 CHECK_REPEAT (repeat);
757 CODE: 819 CODE:
758 RESET (timer, w, (w, after, repeat)); 820 RESET (timer, w, (w, after, repeat));
759 821
822NV at (ev_timer *w)
823 CODE:
824 RETVAL = w->at;
825 OUTPUT:
826 RETVAL
827
760MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 828MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
761 829
762void ev_periodic_start (ev_periodic *w) 830void ev_periodic_start (ev_periodic *w)
763 INIT: 831 INIT:
764 CHECK_REPEAT (w->interval); 832 CHECK_REPEAT (w->interval);
770 STOP (periodic, w); 838 STOP (periodic, w);
771 839
772void ev_periodic_again (ev_periodic *w) 840void ev_periodic_again (ev_periodic *w)
773 CODE: 841 CODE:
774 REF (w); 842 REF (w);
775 ev_periodic_again (w); 843 ev_periodic_again (w->loop, w);
776 UNREF (w); 844 UNREF (w);
777 845
778void DESTROY (ev_periodic *w) 846void DESTROY (ev_periodic *w)
779 CODE: 847 CODE:
780 STOP (periodic, w); 848 STOP (periodic, w);
789 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 857 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
790 858
791 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 859 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
792} 860}
793 861
862NV at (ev_periodic *w)
863 CODE:
864 RETVAL = w->at;
865 OUTPUT:
866 RETVAL
867
794MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 868MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
795 869
796void ev_idle_start (ev_idle *w) 870void ev_idle_start (ev_idle *w)
797 CODE: 871 CODE:
798 START (idle, w); 872 START (idle, w);
832 STOP (check, w); 906 STOP (check, w);
833 907
834void DESTROY (ev_check *w) 908void DESTROY (ev_check *w)
835 CODE: 909 CODE:
836 STOP (check, w); 910 STOP (check, w);
911 e_destroy (w);
912
913MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
914
915void ev_fork_start (ev_fork *w)
916 CODE:
917 START (fork, w);
918
919void ev_fork_stop (ev_fork *w)
920 CODE:
921 STOP (fork, w);
922
923void DESTROY (ev_fork *w)
924 CODE:
925 STOP (fork, w);
837 e_destroy (w); 926 e_destroy (w);
838 927
839MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 928MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
840 929
841void ev_child_start (ev_child *w) 930void ev_child_start (ev_child *w)
930 PPCODE: 1019 PPCODE:
931{ 1020{
932 ev_statdata *s = ix ? &w->attr : &w->prev; 1021 ev_statdata *s = ix ? &w->attr : &w->prev;
933 1022
934 if (ix == 1) 1023 if (ix == 1)
935 ev_stat_stat (w); 1024 ev_stat_stat (w->loop, w);
936 else if (!s->st_nlink) 1025 else if (!s->st_nlink)
937 errno = ENOENT; 1026 errno = ENOENT;
938 1027
939 PL_statcache.st_dev = s->st_nlink; 1028 PL_statcache.st_dev = s->st_nlink;
940 PL_statcache.st_ino = s->st_ino; 1029 PL_statcache.st_ino = s->st_ino;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines