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

Comparing EV/EV.xs (file contents):
Revision 1.88 by root, Sat Dec 8 04:02:30 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
365 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 366 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
366 stash_check = gv_stashpv ("EV::Check" , 1); 367 stash_check = gv_stashpv ("EV::Check" , 1);
367 stash_child = gv_stashpv ("EV::Child" , 1); 368 stash_child = gv_stashpv ("EV::Child" , 1);
368 stash_embed = gv_stashpv ("EV::Embed" , 1); 369 stash_embed = gv_stashpv ("EV::Embed" , 1);
369 stash_stat = gv_stashpv ("EV::Stat" , 1); 370 stash_stat = gv_stashpv ("EV::Stat" , 1);
371 stash_fork = gv_stashpv ("EV::Fork" , 1);
370 372
371 { 373 {
372 SV *sv = perl_get_sv ("EV::API", TRUE); 374 SV *sv = perl_get_sv ("EV::API", TRUE);
373 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 375 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
374 376
375 /* the poor man's shared library emulator */ 377 /* the poor man's shared library emulator */
376 evapi.ver = EV_API_VERSION; 378 evapi.ver = EV_API_VERSION;
377 evapi.rev = EV_API_REVISION; 379 evapi.rev = EV_API_REVISION;
378 evapi.sv_fileno = sv_fileno; 380 evapi.sv_fileno = sv_fileno;
379 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;
380 evapi.now = ev_now; 390 evapi.now = ev_now;
381 evapi.backend = ev_backend; 391 evapi.backend = ev_backend;
382 evapi.unloop = ev_unloop; 392 evapi.unloop = ev_unloop;
383 evapi.ref = ev_ref; 393 evapi.ref = ev_ref;
384 evapi.unref = ev_unref; 394 evapi.unref = ev_unref;
385 evapi.time = ev_time;
386 evapi.loop = ev_loop; 395 evapi.loop = ev_loop;
387 evapi.once = ev_once; 396 evapi.once = ev_once;
388 evapi.io_start = ev_io_start; 397 evapi.io_start = ev_io_start;
389 evapi.io_stop = ev_io_stop; 398 evapi.io_stop = ev_io_stop;
390 evapi.timer_start = ev_timer_start; 399 evapi.timer_start = ev_timer_start;
391 evapi.timer_stop = ev_timer_stop; 400 evapi.timer_stop = ev_timer_stop;
392 evapi.timer_again = ev_timer_again; 401 evapi.timer_again = ev_timer_again;
393 evapi.periodic_start = ev_periodic_start; 402 evapi.periodic_start = ev_periodic_start;
394 evapi.periodic_stop = ev_periodic_stop; 403 evapi.periodic_stop = ev_periodic_stop;
395 evapi.signal_start = ev_signal_start; 404 evapi.signal_start = ev_signal_start;
396 evapi.signal_stop = ev_signal_stop; 405 evapi.signal_stop = ev_signal_stop;
397 evapi.idle_start = ev_idle_start; 406 evapi.idle_start = ev_idle_start;
398 evapi.idle_stop = ev_idle_stop; 407 evapi.idle_stop = ev_idle_stop;
399 evapi.prepare_start = ev_prepare_start; 408 evapi.prepare_start = ev_prepare_start;
400 evapi.prepare_stop = ev_prepare_stop; 409 evapi.prepare_stop = ev_prepare_stop;
401 evapi.check_start = ev_check_start; 410 evapi.check_start = ev_check_start;
402 evapi.check_stop = ev_check_stop; 411 evapi.check_stop = ev_check_stop;
403 evapi.child_start = ev_child_start; 412 evapi.child_start = ev_child_start;
404 evapi.child_stop = ev_child_stop; 413 evapi.child_stop = ev_child_stop;
405 evapi.stat_start = ev_stat_start; 414 evapi.stat_start = ev_stat_start;
406 evapi.stat_stop = ev_stat_stop; 415 evapi.stat_stop = ev_stat_stop;
407 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;
408 evapi.clear_pending = ev_clear_pending; 422 evapi.clear_pending = ev_clear_pending;
423 evapi.invoke = ev_invoke;
409 424
410 sv_setiv (sv, (IV)&evapi); 425 sv_setiv (sv, (IV)&evapi);
411 SvREADONLY_on (sv); 426 SvREADONLY_on (sv);
412 } 427 }
413#ifndef _WIN32 428#ifndef _WIN32
414 pthread_atfork (0, 0, ev_default_fork); 429 pthread_atfork (0, 0, ev_default_fork);
415#endif 430#endif
416} 431}
417 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
418NV ev_now () 448NV ev_now ()
449 C_ARGS: evapi.default_loop
419 450
420unsigned int ev_backend () 451unsigned int ev_backend ()
421 452 C_ARGS: evapi.default_loop
422NV ev_time ()
423
424unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
425 453
426unsigned int ev_loop_count () 454unsigned int ev_loop_count ()
455 C_ARGS: evapi.default_loop
427 456
428void ev_loop (int flags = 0) 457void ev_loop (int flags = 0)
458 C_ARGS: evapi.default_loop, flags
429 459
430void 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}
431 474
432ev_io *io (SV *fh, int events, SV *cb) 475ev_io *io (SV *fh, int events, SV *cb)
433 ALIAS: 476 ALIAS:
434 io_ns = 1 477 io_ns = 1
435 CODE: 478 CODE:
517 ev_check_set (RETVAL); 560 ev_check_set (RETVAL);
518 if (!ix) START (check, RETVAL); 561 if (!ix) START (check, RETVAL);
519 OUTPUT: 562 OUTPUT:
520 RETVAL 563 RETVAL
521 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
522ev_child *child (int pid, SV *cb) 575ev_child *child (int pid, SV *cb)
523 ALIAS: 576 ALIAS:
524 child_ns = 1 577 child_ns = 1
525 CODE: 578 CODE:
526 RETVAL = e_new (sizeof (ev_child), cb); 579 RETVAL = e_new (sizeof (ev_child), cb);
541 RETVAL 594 RETVAL
542 595
543void once (SV *fh, int events, SV *timeout, SV *cb) 596void once (SV *fh, int events, SV *timeout, SV *cb)
544 CODE: 597 CODE:
545 ev_once ( 598 ev_once (
599 evapi.default_loop,
546 sv_fileno (fh), events, 600 sv_fileno (fh), events,
547 SvOK (timeout) ? SvNV (timeout) : -1., 601 SvOK (timeout) ? SvNV (timeout) : -1.,
548 e_once_cb, 602 e_once_cb,
549 newSVsv (cb) 603 newSVsv (cb)
550 ); 604 );
554MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 608MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
555 609
556int ev_is_active (ev_watcher *w) 610int ev_is_active (ev_watcher *w)
557 611
558int 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
559 622
560int keepalive (ev_watcher *w, int new_value = 0) 623int keepalive (ev_watcher *w, int new_value = 0)
561 CODE: 624 CODE:
562{ 625{
563 RETVAL = w->flags & WFLAG_KEEPALIVE; 626 RETVAL = w->flags & WFLAG_KEEPALIVE;
595 w->data = newSVsv (new_data); 658 w->data = newSVsv (new_data);
596 } 659 }
597} 660}
598 OUTPUT: 661 OUTPUT:
599 RETVAL 662 RETVAL
600
601void trigger (ev_watcher *w, int revents = EV_NONE)
602 CODE:
603 w->cb (w, revents);
604 663
605int priority (ev_watcher *w, int new_priority = 0) 664int priority (ev_watcher *w, int new_priority = 0)
606 CODE: 665 CODE:
607{ 666{
608 RETVAL = w->priority; 667 RETVAL = w->priority;
744void ev_timer_again (ev_timer *w) 803void ev_timer_again (ev_timer *w)
745 INIT: 804 INIT:
746 CHECK_REPEAT (w->repeat); 805 CHECK_REPEAT (w->repeat);
747 CODE: 806 CODE:
748 REF (w); 807 REF (w);
749 ev_timer_again (w); 808 ev_timer_again (w->loop, w);
750 UNREF (w); 809 UNREF (w);
751 810
752void DESTROY (ev_timer *w) 811void DESTROY (ev_timer *w)
753 CODE: 812 CODE:
754 STOP (timer, w); 813 STOP (timer, w);
758 INIT: 817 INIT:
759 CHECK_REPEAT (repeat); 818 CHECK_REPEAT (repeat);
760 CODE: 819 CODE:
761 RESET (timer, w, (w, after, repeat)); 820 RESET (timer, w, (w, after, repeat));
762 821
822NV at (ev_timer *w)
823 CODE:
824 RETVAL = w->at;
825 OUTPUT:
826 RETVAL
827
763MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 828MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
764 829
765void ev_periodic_start (ev_periodic *w) 830void ev_periodic_start (ev_periodic *w)
766 INIT: 831 INIT:
767 CHECK_REPEAT (w->interval); 832 CHECK_REPEAT (w->interval);
773 STOP (periodic, w); 838 STOP (periodic, w);
774 839
775void ev_periodic_again (ev_periodic *w) 840void ev_periodic_again (ev_periodic *w)
776 CODE: 841 CODE:
777 REF (w); 842 REF (w);
778 ev_periodic_again (w); 843 ev_periodic_again (w->loop, w);
779 UNREF (w); 844 UNREF (w);
780 845
781void DESTROY (ev_periodic *w) 846void DESTROY (ev_periodic *w)
782 CODE: 847 CODE:
783 STOP (periodic, w); 848 STOP (periodic, w);
792 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 857 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
793 858
794 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));
795} 860}
796 861
862NV at (ev_periodic *w)
863 CODE:
864 RETVAL = w->at;
865 OUTPUT:
866 RETVAL
867
797MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 868MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
798 869
799void ev_idle_start (ev_idle *w) 870void ev_idle_start (ev_idle *w)
800 CODE: 871 CODE:
801 START (idle, w); 872 START (idle, w);
835 STOP (check, w); 906 STOP (check, w);
836 907
837void DESTROY (ev_check *w) 908void DESTROY (ev_check *w)
838 CODE: 909 CODE:
839 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);
840 e_destroy (w); 926 e_destroy (w);
841 927
842MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 928MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
843 929
844void ev_child_start (ev_child *w) 930void ev_child_start (ev_child *w)
933 PPCODE: 1019 PPCODE:
934{ 1020{
935 ev_statdata *s = ix ? &w->attr : &w->prev; 1021 ev_statdata *s = ix ? &w->attr : &w->prev;
936 1022
937 if (ix == 1) 1023 if (ix == 1)
938 ev_stat_stat (w); 1024 ev_stat_stat (w->loop, w);
939 else if (!s->st_nlink) 1025 else if (!s->st_nlink)
940 errno = ENOENT; 1026 errno = ENOENT;
941 1027
942 PL_statcache.st_dev = s->st_nlink; 1028 PL_statcache.st_dev = s->st_nlink;
943 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