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

Comparing EV/EV.xs (file contents):
Revision 1.100 by root, Fri Dec 21 09:43:57 2007 UTC vs.
Revision 1.109 by root, Wed Apr 2 07:59:17 2008 UTC

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 6
7#define EV_PROTOTYPES 1
8#define EV_H <ev.h>
9#include "EV/EVAPI.h"
10
11/* fix perl api breakage */ 7/* fix perl api breakage */
12#undef signal 8#undef signal
13#undef sigaction 9#undef sigaction
10
11#define EV_PROTOTYPES 1
12#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
13#define EV_H <ev.h>
14#include "EV/EVAPI.h"
14 15
15#define EV_SELECT_IS_WINSOCKET 0 16#define EV_SELECT_IS_WINSOCKET 0
16#ifdef _WIN32 17#ifdef _WIN32
17# define EV_SELECT_USE_FD_SET 0 18# define EV_SELECT_USE_FD_SET 0
18# define NFDBITS PERL_NFDBITS 19# define NFDBITS PERL_NFDBITS
28#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
29 30
30#define WFLAG_KEEPALIVE 1 31#define WFLAG_KEEPALIVE 1
31 32
32#define UNREF(w) \ 33#define UNREF(w) \
33 if (!((w)->flags & WFLAG_KEEPALIVE) \ 34 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
34 && !ev_is_active (w)) \ 35 && !ev_is_active (w)) \
35 ev_unref (e_loop (w)); 36 ev_unref (e_loop (w));
36 37
37#define REF(w) \ 38#define REF(w) \
38 if (!((w)->flags & WFLAG_KEEPALIVE) \ 39 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
39 && ev_is_active (w)) \ 40 && ev_is_active (w)) \
40 ev_ref (e_loop (w)); 41 ev_ref (e_loop (w));
41 42
42#define START(type,w) \ 43#define START(type,w) \
43 do { \ 44 do { \
44 UNREF (w); \ 45 UNREF (w); \
45 ev_ ## type ## _start (e_loop (w), w); \ 46 ev_ ## type ## _start (e_loop (w), w); \
46 } while (0) 47 } while (0)
47 48
48#define STOP(type,w) \ 49#define STOP(type,w) \
49 do { \ 50 do { \
50 REF (w); \ 51 REF (w); \
51 ev_ ## type ## _stop (e_loop (w), w); \ 52 ev_ ## type ## _stop (e_loop (w), w); \
52 } while (0) 53 } while (0)
53 54
54#define RESET(type,w,seta) \ 55#define RESET(type,w,seta) \
55 do { \ 56 do { \
56 int active = ev_is_active (w); \ 57 int active = ev_is_active (w); \
76 *stash_stat, 77 *stash_stat,
77 *stash_idle, 78 *stash_idle,
78 *stash_prepare, 79 *stash_prepare,
79 *stash_check, 80 *stash_check,
80 *stash_embed, 81 *stash_embed,
81 *stash_fork; 82 *stash_fork,
83 *stash_async;
82 84
83#ifndef SIG_SIZE 85#ifndef SIG_SIZE
84/* kudos to Slaven Rezic for the idea */ 86/* kudos to Slaven Rezic for the idea */
85static char sig_size [] = { SIG_NUM }; 87static char sig_size [] = { SIG_NUM };
86# define SIG_SIZE (sizeof (sig_size) + 1) 88# define SIG_SIZE (sizeof (sig_size) + 1)
137 139
138 w = (ev_watcher *)SvPVX (self); 140 w = (ev_watcher *)SvPVX (self);
139 141
140 ev_init (w, e_cb); 142 ev_init (w, e_cb);
141 143
142 w->loop = SvREFCNT_inc (SvRV (loop)); 144 w->loop = SvREFCNT_inc (SvRV (loop));
143 w->flags = WFLAG_KEEPALIVE; 145 w->e_flags = WFLAG_KEEPALIVE;
144 w->data = 0; 146 w->data = 0;
145 w->fh = 0; 147 w->fh = 0;
146 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);
147 w->self = self; 149 w->self = self;
148 150
149 return (void *)w; 151 return (void *)w;
150} 152}
151 153
152static void 154static void
374 stash_check = gv_stashpv ("EV::Check" , 1); 376 stash_check = gv_stashpv ("EV::Check" , 1);
375 stash_child = gv_stashpv ("EV::Child" , 1); 377 stash_child = gv_stashpv ("EV::Child" , 1);
376 stash_embed = gv_stashpv ("EV::Embed" , 1); 378 stash_embed = gv_stashpv ("EV::Embed" , 1);
377 stash_stat = gv_stashpv ("EV::Stat" , 1); 379 stash_stat = gv_stashpv ("EV::Stat" , 1);
378 stash_fork = gv_stashpv ("EV::Fork" , 1); 380 stash_fork = gv_stashpv ("EV::Fork" , 1);
381 stash_async = gv_stashpv ("EV::Async" , 1);
379 382
380 { 383 {
381 SV *sv = perl_get_sv ("EV::API", TRUE); 384 SV *sv = perl_get_sv ("EV::API", TRUE);
382 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 385 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
383 386
387 evapi.sv_fileno = sv_fileno; 390 evapi.sv_fileno = sv_fileno;
388 evapi.sv_signum = sv_signum; 391 evapi.sv_signum = sv_signum;
389 evapi.supported_backends = ev_supported_backends (); 392 evapi.supported_backends = ev_supported_backends ();
390 evapi.recommended_backends = ev_recommended_backends (); 393 evapi.recommended_backends = ev_recommended_backends ();
391 evapi.embeddable_backends = ev_embeddable_backends (); 394 evapi.embeddable_backends = ev_embeddable_backends ();
392 evapi.time = ev_time; 395 evapi.time_ = ev_time;
396 evapi.sleep_ = ev_sleep;
393 evapi.loop_new = ev_loop_new; 397 evapi.loop_new = ev_loop_new;
394 evapi.loop_destroy = ev_loop_destroy; 398 evapi.loop_destroy = ev_loop_destroy;
395 evapi.loop_fork = ev_loop_fork; 399 evapi.loop_fork = ev_loop_fork;
396 evapi.loop_count = ev_loop_count; 400 evapi.loop_count = ev_loop_count;
397 evapi.now = ev_now; 401 evapi.now = ev_now;
424 evapi.embed_start = ev_embed_start; 428 evapi.embed_start = ev_embed_start;
425 evapi.embed_stop = ev_embed_stop; 429 evapi.embed_stop = ev_embed_stop;
426 evapi.embed_sweep = ev_embed_sweep; 430 evapi.embed_sweep = ev_embed_sweep;
427 evapi.fork_start = ev_fork_start; 431 evapi.fork_start = ev_fork_start;
428 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;
429 evapi.clear_pending = ev_clear_pending; 436 evapi.clear_pending = ev_clear_pending;
430 evapi.invoke = ev_invoke; 437 evapi.invoke = ev_invoke;
431 438
432 sv_setiv (sv, (IV)&evapi); 439 sv_setiv (sv, (IV)&evapi);
433 SvREADONLY_on (sv); 440 SvREADONLY_on (sv);
453 RETVAL = newSVsv (default_loop_sv); 460 RETVAL = newSVsv (default_loop_sv);
454} 461}
455 OUTPUT: 462 OUTPUT:
456 RETVAL 463 RETVAL
457 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
458NV ev_time () 477NV ev_time ()
459 478
460NV ev_now () 479NV ev_now ()
461 C_ARGS: evapi.default_loop 480 C_ARGS: evapi.default_loop
462 481
464 C_ARGS: evapi.default_loop 483 C_ARGS: evapi.default_loop
465 484
466unsigned int ev_loop_count () 485unsigned int ev_loop_count ()
467 C_ARGS: evapi.default_loop 486 C_ARGS: evapi.default_loop
468 487
488void ev_set_io_collect_interval (NV interval)
489 C_ARGS: evapi.default_loop, interval
490
491void ev_set_timeout_collect_interval (NV interval)
492 C_ARGS: evapi.default_loop, interval
493
469void ev_loop (int flags = 0) 494void ev_loop (int flags = 0)
470 C_ARGS: evapi.default_loop, flags 495 C_ARGS: evapi.default_loop, flags
471 496
472void ev_unloop (int how = 1) 497void ev_unloop (int how = EVUNLOOP_ONE)
473 C_ARGS: evapi.default_loop, how 498 C_ARGS: evapi.default_loop, how
474 499
475void ev_feed_fd_event (int fd, int revents = EV_NONE) 500void ev_feed_fd_event (int fd, int revents = EV_NONE)
476 C_ARGS: evapi.default_loop, fd, revents 501 C_ARGS: evapi.default_loop, fd, revents
477 502
582 ev_fork_set (RETVAL); 607 ev_fork_set (RETVAL);
583 if (!ix) START (fork, RETVAL); 608 if (!ix) START (fork, RETVAL);
584 OUTPUT: 609 OUTPUT:
585 RETVAL 610 RETVAL
586 611
587ev_child *child (int pid, SV *cb) 612ev_child *child (int pid, int trace, SV *cb)
588 ALIAS: 613 ALIAS:
589 child_ns = 1 614 child_ns = 1
590 CODE: 615 CODE:
591 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 616 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
592 ev_child_set (RETVAL, pid); 617 ev_child_set (RETVAL, pid, trace);
593 if (!ix) START (child, RETVAL); 618 if (!ix) START (child, RETVAL);
594 OUTPUT: 619 OUTPUT:
595 RETVAL 620 RETVAL
596 621
597ev_stat *stat (SV *path, NV interval, SV *cb) 622ev_stat *stat (SV *path, NV interval, SV *cb)
619 644
620 if (!SvOK (cb)) ev_set_cb (RETVAL, 0); 645 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
621 646
622 if (!ix) START (embed, RETVAL); 647 if (!ix) START (embed, RETVAL);
623} 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);
624 OUTPUT: 659 OUTPUT:
625 RETVAL 660 RETVAL
626 661
627void once (SV *fh, int events, SV *timeout, SV *cb) 662void once (SV *fh, int events, SV *timeout, SV *cb)
628 CODE: 663 CODE:
652 C_ARGS: e_loop (w), w, revents 687 C_ARGS: e_loop (w), w, revents
653 688
654int keepalive (ev_watcher *w, int new_value = 0) 689int keepalive (ev_watcher *w, int new_value = 0)
655 CODE: 690 CODE:
656{ 691{
657 RETVAL = w->flags & WFLAG_KEEPALIVE; 692 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
658 new_value = new_value ? WFLAG_KEEPALIVE : 0; 693 new_value = new_value ? WFLAG_KEEPALIVE : 0;
659 694
660 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 695 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
661 { 696 {
662 REF (w); 697 REF (w);
663 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 698 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
664 UNREF (w); 699 UNREF (w);
665 } 700 }
666} 701}
667 OUTPUT: 702 OUTPUT:
668 RETVAL 703 RETVAL
975void DESTROY (ev_child *w) 1010void DESTROY (ev_child *w)
976 CODE: 1011 CODE:
977 STOP (child, w); 1012 STOP (child, w);
978 e_destroy (w); 1013 e_destroy (w);
979 1014
980void set (ev_child *w, int pid) 1015void set (ev_child *w, int pid, int trace)
981 CODE: 1016 CODE:
982 RESET (child, w, (w, pid)); 1017 RESET (child, w, (w, pid, trace));
983 1018
984int pid (ev_child *w, int new_pid = 0)
985 CODE:
986{
987 RETVAL = w->pid;
988
989 if (items > 1)
990 RESET (child, w, (w, new_pid));
991}
992 OUTPUT:
993 RETVAL
994
995
996int rstatus (ev_child *w) 1019int pid (ev_child *w)
997 ALIAS: 1020 ALIAS:
998 rpid = 1 1021 rpid = 1
1022 rstatus = 2
999 CODE: 1023 CODE:
1000 RETVAL = ix ? w->rpid : w->rstatus; 1024 RETVAL = ix == 0 ? w->pid
1025 : ix == 1 ? w->rpid
1026 : w->rstatus;
1001 OUTPUT: 1027 OUTPUT:
1002 RETVAL 1028 RETVAL
1003 1029
1004MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1030MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1005 1031
1121 CODE: 1147 CODE:
1122 RETVAL = newSVsv (w->fh); 1148 RETVAL = newSVsv (w->fh);
1123 OUTPUT: 1149 OUTPUT:
1124 RETVAL 1150 RETVAL
1125 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
1126MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1173MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1127 1174
1128SV *new (SV *klass, unsigned int flags = 0) 1175SV *new (SV *klass, unsigned int flags = 0)
1129 CODE: 1176 CODE:
1130{ 1177{
1144 ev_loop_destroy (loop); 1191 ev_loop_destroy (loop);
1145 1192
1146void ev_loop_fork (struct ev_loop *loop) 1193void ev_loop_fork (struct ev_loop *loop)
1147 1194
1148NV ev_now (struct ev_loop *loop) 1195NV ev_now (struct ev_loop *loop)
1196
1197void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1198
1199void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1149 1200
1150unsigned int ev_backend (struct ev_loop *loop) 1201unsigned int ev_backend (struct ev_loop *loop)
1151 1202
1152unsigned int ev_loop_count (struct ev_loop *loop) 1203unsigned int ev_loop_count (struct ev_loop *loop)
1153 1204
1272 ev_fork_set (RETVAL); 1323 ev_fork_set (RETVAL);
1273 if (!ix) START (fork, RETVAL); 1324 if (!ix) START (fork, RETVAL);
1274 OUTPUT: 1325 OUTPUT:
1275 RETVAL 1326 RETVAL
1276 1327
1277ev_child *child (struct ev_loop *loop, int pid, SV *cb) 1328ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1278 ALIAS: 1329 ALIAS:
1279 child_ns = 1 1330 child_ns = 1
1280 CODE: 1331 CODE:
1281 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1332 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1282 ev_child_set (RETVAL, pid); 1333 ev_child_set (RETVAL, pid, trace);
1283 if (!ix) START (child, RETVAL); 1334 if (!ix) START (child, RETVAL);
1284 OUTPUT: 1335 OUTPUT:
1285 RETVAL 1336 RETVAL
1286 1337
1287ev_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)
1309 1360
1310 if (!SvOK (cb)) ev_set_cb (RETVAL, 0); 1361 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1311 1362
1312 if (!ix) START (embed, RETVAL); 1363 if (!ix) START (embed, RETVAL);
1313} 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);
1314 OUTPUT: 1375 OUTPUT:
1315 RETVAL 1376 RETVAL
1316 1377
1317void 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)
1318 CODE: 1379 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines