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

Comparing EV/EV.xs (file contents):
Revision 1.99 by root, Fri Dec 21 05:30:25 2007 UTC vs.
Revision 1.105 by root, Thu Jan 31 20:10:28 2008 UTC

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 7#define EV_PROTOTYPES 1
8#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
8#define EV_H <ev.h> 9#define EV_H <ev.h>
9#include "EV/EVAPI.h" 10#include "EV/EVAPI.h"
10 11
11/* fix perl api breakage */ 12/* fix perl api breakage */
12#undef signal 13#undef signal
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); \
137 138
138 w = (ev_watcher *)SvPVX (self); 139 w = (ev_watcher *)SvPVX (self);
139 140
140 ev_init (w, e_cb); 141 ev_init (w, e_cb);
141 142
142 w->loop = SvREFCNT_inc (SvRV (loop)); 143 w->loop = SvREFCNT_inc (SvRV (loop));
143 w->flags = WFLAG_KEEPALIVE; 144 w->e_flags = WFLAG_KEEPALIVE;
144 w->data = 0; 145 w->data = 0;
145 w->fh = 0; 146 w->fh = 0;
146 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); 147 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv);
147 w->self = self; 148 w->self = self;
148 149
149 return (void *)w; 150 return (void *)w;
150} 151}
151 152
152static void 153static void
388 evapi.sv_signum = sv_signum; 389 evapi.sv_signum = sv_signum;
389 evapi.supported_backends = ev_supported_backends (); 390 evapi.supported_backends = ev_supported_backends ();
390 evapi.recommended_backends = ev_recommended_backends (); 391 evapi.recommended_backends = ev_recommended_backends ();
391 evapi.embeddable_backends = ev_embeddable_backends (); 392 evapi.embeddable_backends = ev_embeddable_backends ();
392 evapi.time = ev_time; 393 evapi.time = ev_time;
394 evapi.sleep = ev_sleep;
393 evapi.loop_new = ev_loop_new; 395 evapi.loop_new = ev_loop_new;
394 evapi.loop_destroy = ev_loop_destroy; 396 evapi.loop_destroy = ev_loop_destroy;
395 evapi.loop_fork = ev_loop_fork; 397 evapi.loop_fork = ev_loop_fork;
396 evapi.loop_count = ev_loop_count; 398 evapi.loop_count = ev_loop_count;
397 evapi.now = ev_now; 399 evapi.now = ev_now;
424 evapi.embed_start = ev_embed_start; 426 evapi.embed_start = ev_embed_start;
425 evapi.embed_stop = ev_embed_stop; 427 evapi.embed_stop = ev_embed_stop;
426 evapi.embed_sweep = ev_embed_sweep; 428 evapi.embed_sweep = ev_embed_sweep;
427 evapi.fork_start = ev_fork_start; 429 evapi.fork_start = ev_fork_start;
428 evapi.fork_stop = ev_fork_stop; 430 evapi.fork_stop = ev_fork_stop;
431 evapi.async_start = ev_async_start;
432 evapi.async_stop = ev_async_stop;
433 evapi.async_send = ev_async_send;
429 evapi.clear_pending = ev_clear_pending; 434 evapi.clear_pending = ev_clear_pending;
430 evapi.invoke = ev_invoke; 435 evapi.invoke = ev_invoke;
431 436
432 sv_setiv (sv, (IV)&evapi); 437 sv_setiv (sv, (IV)&evapi);
433 SvREADONLY_on (sv); 438 SvREADONLY_on (sv);
453 RETVAL = newSVsv (default_loop_sv); 458 RETVAL = newSVsv (default_loop_sv);
454} 459}
455 OUTPUT: 460 OUTPUT:
456 RETVAL 461 RETVAL
457 462
463void ev_default_destroy ()
464 CODE:
465 ev_default_destroy ();
466 SvREFCNT_dec (default_loop_sv);
467 default_loop_sv = 0;
468
469unsigned int ev_supported_backends ()
470
471unsigned int ev_recommended_backends ()
472
473unsigned int ev_embeddable_backends ()
474
458NV ev_time () 475NV ev_time ()
459 476
460NV ev_now () 477NV ev_now ()
461 C_ARGS: evapi.default_loop 478 C_ARGS: evapi.default_loop
462 479
464 C_ARGS: evapi.default_loop 481 C_ARGS: evapi.default_loop
465 482
466unsigned int ev_loop_count () 483unsigned int ev_loop_count ()
467 C_ARGS: evapi.default_loop 484 C_ARGS: evapi.default_loop
468 485
486void ev_set_io_collect_interval (NV interval)
487 C_ARGS: evapi.default_loop, interval
488
489void ev_set_timeout_collect_interval (NV interval)
490 C_ARGS: evapi.default_loop, interval
491
469void ev_loop (int flags = 0) 492void ev_loop (int flags = 0)
470 C_ARGS: evapi.default_loop, flags 493 C_ARGS: evapi.default_loop, flags
471 494
472void ev_unloop (int how = 1) 495void ev_unloop (int how = EVUNLOOP_ONE)
473 C_ARGS: evapi.default_loop, how 496 C_ARGS: evapi.default_loop, how
474 497
475void ev_feed_fd_event (int fd, int revents = EV_NONE) 498void ev_feed_fd_event (int fd, int revents = EV_NONE)
476 C_ARGS: evapi.default_loop, fd, revents 499 C_ARGS: evapi.default_loop, fd, revents
477 500
582 ev_fork_set (RETVAL); 605 ev_fork_set (RETVAL);
583 if (!ix) START (fork, RETVAL); 606 if (!ix) START (fork, RETVAL);
584 OUTPUT: 607 OUTPUT:
585 RETVAL 608 RETVAL
586 609
587ev_child *child (int pid, SV *cb) 610ev_child *child (int pid, int trace, SV *cb)
588 ALIAS: 611 ALIAS:
589 child_ns = 1 612 child_ns = 1
590 CODE: 613 CODE:
591 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 614 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
592 ev_child_set (RETVAL, pid); 615 ev_child_set (RETVAL, pid, trace);
593 if (!ix) START (child, RETVAL); 616 if (!ix) START (child, RETVAL);
594 OUTPUT: 617 OUTPUT:
595 RETVAL 618 RETVAL
596 619
597ev_stat *stat (SV *path, NV interval, SV *cb) 620ev_stat *stat (SV *path, NV interval, SV *cb)
652 C_ARGS: e_loop (w), w, revents 675 C_ARGS: e_loop (w), w, revents
653 676
654int keepalive (ev_watcher *w, int new_value = 0) 677int keepalive (ev_watcher *w, int new_value = 0)
655 CODE: 678 CODE:
656{ 679{
657 RETVAL = w->flags & WFLAG_KEEPALIVE; 680 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
658 new_value = new_value ? WFLAG_KEEPALIVE : 0; 681 new_value = new_value ? WFLAG_KEEPALIVE : 0;
659 682
660 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 683 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
661 { 684 {
662 REF (w); 685 REF (w);
663 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 686 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
664 UNREF (w); 687 UNREF (w);
665 } 688 }
666} 689}
667 OUTPUT: 690 OUTPUT:
668 RETVAL 691 RETVAL
915void DESTROY (ev_idle *w) 938void DESTROY (ev_idle *w)
916 CODE: 939 CODE:
917 STOP (idle, w); 940 STOP (idle, w);
918 e_destroy (w); 941 e_destroy (w);
919 942
920MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 943MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
921 944
922void ev_prepare_start (ev_prepare *w) 945void ev_prepare_start (ev_prepare *w)
923 CODE: 946 CODE:
924 START (prepare, w); 947 START (prepare, w);
925 948
975void DESTROY (ev_child *w) 998void DESTROY (ev_child *w)
976 CODE: 999 CODE:
977 STOP (child, w); 1000 STOP (child, w);
978 e_destroy (w); 1001 e_destroy (w);
979 1002
980void set (ev_child *w, int pid) 1003void set (ev_child *w, int pid, int trace)
981 CODE: 1004 CODE:
982 RESET (child, w, (w, pid)); 1005 RESET (child, w, (w, pid, trace));
983 1006
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) 1007int pid (ev_child *w)
997 ALIAS: 1008 ALIAS:
998 rpid = 1 1009 rpid = 1
1010 rstatus = 2
999 CODE: 1011 CODE:
1000 RETVAL = ix ? w->rpid : w->rstatus; 1012 RETVAL = ix == 0 ? w->pid
1013 : ix == 1 ? w->rpid
1014 : w->rstatus;
1001 OUTPUT: 1015 OUTPUT:
1002 RETVAL 1016 RETVAL
1003 1017
1004MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1018MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1005 1019
1145 1159
1146void ev_loop_fork (struct ev_loop *loop) 1160void ev_loop_fork (struct ev_loop *loop)
1147 1161
1148NV ev_now (struct ev_loop *loop) 1162NV ev_now (struct ev_loop *loop)
1149 1163
1164void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1165
1166void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1167
1150unsigned int ev_backend (struct ev_loop *loop) 1168unsigned int ev_backend (struct ev_loop *loop)
1151 1169
1152unsigned int ev_loop_count (struct ev_loop *loop) 1170unsigned int ev_loop_count (struct ev_loop *loop)
1153 1171
1154void ev_loop (struct ev_loop *loop, int flags = 0) 1172void ev_loop (struct ev_loop *loop, int flags = 0)
1272 ev_fork_set (RETVAL); 1290 ev_fork_set (RETVAL);
1273 if (!ix) START (fork, RETVAL); 1291 if (!ix) START (fork, RETVAL);
1274 OUTPUT: 1292 OUTPUT:
1275 RETVAL 1293 RETVAL
1276 1294
1277ev_child *child (struct ev_loop *loop, int pid, SV *cb) 1295ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1278 ALIAS: 1296 ALIAS:
1279 child_ns = 1 1297 child_ns = 1
1280 CODE: 1298 CODE:
1281 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1299 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1282 ev_child_set (RETVAL, pid); 1300 ev_child_set (RETVAL, pid, trace);
1283 if (!ix) START (child, RETVAL); 1301 if (!ix) START (child, RETVAL);
1284 OUTPUT: 1302 OUTPUT:
1285 RETVAL 1303 RETVAL
1286 1304
1287ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1305ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines