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

Comparing EV/EV.xs (file contents):
Revision 1.105 by root, Thu Jan 31 20:10:28 2008 UTC vs.
Revision 1.113 by root, Thu May 22 02:44: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
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)
126 return SvIV (fh); 127 return SvIV (fh);
127 128
128 return -1; 129 return -1;
129} 130}
130 131
132static SV *
133e_get_cv (SV *cb_sv)
134{
135 HV *st;
136 GV *gvp;
137 CV *cv = sv_2cv (cb_sv, &st, &gvp, 0);
138
139 if (!cv)
140 croak ("EV watcher callback must be a CODE reference");
141
142 return (SV *)cv;
143}
144
131static void * 145static void *
132e_new (int size, SV *cb_sv, SV *loop) 146e_new (int size, SV *cb_sv, SV *loop)
133{ 147{
148 SV *cv = e_get_cv (cb_sv);
134 ev_watcher *w; 149 ev_watcher *w;
135 SV *self = NEWSV (0, size); 150 SV *self = NEWSV (0, size);
136 SvPOK_only (self); 151 SvPOK_only (self);
137 SvCUR_set (self, size); 152 SvCUR_set (self, size);
138 153
142 157
143 w->loop = SvREFCNT_inc (SvRV (loop)); 158 w->loop = SvREFCNT_inc (SvRV (loop));
144 w->e_flags = WFLAG_KEEPALIVE; 159 w->e_flags = WFLAG_KEEPALIVE;
145 w->data = 0; 160 w->data = 0;
146 w->fh = 0; 161 w->fh = 0;
147 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); 162 w->cb_sv = SvREFCNT_inc (cv);
148 w->self = self; 163 w->self = self;
149 164
150 return (void *)w; 165 return (void *)w;
151} 166}
152 167
375 stash_check = gv_stashpv ("EV::Check" , 1); 390 stash_check = gv_stashpv ("EV::Check" , 1);
376 stash_child = gv_stashpv ("EV::Child" , 1); 391 stash_child = gv_stashpv ("EV::Child" , 1);
377 stash_embed = gv_stashpv ("EV::Embed" , 1); 392 stash_embed = gv_stashpv ("EV::Embed" , 1);
378 stash_stat = gv_stashpv ("EV::Stat" , 1); 393 stash_stat = gv_stashpv ("EV::Stat" , 1);
379 stash_fork = gv_stashpv ("EV::Fork" , 1); 394 stash_fork = gv_stashpv ("EV::Fork" , 1);
395 stash_async = gv_stashpv ("EV::Async" , 1);
380 396
381 { 397 {
382 SV *sv = perl_get_sv ("EV::API", TRUE); 398 SV *sv = perl_get_sv ("EV::API", TRUE);
383 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 399 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
384 400
388 evapi.sv_fileno = sv_fileno; 404 evapi.sv_fileno = sv_fileno;
389 evapi.sv_signum = sv_signum; 405 evapi.sv_signum = sv_signum;
390 evapi.supported_backends = ev_supported_backends (); 406 evapi.supported_backends = ev_supported_backends ();
391 evapi.recommended_backends = ev_recommended_backends (); 407 evapi.recommended_backends = ev_recommended_backends ();
392 evapi.embeddable_backends = ev_embeddable_backends (); 408 evapi.embeddable_backends = ev_embeddable_backends ();
393 evapi.time = ev_time; 409 evapi.time_ = ev_time;
394 evapi.sleep = ev_sleep; 410 evapi.sleep_ = ev_sleep;
395 evapi.loop_new = ev_loop_new; 411 evapi.loop_new = ev_loop_new;
396 evapi.loop_destroy = ev_loop_destroy; 412 evapi.loop_destroy = ev_loop_destroy;
397 evapi.loop_fork = ev_loop_fork; 413 evapi.loop_fork = ev_loop_fork;
398 evapi.loop_count = ev_loop_count; 414 evapi.loop_count = ev_loop_count;
399 evapi.now = ev_now; 415 evapi.now = ev_now;
645 if (!ix) START (embed, RETVAL); 661 if (!ix) START (embed, RETVAL);
646} 662}
647 OUTPUT: 663 OUTPUT:
648 RETVAL 664 RETVAL
649 665
666ev_async *async (SV *cb)
667 ALIAS:
668 async_ns = 1
669 CODE:
670 RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
671 ev_async_set (RETVAL);
672 if (!ix) START (async, RETVAL);
673 OUTPUT:
674 RETVAL
675
650void once (SV *fh, int events, SV *timeout, SV *cb) 676void once (SV *fh, int events, SV *timeout, SV *cb)
651 CODE: 677 CODE:
652 ev_once ( 678 ev_once (
653 evapi.default_loop, 679 evapi.default_loop,
654 sv_fileno (fh), events, 680 sv_fileno (fh), events,
691 RETVAL 717 RETVAL
692 718
693SV *cb (ev_watcher *w, SV *new_cb = 0) 719SV *cb (ev_watcher *w, SV *new_cb = 0)
694 CODE: 720 CODE:
695{ 721{
696 RETVAL = newSVsv (w->cb_sv);
697
698 if (items > 1) 722 if (items > 1)
699 sv_setsv (w->cb_sv, new_cb); 723 {
724 new_cb = e_get_cv (new_cb);
725 RETVAL = newRV_noinc (w->cb_sv);
726 w->cb_sv = SvREFCNT_inc (new_cb);
727 }
728 else
729 RETVAL = newRV_inc (w->cb_sv);
700} 730}
701 OUTPUT: 731 OUTPUT:
702 RETVAL 732 RETVAL
703 733
704SV *data (ev_watcher *w, SV *new_data = 0) 734SV *data (ev_watcher *w, SV *new_data = 0)
877 INIT: 907 INIT:
878 CHECK_REPEAT (repeat); 908 CHECK_REPEAT (repeat);
879 CODE: 909 CODE:
880 RESET (timer, w, (w, after, repeat)); 910 RESET (timer, w, (w, after, repeat));
881 911
882NV at (ev_timer *w)
883 CODE:
884 RETVAL = w->at;
885 OUTPUT:
886 RETVAL
887
888MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 912MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
889 913
890void ev_periodic_start (ev_periodic *w) 914void ev_periodic_start (ev_periodic *w)
891 INIT: 915 INIT:
892 CHECK_REPEAT (w->interval); 916 CHECK_REPEAT (w->interval);
919 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 943 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
920} 944}
921 945
922NV at (ev_periodic *w) 946NV at (ev_periodic *w)
923 CODE: 947 CODE:
924 RETVAL = w->at; 948 RETVAL = ev_periodic_at (w);
925 OUTPUT: 949 OUTPUT:
926 RETVAL 950 RETVAL
927 951
928MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 952MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
929 953
1135 CODE: 1159 CODE:
1136 RETVAL = newSVsv (w->fh); 1160 RETVAL = newSVsv (w->fh);
1137 OUTPUT: 1161 OUTPUT:
1138 RETVAL 1162 RETVAL
1139 1163
1164void ev_embed_sweep (ev_embed *w)
1165 C_ARGS: e_loop (w), w
1166
1167MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1168
1169void ev_async_start (ev_async *w)
1170 CODE:
1171 START (async, w);
1172
1173void ev_async_stop (ev_async *w)
1174 CODE:
1175 STOP (async, w);
1176
1177void DESTROY (ev_async *w)
1178 CODE:
1179 STOP (async, w);
1180 e_destroy (w);
1181
1182void ev_async_send (ev_async *w)
1183 C_ARGS: e_loop (w), w
1184
1185SV *ev_async_async_pending (ev_async *w)
1186 CODE:
1187 RETVAL = boolSV (ev_async_pending (w));
1188 OUTPUT:
1189 RETVAL
1190
1140MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1191MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1141 1192
1142SV *new (SV *klass, unsigned int flags = 0) 1193SV *new (SV *klass, unsigned int flags = 0)
1143 CODE: 1194 CODE:
1144{ 1195{
1156 CODE: 1207 CODE:
1157 if (loop != evapi.default_loop) /* global destruction sucks */ 1208 if (loop != evapi.default_loop) /* global destruction sucks */
1158 ev_loop_destroy (loop); 1209 ev_loop_destroy (loop);
1159 1210
1160void ev_loop_fork (struct ev_loop *loop) 1211void ev_loop_fork (struct ev_loop *loop)
1212
1213void ev_loop_verify (struct ev_loop *loop)
1161 1214
1162NV ev_now (struct ev_loop *loop) 1215NV ev_now (struct ev_loop *loop)
1163 1216
1164void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) 1217void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1165 1218
1327 1380
1328 if (!SvOK (cb)) ev_set_cb (RETVAL, 0); 1381 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1329 1382
1330 if (!ix) START (embed, RETVAL); 1383 if (!ix) START (embed, RETVAL);
1331} 1384}
1385 OUTPUT:
1386 RETVAL
1387
1388ev_async *async (struct ev_loop *loop, SV *cb)
1389 ALIAS:
1390 async_ns = 1
1391 CODE:
1392 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1393 ev_async_set (RETVAL);
1394 if (!ix) START (async, RETVAL);
1332 OUTPUT: 1395 OUTPUT:
1333 RETVAL 1396 RETVAL
1334 1397
1335void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) 1398void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1336 CODE: 1399 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines