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

Comparing EV/EV.xs (file contents):
Revision 1.103 by root, Wed Dec 26 14:55:22 2007 UTC vs.
Revision 1.111 by root, Sun May 18 10:45:36 2008 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
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
7/* fix perl api breakage */
8#undef signal
9#undef sigaction
6 10
7#define EV_PROTOTYPES 1 11#define EV_PROTOTYPES 1
8#define EV_USE_NANOSLEEP EV_USE_MONOTONIC 12#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
9#define EV_H <ev.h> 13#define EV_H <ev.h>
10#include "EV/EVAPI.h" 14#include "EV/EVAPI.h"
11
12/* fix perl api breakage */
13#undef signal
14#undef sigaction
15 15
16#define EV_SELECT_IS_WINSOCKET 0 16#define EV_SELECT_IS_WINSOCKET 0
17#ifdef _WIN32 17#ifdef _WIN32
18# define EV_SELECT_USE_FD_SET 0 18# define EV_SELECT_USE_FD_SET 0
19# define NFDBITS PERL_NFDBITS 19# define NFDBITS PERL_NFDBITS
29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
30 30
31#define WFLAG_KEEPALIVE 1 31#define WFLAG_KEEPALIVE 1
32 32
33#define UNREF(w) \ 33#define UNREF(w) \
34 if (!((w)->flags & WFLAG_KEEPALIVE) \ 34 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
35 && !ev_is_active (w)) \ 35 && !ev_is_active (w)) \
36 ev_unref (e_loop (w)); 36 ev_unref (e_loop (w));
37 37
38#define REF(w) \ 38#define REF(w) \
39 if (!((w)->flags & WFLAG_KEEPALIVE) \ 39 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
40 && ev_is_active (w)) \ 40 && ev_is_active (w)) \
41 ev_ref (e_loop (w)); 41 ev_ref (e_loop (w));
42 42
43#define START(type,w) \ 43#define START(type,w) \
44 do { \ 44 do { \
77 *stash_stat, 77 *stash_stat,
78 *stash_idle, 78 *stash_idle,
79 *stash_prepare, 79 *stash_prepare,
80 *stash_check, 80 *stash_check,
81 *stash_embed, 81 *stash_embed,
82 *stash_fork; 82 *stash_fork,
83 *stash_async;
83 84
84#ifndef SIG_SIZE 85#ifndef SIG_SIZE
85/* kudos to Slaven Rezic for the idea */ 86/* kudos to Slaven Rezic for the idea */
86static char sig_size [] = { SIG_NUM }; 87static char sig_size [] = { SIG_NUM };
87# define SIG_SIZE (sizeof (sig_size) + 1) 88# define SIG_SIZE (sizeof (sig_size) + 1)
138 139
139 w = (ev_watcher *)SvPVX (self); 140 w = (ev_watcher *)SvPVX (self);
140 141
141 ev_init (w, e_cb); 142 ev_init (w, e_cb);
142 143
143 w->loop = SvREFCNT_inc (SvRV (loop)); 144 w->loop = SvREFCNT_inc (SvRV (loop));
144 w->flags = WFLAG_KEEPALIVE; 145 w->e_flags = WFLAG_KEEPALIVE;
145 w->data = 0; 146 w->data = 0;
146 w->fh = 0; 147 w->fh = 0;
147 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); 148 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv);
148 w->self = self; 149 w->self = self;
149 150
150 return (void *)w; 151 return (void *)w;
151} 152}
152 153
153static void 154static void
375 stash_check = gv_stashpv ("EV::Check" , 1); 376 stash_check = gv_stashpv ("EV::Check" , 1);
376 stash_child = gv_stashpv ("EV::Child" , 1); 377 stash_child = gv_stashpv ("EV::Child" , 1);
377 stash_embed = gv_stashpv ("EV::Embed" , 1); 378 stash_embed = gv_stashpv ("EV::Embed" , 1);
378 stash_stat = gv_stashpv ("EV::Stat" , 1); 379 stash_stat = gv_stashpv ("EV::Stat" , 1);
379 stash_fork = gv_stashpv ("EV::Fork" , 1); 380 stash_fork = gv_stashpv ("EV::Fork" , 1);
381 stash_async = gv_stashpv ("EV::Async" , 1);
380 382
381 { 383 {
382 SV *sv = perl_get_sv ("EV::API", TRUE); 384 SV *sv = perl_get_sv ("EV::API", TRUE);
383 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 385 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
384 386
388 evapi.sv_fileno = sv_fileno; 390 evapi.sv_fileno = sv_fileno;
389 evapi.sv_signum = sv_signum; 391 evapi.sv_signum = sv_signum;
390 evapi.supported_backends = ev_supported_backends (); 392 evapi.supported_backends = ev_supported_backends ();
391 evapi.recommended_backends = ev_recommended_backends (); 393 evapi.recommended_backends = ev_recommended_backends ();
392 evapi.embeddable_backends = ev_embeddable_backends (); 394 evapi.embeddable_backends = ev_embeddable_backends ();
393 evapi.time = ev_time; 395 evapi.time_ = ev_time;
394 evapi.sleep = ev_sleep; 396 evapi.sleep_ = ev_sleep;
395 evapi.loop_new = ev_loop_new; 397 evapi.loop_new = ev_loop_new;
396 evapi.loop_destroy = ev_loop_destroy; 398 evapi.loop_destroy = ev_loop_destroy;
397 evapi.loop_fork = ev_loop_fork; 399 evapi.loop_fork = ev_loop_fork;
398 evapi.loop_count = ev_loop_count; 400 evapi.loop_count = ev_loop_count;
399 evapi.now = ev_now; 401 evapi.now = ev_now;
426 evapi.embed_start = ev_embed_start; 428 evapi.embed_start = ev_embed_start;
427 evapi.embed_stop = ev_embed_stop; 429 evapi.embed_stop = ev_embed_stop;
428 evapi.embed_sweep = ev_embed_sweep; 430 evapi.embed_sweep = ev_embed_sweep;
429 evapi.fork_start = ev_fork_start; 431 evapi.fork_start = ev_fork_start;
430 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;
431 evapi.clear_pending = ev_clear_pending; 436 evapi.clear_pending = ev_clear_pending;
432 evapi.invoke = ev_invoke; 437 evapi.invoke = ev_invoke;
433 438
434 sv_setiv (sv, (IV)&evapi); 439 sv_setiv (sv, (IV)&evapi);
435 SvREADONLY_on (sv); 440 SvREADONLY_on (sv);
487 C_ARGS: evapi.default_loop, interval 492 C_ARGS: evapi.default_loop, interval
488 493
489void ev_loop (int flags = 0) 494void ev_loop (int flags = 0)
490 C_ARGS: evapi.default_loop, flags 495 C_ARGS: evapi.default_loop, flags
491 496
492void ev_unloop (int how = 1) 497void ev_unloop (int how = EVUNLOOP_ONE)
493 C_ARGS: evapi.default_loop, how 498 C_ARGS: evapi.default_loop, how
494 499
495void ev_feed_fd_event (int fd, int revents = EV_NONE) 500void ev_feed_fd_event (int fd, int revents = EV_NONE)
496 C_ARGS: evapi.default_loop, fd, revents 501 C_ARGS: evapi.default_loop, fd, revents
497 502
602 ev_fork_set (RETVAL); 607 ev_fork_set (RETVAL);
603 if (!ix) START (fork, RETVAL); 608 if (!ix) START (fork, RETVAL);
604 OUTPUT: 609 OUTPUT:
605 RETVAL 610 RETVAL
606 611
607ev_child *child (int pid, SV *cb) 612ev_child *child (int pid, int trace, SV *cb)
608 ALIAS: 613 ALIAS:
609 child_ns = 1 614 child_ns = 1
610 CODE: 615 CODE:
611 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 616 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
612 ev_child_set (RETVAL, pid); 617 ev_child_set (RETVAL, pid, trace);
613 if (!ix) START (child, RETVAL); 618 if (!ix) START (child, RETVAL);
614 OUTPUT: 619 OUTPUT:
615 RETVAL 620 RETVAL
616 621
617ev_stat *stat (SV *path, NV interval, SV *cb) 622ev_stat *stat (SV *path, NV interval, SV *cb)
639 644
640 if (!SvOK (cb)) ev_set_cb (RETVAL, 0); 645 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
641 646
642 if (!ix) START (embed, RETVAL); 647 if (!ix) START (embed, RETVAL);
643} 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);
644 OUTPUT: 659 OUTPUT:
645 RETVAL 660 RETVAL
646 661
647void once (SV *fh, int events, SV *timeout, SV *cb) 662void once (SV *fh, int events, SV *timeout, SV *cb)
648 CODE: 663 CODE:
672 C_ARGS: e_loop (w), w, revents 687 C_ARGS: e_loop (w), w, revents
673 688
674int keepalive (ev_watcher *w, int new_value = 0) 689int keepalive (ev_watcher *w, int new_value = 0)
675 CODE: 690 CODE:
676{ 691{
677 RETVAL = w->flags & WFLAG_KEEPALIVE; 692 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
678 new_value = new_value ? WFLAG_KEEPALIVE : 0; 693 new_value = new_value ? WFLAG_KEEPALIVE : 0;
679 694
680 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 695 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
681 { 696 {
682 REF (w); 697 REF (w);
683 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 698 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
684 UNREF (w); 699 UNREF (w);
685 } 700 }
686} 701}
687 OUTPUT: 702 OUTPUT:
688 RETVAL 703 RETVAL
874 INIT: 889 INIT:
875 CHECK_REPEAT (repeat); 890 CHECK_REPEAT (repeat);
876 CODE: 891 CODE:
877 RESET (timer, w, (w, after, repeat)); 892 RESET (timer, w, (w, after, repeat));
878 893
879NV at (ev_timer *w)
880 CODE:
881 RETVAL = w->at;
882 OUTPUT:
883 RETVAL
884
885MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 894MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
886 895
887void ev_periodic_start (ev_periodic *w) 896void ev_periodic_start (ev_periodic *w)
888 INIT: 897 INIT:
889 CHECK_REPEAT (w->interval); 898 CHECK_REPEAT (w->interval);
916 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 925 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
917} 926}
918 927
919NV at (ev_periodic *w) 928NV at (ev_periodic *w)
920 CODE: 929 CODE:
921 RETVAL = w->at; 930 RETVAL = ev_periodic_at (w);
922 OUTPUT: 931 OUTPUT:
923 RETVAL 932 RETVAL
924 933
925MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 934MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
926 935
995void DESTROY (ev_child *w) 1004void DESTROY (ev_child *w)
996 CODE: 1005 CODE:
997 STOP (child, w); 1006 STOP (child, w);
998 e_destroy (w); 1007 e_destroy (w);
999 1008
1000void set (ev_child *w, int pid) 1009void set (ev_child *w, int pid, int trace)
1001 CODE: 1010 CODE:
1002 RESET (child, w, (w, pid)); 1011 RESET (child, w, (w, pid, trace));
1003 1012
1004int pid (ev_child *w, int new_pid = 0)
1005 CODE:
1006{
1007 RETVAL = w->pid;
1008
1009 if (items > 1)
1010 RESET (child, w, (w, new_pid));
1011}
1012 OUTPUT:
1013 RETVAL
1014
1015
1016int rstatus (ev_child *w) 1013int pid (ev_child *w)
1017 ALIAS: 1014 ALIAS:
1018 rpid = 1 1015 rpid = 1
1016 rstatus = 2
1019 CODE: 1017 CODE:
1020 RETVAL = ix ? w->rpid : w->rstatus; 1018 RETVAL = ix == 0 ? w->pid
1019 : ix == 1 ? w->rpid
1020 : w->rstatus;
1021 OUTPUT: 1021 OUTPUT:
1022 RETVAL 1022 RETVAL
1023 1023
1024MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1024MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1025 1025
1141 CODE: 1141 CODE:
1142 RETVAL = newSVsv (w->fh); 1142 RETVAL = newSVsv (w->fh);
1143 OUTPUT: 1143 OUTPUT:
1144 RETVAL 1144 RETVAL
1145 1145
1146void ev_embed_sweep (ev_embed *w)
1147 C_ARGS: e_loop (w), w
1148
1149MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1150
1151void ev_async_start (ev_async *w)
1152 CODE:
1153 START (async, w);
1154
1155void ev_async_stop (ev_async *w)
1156 CODE:
1157 STOP (async, w);
1158
1159void DESTROY (ev_async *w)
1160 CODE:
1161 STOP (async, w);
1162 e_destroy (w);
1163
1164void ev_async_send (ev_async *w)
1165 C_ARGS: e_loop (w), w
1166
1167SV *ev_async_async_pending (ev_async *w)
1168 CODE:
1169 RETVAL = boolSV (ev_async_pending (w));
1170 OUTPUT:
1171 RETVAL
1172
1146MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1173MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1147 1174
1148SV *new (SV *klass, unsigned int flags = 0) 1175SV *new (SV *klass, unsigned int flags = 0)
1149 CODE: 1176 CODE:
1150{ 1177{
1296 ev_fork_set (RETVAL); 1323 ev_fork_set (RETVAL);
1297 if (!ix) START (fork, RETVAL); 1324 if (!ix) START (fork, RETVAL);
1298 OUTPUT: 1325 OUTPUT:
1299 RETVAL 1326 RETVAL
1300 1327
1301ev_child *child (struct ev_loop *loop, int pid, SV *cb) 1328ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1302 ALIAS: 1329 ALIAS:
1303 child_ns = 1 1330 child_ns = 1
1304 CODE: 1331 CODE:
1305 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1332 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1306 ev_child_set (RETVAL, pid); 1333 ev_child_set (RETVAL, pid, trace);
1307 if (!ix) START (child, RETVAL); 1334 if (!ix) START (child, RETVAL);
1308 OUTPUT: 1335 OUTPUT:
1309 RETVAL 1336 RETVAL
1310 1337
1311ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1338ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1333 1360
1334 if (!SvOK (cb)) ev_set_cb (RETVAL, 0); 1361 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1335 1362
1336 if (!ix) START (embed, RETVAL); 1363 if (!ix) START (embed, RETVAL);
1337} 1364}
1365 OUTPUT:
1366 RETVAL
1367
1368ev_async *async (struct ev_loop *loop, SV *cb)
1369 ALIAS:
1370 async_ns = 1
1371 CODE:
1372 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1373 ev_async_set (RETVAL);
1374 if (!ix) START (async, RETVAL);
1338 OUTPUT: 1375 OUTPUT:
1339 RETVAL 1376 RETVAL
1340 1377
1341void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) 1378void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1342 CODE: 1379 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines