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

Comparing EV/EV.xs (file contents):
Revision 1.101 by root, Sat Dec 22 05:47:51 2007 UTC vs.
Revision 1.110 by root, Tue Apr 15 04:41:57 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 { \
45 UNREF (w); \ 45 UNREF (w); \
46 ev_ ## type ## _start (e_loop (w), w); \ 46 ev_ ## type ## _start (e_loop (w), w); \
47 } while (0) 47 } while (0)
48 48
49#define STOP(type,w) \ 49#define STOP(type,w) \
50 do { \ 50 do { \
51 REF (w); \ 51 REF (w); \
52 ev_ ## type ## _stop (e_loop (w), w); \ 52 ev_ ## type ## _stop (e_loop (w), w); \
53 } while (0) 53 } while (0)
54 54
55#define RESET(type,w,seta) \ 55#define RESET(type,w,seta) \
56 do { \ 56 do { \
57 int active = ev_is_active (w); \ 57 int active = ev_is_active (w); \
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);
455 RETVAL = newSVsv (default_loop_sv); 460 RETVAL = newSVsv (default_loop_sv);
456} 461}
457 OUTPUT: 462 OUTPUT:
458 RETVAL 463 RETVAL
459 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 ()
476
460NV ev_time () 477NV ev_time ()
461 478
462NV ev_now () 479NV ev_now ()
463 C_ARGS: evapi.default_loop 480 C_ARGS: evapi.default_loop
464 481
475 C_ARGS: evapi.default_loop, interval 492 C_ARGS: evapi.default_loop, interval
476 493
477void ev_loop (int flags = 0) 494void ev_loop (int flags = 0)
478 C_ARGS: evapi.default_loop, flags 495 C_ARGS: evapi.default_loop, flags
479 496
480void ev_unloop (int how = 1) 497void ev_unloop (int how = EVUNLOOP_ONE)
481 C_ARGS: evapi.default_loop, how 498 C_ARGS: evapi.default_loop, how
482 499
483void ev_feed_fd_event (int fd, int revents = EV_NONE) 500void ev_feed_fd_event (int fd, int revents = EV_NONE)
484 C_ARGS: evapi.default_loop, fd, revents 501 C_ARGS: evapi.default_loop, fd, revents
485 502
590 ev_fork_set (RETVAL); 607 ev_fork_set (RETVAL);
591 if (!ix) START (fork, RETVAL); 608 if (!ix) START (fork, RETVAL);
592 OUTPUT: 609 OUTPUT:
593 RETVAL 610 RETVAL
594 611
595ev_child *child (int pid, SV *cb) 612ev_child *child (int pid, int trace, SV *cb)
596 ALIAS: 613 ALIAS:
597 child_ns = 1 614 child_ns = 1
598 CODE: 615 CODE:
599 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 616 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
600 ev_child_set (RETVAL, pid); 617 ev_child_set (RETVAL, pid, trace);
601 if (!ix) START (child, RETVAL); 618 if (!ix) START (child, RETVAL);
602 OUTPUT: 619 OUTPUT:
603 RETVAL 620 RETVAL
604 621
605ev_stat *stat (SV *path, NV interval, SV *cb) 622ev_stat *stat (SV *path, NV interval, SV *cb)
627 644
628 if (!SvOK (cb)) ev_set_cb (RETVAL, 0); 645 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
629 646
630 if (!ix) START (embed, RETVAL); 647 if (!ix) START (embed, RETVAL);
631} 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);
632 OUTPUT: 659 OUTPUT:
633 RETVAL 660 RETVAL
634 661
635void once (SV *fh, int events, SV *timeout, SV *cb) 662void once (SV *fh, int events, SV *timeout, SV *cb)
636 CODE: 663 CODE:
660 C_ARGS: e_loop (w), w, revents 687 C_ARGS: e_loop (w), w, revents
661 688
662int keepalive (ev_watcher *w, int new_value = 0) 689int keepalive (ev_watcher *w, int new_value = 0)
663 CODE: 690 CODE:
664{ 691{
665 RETVAL = w->flags & WFLAG_KEEPALIVE; 692 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
666 new_value = new_value ? WFLAG_KEEPALIVE : 0; 693 new_value = new_value ? WFLAG_KEEPALIVE : 0;
667 694
668 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 695 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
669 { 696 {
670 REF (w); 697 REF (w);
671 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 698 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
672 UNREF (w); 699 UNREF (w);
673 } 700 }
674} 701}
675 OUTPUT: 702 OUTPUT:
676 RETVAL 703 RETVAL
983void DESTROY (ev_child *w) 1010void DESTROY (ev_child *w)
984 CODE: 1011 CODE:
985 STOP (child, w); 1012 STOP (child, w);
986 e_destroy (w); 1013 e_destroy (w);
987 1014
988void set (ev_child *w, int pid) 1015void set (ev_child *w, int pid, int trace)
989 CODE: 1016 CODE:
990 RESET (child, w, (w, pid)); 1017 RESET (child, w, (w, pid, trace));
991 1018
992int pid (ev_child *w, int new_pid = 0)
993 CODE:
994{
995 RETVAL = w->pid;
996
997 if (items > 1)
998 RESET (child, w, (w, new_pid));
999}
1000 OUTPUT:
1001 RETVAL
1002
1003
1004int rstatus (ev_child *w) 1019int pid (ev_child *w)
1005 ALIAS: 1020 ALIAS:
1006 rpid = 1 1021 rpid = 1
1022 rstatus = 2
1007 CODE: 1023 CODE:
1008 RETVAL = ix ? w->rpid : w->rstatus; 1024 RETVAL = ix == 0 ? w->pid
1025 : ix == 1 ? w->rpid
1026 : w->rstatus;
1009 OUTPUT: 1027 OUTPUT:
1010 RETVAL 1028 RETVAL
1011 1029
1012MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1030MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1013 1031
1129 CODE: 1147 CODE:
1130 RETVAL = newSVsv (w->fh); 1148 RETVAL = newSVsv (w->fh);
1131 OUTPUT: 1149 OUTPUT:
1132 RETVAL 1150 RETVAL
1133 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
1134MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1179MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1135 1180
1136SV *new (SV *klass, unsigned int flags = 0) 1181SV *new (SV *klass, unsigned int flags = 0)
1137 CODE: 1182 CODE:
1138{ 1183{
1284 ev_fork_set (RETVAL); 1329 ev_fork_set (RETVAL);
1285 if (!ix) START (fork, RETVAL); 1330 if (!ix) START (fork, RETVAL);
1286 OUTPUT: 1331 OUTPUT:
1287 RETVAL 1332 RETVAL
1288 1333
1289ev_child *child (struct ev_loop *loop, int pid, SV *cb) 1334ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1290 ALIAS: 1335 ALIAS:
1291 child_ns = 1 1336 child_ns = 1
1292 CODE: 1337 CODE:
1293 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1338 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1294 ev_child_set (RETVAL, pid); 1339 ev_child_set (RETVAL, pid, trace);
1295 if (!ix) START (child, RETVAL); 1340 if (!ix) START (child, RETVAL);
1296 OUTPUT: 1341 OUTPUT:
1297 RETVAL 1342 RETVAL
1298 1343
1299ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1344ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1321 1366
1322 if (!SvOK (cb)) ev_set_cb (RETVAL, 0); 1367 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1323 1368
1324 if (!ix) START (embed, RETVAL); 1369 if (!ix) START (embed, RETVAL);
1325} 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);
1326 OUTPUT: 1381 OUTPUT:
1327 RETVAL 1382 RETVAL
1328 1383
1329void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) 1384void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1330 CODE: 1385 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines