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

Comparing EV/EV.xs (file contents):
Revision 1.30 by root, Thu Nov 1 08:10:03 2007 UTC vs.
Revision 1.117 by root, Wed Oct 29 14:12:34 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 TIMEOUT_NONE HUGE_VAL 7/* fix perl api breakage */
8#define EV_USE_EPOLL 1 8#undef signal
9#undef sigaction
9 10
10#define EV_PROTOTYPES 1 11#define EV_PROTOTYPES 1
12#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
13#define EV_H <ev.h>
11#include "EV/EVAPI.h" 14#include "EV/EVAPI.h"
12 15
16#define EV_SELECT_IS_WINSOCKET 0
17#ifdef _WIN32
18# define EV_SELECT_USE_FD_SET 0
19# define NFDBITS PERL_NFDBITS
20# define fd_mask Perl_fd_mask
21#endif
22/* due to bugs in OS X we have to use libev/ explicitly here */
13#include "libev/ev.c" 23#include "libev/ev.c"
14 24
25#ifndef _WIN32
26# include <pthread.h>
27#endif
28
29/* 5.10.0 */
30#ifndef SvREFCNT_inc_NN
31# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv)
32#endif
33
34#if __GNUC__ >= 3
35# define expect(expr,value) __builtin_expect ((expr),(value))
36#else
37# define expect(expr,value) (expr)
38#endif
39
40#define expect_false(expr) expect ((expr) != 0, 0)
41#define expect_true(expr) expect ((expr) != 0, 1)
42
43#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
44
45#define WFLAG_KEEPALIVE 1
46
47#define UNREF(w) \
48 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
49 && !ev_is_active (w)) \
50 ev_unref (e_loop (w));
51
52#define REF(w) \
53 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
54 && ev_is_active (w)) \
55 ev_ref (e_loop (w));
56
57#define START(type,w) \
58 do { \
59 UNREF (w); \
60 ev_ ## type ## _start (e_loop (w), w); \
61 } while (0)
62
63#define STOP(type,w) \
64 do { \
65 REF (w); \
66 ev_ ## type ## _stop (e_loop (w), w); \
67 } while (0)
68
69#define RESET(type,w,seta) \
70 do { \
71 int active = ev_is_active (w); \
72 if (active) STOP (type, w); \
73 ev_ ## type ## _set seta; \
74 if (active) START (type, w); \
75 } while (0)
76
15typedef int Signal; 77typedef int Signal;
16 78
79static SV *default_loop_sv;
80
17static struct EVAPI evapi; 81static struct EVAPI evapi;
18 82
19static HV 83static HV
84 *stash_loop,
20 *stash_watcher, 85 *stash_watcher,
21 *stash_io, 86 *stash_io,
22 *stash_timer, 87 *stash_timer,
23 *stash_periodic, 88 *stash_periodic,
24 *stash_signal, 89 *stash_signal,
90 *stash_child,
91 *stash_stat,
25 *stash_idle, 92 *stash_idle,
26 *stash_prepare, 93 *stash_prepare,
27 *stash_check, 94 *stash_check,
28 *stash_child; 95 *stash_embed,
96 *stash_fork,
97 *stash_async;
29 98
99#ifndef SIG_SIZE
100/* kudos to Slaven Rezic for the idea */
101static char sig_size [] = { SIG_NUM };
102# define SIG_SIZE (sizeof (sig_size) + 1)
103#endif
104
30static int 105static Signal
31sv_signum (SV *sig) 106sv_signum (SV *sig)
32{ 107{
33 int signum; 108 Signal signum;
34 109
35 if (SvIV (sig) > 0) 110 SvGETMAGIC (sig);
36 return SvIV (sig);
37 111
38 for (signum = 1; signum < SIG_SIZE; ++signum) 112 for (signum = 1; signum < SIG_SIZE; ++signum)
39 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 113 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
40 return signum; 114 return signum;
41 115
116 signum = SvIV (sig);
117
118 if (signum > 0 && signum < SIG_SIZE)
119 return signum;
120
42 return -1; 121 return -1;
43} 122}
44 123
45///////////////////////////////////////////////////////////////////////////// 124/////////////////////////////////////////////////////////////////////////////
46// Event 125// Event
47 126
48static void e_cb (struct ev_watcher *w, int revents); 127static void e_cb (EV_P_ ev_watcher *w, int revents);
49 128
50static int 129static int
51sv_fileno (SV *fh) 130sv_fileno (SV *fh)
52{ 131{
53 SvGETMAGIC (fh); 132 SvGETMAGIC (fh);
56 fh = SvRV (fh); 135 fh = SvRV (fh);
57 136
58 if (SvTYPE (fh) == SVt_PVGV) 137 if (SvTYPE (fh) == SVt_PVGV)
59 return PerlIO_fileno (IoIFP (sv_2io (fh))); 138 return PerlIO_fileno (IoIFP (sv_2io (fh)));
60 139
61 if (SvIOK (fh)) 140 if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL))
62 return SvIV (fh); 141 return SvIV (fh);
63 142
64 return -1; 143 return -1;
65} 144}
66 145
146static SV *
147e_get_cv (SV *cb_sv)
148{
149 HV *st;
150 GV *gvp;
151 CV *cv = sv_2cv (cb_sv, &st, &gvp, 0);
152
153 if (!cv)
154 croak ("EV watcher callback must be a CODE reference");
155
156 return (SV *)cv;
157}
158
67static void * 159static void *
68e_new (int size, SV *cb_sv) 160e_new (int size, SV *cb_sv, SV *loop)
69{ 161{
162 SV *cv = cb_sv ? e_get_cv (cb_sv) : 0;
70 struct ev_watcher *w; 163 ev_watcher *w;
71 SV *self = NEWSV (0, size); 164 SV *self = NEWSV (0, size);
72 SvPOK_only (self); 165 SvPOK_only (self);
73 SvCUR_set (self, size); 166 SvCUR_set (self, size);
74 167
75 w = (struct ev_watcher *)SvPVX (self); 168 w = (ev_watcher *)SvPVX (self);
76 169
77 ev_watcher_init (w, e_cb); 170 ev_init (w, cv ? e_cb : 0);
78 171
172 w->loop = SvREFCNT_inc (SvRV (loop));
173 w->e_flags = WFLAG_KEEPALIVE;
174 w->data = 0;
79 w->fh = 0; 175 w->fh = 0;
80 w->cb_sv = newSVsv (cb_sv); 176 w->cb_sv = SvREFCNT_inc (cv);
81 w->self = self; 177 w->self = self;
82 178
83 return (void *)w; 179 return (void *)w;
84} 180}
85 181
182static void
183e_destroy (void *w_)
184{
185 ev_watcher *w = (ev_watcher *)w_;
186
187 SvREFCNT_dec (w->loop ); w->loop = 0;
188 SvREFCNT_dec (w->fh ); w->fh = 0;
189 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
190 SvREFCNT_dec (w->data ); w->data = 0;
191}
192
86static SV * 193static SV *
87e_bless (struct ev_watcher *w, HV *stash) 194e_bless (ev_watcher *w, HV *stash)
88{ 195{
89 SV *rv; 196 SV *rv;
90 197
91 if (SvOBJECT (w->self)) 198 if (SvOBJECT (w->self))
92 rv = newRV_inc (w->self); 199 rv = newRV_inc (w->self);
98 } 205 }
99 206
100 return rv; 207 return rv;
101} 208}
102 209
210static SV *sv_self_cache, *sv_events_cache;
211
103static void 212static void
104e_cb (struct ev_watcher *w, int revents) 213e_cb (EV_P_ ev_watcher *w, int revents)
105{ 214{
106 dSP; 215 dSP;
107 I32 mark = SP - PL_stack_base; 216 I32 mark = SP - PL_stack_base;
108 SV *sv_self, *sv_events, *sv_status = 0; 217 SV *sv_self, *sv_events;
109 static SV *sv_events_cache;
110 218
219 if (expect_true (sv_self_cache))
220 {
221 sv_self = sv_self_cache; sv_self_cache = 0;
222 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
223 }
224 else
225 {
111 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 226 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
227 SvREADONLY_on (sv_self);
228 }
229
230 if (expect_true (sv_events_cache))
231 {
232 sv_events = sv_events_cache; sv_events_cache = 0;
233 SvIV_set (sv_events, revents);
234 }
235 else
236 {
237 sv_events = newSViv (revents);
238 SvREADONLY_on (sv_events);
239 }
240
241 PUSHMARK (SP);
242 EXTEND (SP, 2);
243 PUSHs (sv_self);
244 PUSHs (sv_events);
245
246 PUTBACK;
247 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
248
249 if (expect_false (sv_self_cache))
250 SvREFCNT_dec (sv_self);
251 else
252 {
253 SvREFCNT_dec (SvRV (sv_self));
254 SvRV_set (sv_self, &PL_sv_undef);
255 sv_self_cache = sv_self;
256 }
257
258 if (expect_false (sv_events_cache))
259 SvREFCNT_dec (sv_events);
260 else
261 sv_events_cache = sv_events;
262
263 if (SvTRUE (ERRSV))
264 {
265 SPAGAIN;
266 PUSHMARK (SP);
267 PUTBACK;
268 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
269 }
270
271 SP = PL_stack_base + mark;
272 PUTBACK;
273}
274
275static void
276e_once_cb (int revents, void *arg)
277{
278 dSP;
279 I32 mark = SP - PL_stack_base;
280 SV *sv_events;
112 281
113 if (sv_events_cache) 282 if (sv_events_cache)
114 { 283 {
115 sv_events = sv_events_cache; sv_events_cache = 0; 284 sv_events = sv_events_cache; sv_events_cache = 0;
116 SvIV_set (sv_events, revents); 285 SvIV_set (sv_events, revents);
117 } 286 }
118 else 287 else
119 sv_events = newSViv (revents); 288 sv_events = newSViv (revents);
120 289
121 PUSHMARK (SP); 290 PUSHMARK (SP);
122 EXTEND (SP, 2);
123 PUSHs (sv_self);
124 PUSHs (sv_events); 291 XPUSHs (sv_events);
125
126 if (revents & EV_CHILD)
127 XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status));
128 292
129 PUTBACK; 293 PUTBACK;
130 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 294 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
131 SP = PL_stack_base + mark; PUTBACK;
132 295
133 SvREFCNT_dec (sv_self); 296 SvREFCNT_dec ((SV *)arg);
134 SvREFCNT_dec (sv_status);
135 297
136 if (sv_events_cache) 298 if (sv_events_cache)
137 SvREFCNT_dec (sv_events); 299 SvREFCNT_dec (sv_events);
138 else 300 else
139 sv_events_cache = sv_events; 301 sv_events_cache = sv_events;
302
303 if (SvTRUE (ERRSV))
304 {
305 SPAGAIN;
306 PUSHMARK (SP);
307 PUTBACK;
308 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
309 }
310
311 SP = PL_stack_base + mark;
312 PUTBACK;
313}
314
315static ev_tstamp
316e_periodic_cb (ev_periodic *w, ev_tstamp now)
317{
318 ev_tstamp retval;
319 int count;
320 dSP;
321
322 ENTER;
323 SAVETMPS;
324
325 PUSHMARK (SP);
326 EXTEND (SP, 2);
327 PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */
328 PUSHs (newSVnv (now));
329
330 PUTBACK;
331 count = call_sv (w->fh, G_SCALAR | G_EVAL);
332 SPAGAIN;
140 333
141 if (SvTRUE (ERRSV)) 334 if (SvTRUE (ERRSV))
142 { 335 {
143 PUSHMARK (SP); 336 PUSHMARK (SP);
144 PUTBACK; 337 PUTBACK;
145 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 338 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
146 SP = PL_stack_base + mark; PUTBACK; 339 SPAGAIN;
147 } 340 }
148}
149 341
150#if 0 342 if (count > 0)
151/////////////////////////////////////////////////////////////////////////////
152// DNS
153
154static void
155dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
156{
157 dSP;
158 SV *cb = (SV *)arg;
159
160 ENTER;
161 SAVETMPS;
162 PUSHMARK (SP);
163 EXTEND (SP, count + 3);
164 PUSHs (sv_2mortal (newSViv (result)));
165
166 if (result == DNS_ERR_NONE && ttl >= 0)
167 { 343 {
168 int i; 344 retval = SvNV (TOPs);
169 345
170 PUSHs (sv_2mortal (newSViv (type))); 346 if (retval < now)
171 PUSHs (sv_2mortal (newSViv (ttl))); 347 retval = now;
172
173 for (i = 0; i < count; ++i)
174 switch (type)
175 {
176 case DNS_IPv6_AAAA:
177 PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16)));
178 break;
179 case DNS_IPv4_A:
180 PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4)));
181 break;
182 case DNS_PTR:
183 PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0)));
184 break;
185 }
186 } 348 }
187 349 else
188 PUTBACK; 350 retval = now;
189 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
190 351
191 FREETMPS; 352 FREETMPS;
192
193 if (SvTRUE (ERRSV))
194 {
195 PUSHMARK (SP);
196 PUTBACK;
197 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
198 }
199
200 LEAVE; 353 LEAVE;
354
355 return retval;
201} 356}
202#endif
203 357
204#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 358#define CHECK_REPEAT(repeat) if (repeat < 0.) \
205 croak (# repeat " value must be >= 0"); 359 croak (# repeat " value must be >= 0");
206 360
361#define CHECK_FD(fh,fd) if ((fd) < 0) \
362 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
363
364#define CHECK_SIG(sv,num) if ((num) < 0) \
365 croak ("illegal signal number or name: %s", SvPV_nolen (sv));
366
207///////////////////////////////////////////////////////////////////////////// 367/////////////////////////////////////////////////////////////////////////////
208// XS interface functions 368// XS interface functions
209 369
210MODULE = EV PACKAGE = EV PREFIX = ev_ 370MODULE = EV PACKAGE = EV PREFIX = ev_
211 371
212PROTOTYPES: ENABLE 372PROTOTYPES: ENABLE
213 373
214BOOT: 374BOOT:
215{ 375{
216 int i;
217 HV *stash = gv_stashpv ("EV", 1); 376 HV *stash = gv_stashpv ("EV", 1);
218 377
219 static const struct { 378 static const struct {
220 const char *name; 379 const char *name;
221 IV iv; 380 IV iv;
222 } *civ, const_iv[] = { 381 } *civ, const_iv[] = {
223# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 382# define const_iv(pfx, name) { # name, (IV) pfx ## name },
383 const_iv (EV_, MINPRI)
384 const_iv (EV_, MAXPRI)
385
224 const_iv (EV_, UNDEF) 386 const_iv (EV_, UNDEF)
225 const_iv (EV_, NONE) 387 const_iv (EV_, NONE)
226 const_iv (EV_, TIMEOUT) 388 const_iv (EV_, TIMEOUT)
227 const_iv (EV_, READ) 389 const_iv (EV_, READ)
228 const_iv (EV_, WRITE) 390 const_iv (EV_, WRITE)
231 const_iv (EV_, CHECK) 393 const_iv (EV_, CHECK)
232 const_iv (EV_, ERROR) 394 const_iv (EV_, ERROR)
233 395
234 const_iv (EV, LOOP_ONESHOT) 396 const_iv (EV, LOOP_ONESHOT)
235 const_iv (EV, LOOP_NONBLOCK) 397 const_iv (EV, LOOP_NONBLOCK)
236
237 const_iv (EV, METHOD_NONE) 398 const_iv (EV, UNLOOP_ONE)
399 const_iv (EV, UNLOOP_ALL)
400
238 const_iv (EV, METHOD_SELECT) 401 const_iv (EV, BACKEND_SELECT)
402 const_iv (EV, BACKEND_POLL)
239 const_iv (EV, METHOD_EPOLL) 403 const_iv (EV, BACKEND_EPOLL)
404 const_iv (EV, BACKEND_KQUEUE)
405 const_iv (EV, BACKEND_DEVPOLL)
406 const_iv (EV, BACKEND_PORT)
407 const_iv (EV, FLAG_AUTO)
408 const_iv (EV, FLAG_NOENV)
409 const_iv (EV, FLAG_FORKCHECK)
240 }; 410 };
241 411
242 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 412 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
243 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 413 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
244 414
415 stash_loop = gv_stashpv ("EV::Loop" , 1);
245 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 416 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
246 stash_io = gv_stashpv ("EV::Io" , 1); 417 stash_io = gv_stashpv ("EV::IO" , 1);
247 stash_timer = gv_stashpv ("EV::Timer" , 1); 418 stash_timer = gv_stashpv ("EV::Timer" , 1);
248 stash_periodic = gv_stashpv ("EV::Periodic", 1); 419 stash_periodic = gv_stashpv ("EV::Periodic", 1);
249 stash_signal = gv_stashpv ("EV::Signal" , 1); 420 stash_signal = gv_stashpv ("EV::Signal" , 1);
250 stash_idle = gv_stashpv ("EV::Idle" , 1); 421 stash_idle = gv_stashpv ("EV::Idle" , 1);
251 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 422 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
252 stash_check = gv_stashpv ("EV::Check" , 1); 423 stash_check = gv_stashpv ("EV::Check" , 1);
253 stash_child = gv_stashpv ("EV::Child" , 1); 424 stash_child = gv_stashpv ("EV::Child" , 1);
425 stash_embed = gv_stashpv ("EV::Embed" , 1);
426 stash_stat = gv_stashpv ("EV::Stat" , 1);
427 stash_fork = gv_stashpv ("EV::Fork" , 1);
428 stash_async = gv_stashpv ("EV::Async" , 1);
254 429
255 { 430 {
256 SV *sv = perl_get_sv ("EV::API", TRUE); 431 SV *sv = perl_get_sv ("EV::API", TRUE);
257 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 432 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
258 433
259 /* the poor man's shared library emulator */ 434 /* the poor man's shared library emulator */
260 evapi.ver = EV_API_VERSION; 435 evapi.ver = EV_API_VERSION;
261 evapi.rev = EV_API_REVISION; 436 evapi.rev = EV_API_REVISION;
262 evapi.sv_fileno = sv_fileno; 437 evapi.sv_fileno = sv_fileno;
263 evapi.sv_signum = sv_signum; 438 evapi.sv_signum = sv_signum;
264 evapi.now = &ev_now; 439 evapi.supported_backends = ev_supported_backends ();
265 evapi.method = &ev_method; 440 evapi.recommended_backends = ev_recommended_backends ();
266 evapi.loop_done = &ev_loop_done; 441 evapi.embeddable_backends = ev_embeddable_backends ();
267 evapi.time = ev_time; 442 evapi.time_ = ev_time;
443 evapi.sleep_ = ev_sleep;
444 evapi.loop_new = ev_loop_new;
445 evapi.loop_destroy = ev_loop_destroy;
446 evapi.loop_fork = ev_loop_fork;
447 evapi.loop_count = ev_loop_count;
448 evapi.now = ev_now;
449 evapi.now_update = ev_now_update;
450 evapi.backend = ev_backend;
451 evapi.unloop = ev_unloop;
452 evapi.ref = ev_ref;
453 evapi.unref = ev_unref;
268 evapi.loop = ev_loop; 454 evapi.loop = ev_loop;
269 evapi.once = ev_once; 455 evapi.once = ev_once;
270 evapi.io_start = ev_io_start; 456 evapi.io_start = ev_io_start;
271 evapi.io_stop = ev_io_stop; 457 evapi.io_stop = ev_io_stop;
272 evapi.timer_start = ev_timer_start; 458 evapi.timer_start = ev_timer_start;
273 evapi.timer_stop = ev_timer_stop; 459 evapi.timer_stop = ev_timer_stop;
274 evapi.timer_again = ev_timer_again; 460 evapi.timer_again = ev_timer_again;
275 evapi.periodic_start = ev_periodic_start; 461 evapi.periodic_start = ev_periodic_start;
276 evapi.periodic_stop = ev_periodic_stop; 462 evapi.periodic_stop = ev_periodic_stop;
277 evapi.signal_start = ev_signal_start; 463 evapi.signal_start = ev_signal_start;
278 evapi.signal_stop = ev_signal_stop; 464 evapi.signal_stop = ev_signal_stop;
279 evapi.idle_start = ev_idle_start; 465 evapi.idle_start = ev_idle_start;
280 evapi.idle_stop = ev_idle_stop; 466 evapi.idle_stop = ev_idle_stop;
281 evapi.prepare_start = ev_prepare_start; 467 evapi.prepare_start = ev_prepare_start;
282 evapi.prepare_stop = ev_prepare_stop; 468 evapi.prepare_stop = ev_prepare_stop;
283 evapi.check_start = ev_check_start; 469 evapi.check_start = ev_check_start;
284 evapi.check_stop = ev_check_stop; 470 evapi.check_stop = ev_check_stop;
285 evapi.child_start = ev_child_start; 471 evapi.child_start = ev_child_start;
286 evapi.child_stop = ev_child_stop; 472 evapi.child_stop = ev_child_stop;
473 evapi.stat_start = ev_stat_start;
474 evapi.stat_stop = ev_stat_stop;
475 evapi.stat_stat = ev_stat_stat;
476 evapi.embed_start = ev_embed_start;
477 evapi.embed_stop = ev_embed_stop;
478 evapi.embed_sweep = ev_embed_sweep;
479 evapi.fork_start = ev_fork_start;
480 evapi.fork_stop = ev_fork_stop;
481 evapi.async_start = ev_async_start;
482 evapi.async_stop = ev_async_stop;
483 evapi.async_send = ev_async_send;
484 evapi.clear_pending = ev_clear_pending;
485 evapi.invoke = ev_invoke;
287 486
288 sv_setiv (sv, (IV)&evapi); 487 sv_setiv (sv, (IV)&evapi);
289 SvREADONLY_on (sv); 488 SvREADONLY_on (sv);
290 } 489 }
490#ifndef _WIN32
491 pthread_atfork (0, 0, ev_default_fork);
492#endif
291} 493}
494
495SV *ev_default_loop (unsigned int flags = 0)
496 CODE:
497{
498 if (!default_loop_sv)
499 {
500 evapi.default_loop = ev_default_loop (flags);
501
502 if (!evapi.default_loop)
503 XSRETURN_UNDEF;
504
505 default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
506 }
507
508 RETVAL = newSVsv (default_loop_sv);
509}
510 OUTPUT:
511 RETVAL
512
513void ev_default_destroy ()
514 CODE:
515 ev_default_destroy ();
516 SvREFCNT_dec (default_loop_sv);
517 default_loop_sv = 0;
518
519unsigned int ev_supported_backends ()
520
521unsigned int ev_recommended_backends ()
522
523unsigned int ev_embeddable_backends ()
524
525void ev_sleep (NV interval)
526
527NV ev_time ()
292 528
293NV ev_now () 529NV ev_now ()
294 CODE: 530 C_ARGS: evapi.default_loop
295 RETVAL = ev_now;
296 OUTPUT:
297 RETVAL
298 531
299int ev_method () 532void ev_now_update ()
300 CODE: 533 C_ARGS: evapi.default_loop
301 RETVAL = ev_method;
302 OUTPUT:
303 RETVAL
304 534
305NV ev_time () 535unsigned int ev_backend ()
536 C_ARGS: evapi.default_loop
306 537
307void ev_init (int flags = 0) 538unsigned int ev_loop_count ()
539 C_ARGS: evapi.default_loop
540
541void ev_set_io_collect_interval (NV interval)
542 C_ARGS: evapi.default_loop, interval
543
544void ev_set_timeout_collect_interval (NV interval)
545 C_ARGS: evapi.default_loop, interval
308 546
309void ev_loop (int flags = 0) 547void ev_loop (int flags = 0)
548 C_ARGS: evapi.default_loop, flags
310 549
311void ev_loop_done (int value = 1) 550void ev_unloop (int how = EVUNLOOP_ONE)
312 CODE: 551 C_ARGS: evapi.default_loop, how
313 ev_loop_done = value;
314 552
553void ev_feed_fd_event (int fd, int revents = EV_NONE)
554 C_ARGS: evapi.default_loop, fd, revents
555
556void ev_feed_signal_event (SV *signal)
557 CODE:
558{
559 Signal signum = sv_signum (signal);
560 CHECK_SIG (signal, signum);
561
562 ev_feed_signal_event (evapi.default_loop, signum);
563}
564
315struct ev_io *io (SV *fh, int events, SV *cb) 565ev_io *io (SV *fh, int events, SV *cb)
316 ALIAS: 566 ALIAS:
317 io_ns = 1 567 io_ns = 1
318 CODE: 568 CODE:
569{
570 int fd = sv_fileno (fh);
571 CHECK_FD (fh, fd);
572
319 RETVAL = e_new (sizeof (struct ev_io), cb); 573 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
320 RETVAL->fh = newSVsv (fh); 574 RETVAL->fh = newSVsv (fh);
321 ev_io_set (RETVAL, sv_fileno (RETVAL->fh), events); 575 ev_io_set (RETVAL, fd, events);
322 if (!ix) ev_io_start (RETVAL); 576 if (!ix) START (io, RETVAL);
577}
323 OUTPUT: 578 OUTPUT:
324 RETVAL 579 RETVAL
325 580
326struct ev_timer *timer (NV after, NV repeat, SV *cb) 581ev_timer *timer (NV after, NV repeat, SV *cb)
327 ALIAS: 582 ALIAS:
328 timer_ns = 1 583 timer_ns = 1
329 INIT: 584 INIT:
330 CHECK_REPEAT (repeat); 585 CHECK_REPEAT (repeat);
331 CODE: 586 CODE:
332 RETVAL = e_new (sizeof (struct ev_timer), cb); 587 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
333 ev_timer_set (RETVAL, after, repeat); 588 ev_timer_set (RETVAL, after, repeat);
334 if (!ix) ev_timer_start (RETVAL); 589 if (!ix) START (timer, RETVAL);
335 OUTPUT: 590 OUTPUT:
336 RETVAL 591 RETVAL
337 592
338struct ev_periodic *periodic (NV at, NV interval, SV *cb) 593SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
339 ALIAS: 594 ALIAS:
340 periodic_ns = 1 595 periodic_ns = 1
341 INIT: 596 INIT:
342 CHECK_REPEAT (interval); 597 CHECK_REPEAT (interval);
343 CODE: 598 CODE:
344 RETVAL = e_new (sizeof (struct ev_periodic), cb); 599{
345 ev_periodic_set (RETVAL, at, interval); 600 ev_periodic *w;
346 if (!ix) ev_periodic_start (RETVAL); 601 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
602 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
603 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
604 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
605 if (!ix) START (periodic, w);
606}
347 OUTPUT: 607 OUTPUT:
348 RETVAL 608 RETVAL
349 609
350struct ev_signal *signal (Signal signum, SV *cb) 610ev_signal *signal (SV *signal, SV *cb)
351 ALIAS: 611 ALIAS:
352 signal_ns = 1 612 signal_ns = 1
353 CODE: 613 CODE:
614{
615 Signal signum = sv_signum (signal);
616 CHECK_SIG (signal, signum);
617
354 RETVAL = e_new (sizeof (struct ev_signal), cb); 618 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
355 ev_signal_set (RETVAL, signum); 619 ev_signal_set (RETVAL, signum);
356 if (!ix) ev_signal_start (RETVAL); 620 if (!ix) START (signal, RETVAL);
621}
357 OUTPUT: 622 OUTPUT:
358 RETVAL 623 RETVAL
359 624
360struct ev_idle *idle (SV *cb) 625ev_idle *idle (SV *cb)
361 ALIAS: 626 ALIAS:
362 idle_ns = 1 627 idle_ns = 1
363 CODE: 628 CODE:
364 RETVAL = e_new (sizeof (struct ev_idle), cb); 629 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
365 ev_idle_set (RETVAL); 630 ev_idle_set (RETVAL);
366 if (!ix) ev_idle_start (RETVAL); 631 if (!ix) START (idle, RETVAL);
367 OUTPUT: 632 OUTPUT:
368 RETVAL 633 RETVAL
369 634
370struct ev_prepare *prepare (SV *cb) 635ev_prepare *prepare (SV *cb)
371 ALIAS: 636 ALIAS:
372 prepare_ns = 1 637 prepare_ns = 1
373 CODE: 638 CODE:
374 RETVAL = e_new (sizeof (struct ev_prepare), cb); 639 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
375 ev_prepare_set (RETVAL); 640 ev_prepare_set (RETVAL);
376 if (!ix) ev_prepare_start (RETVAL); 641 if (!ix) START (prepare, RETVAL);
377 OUTPUT: 642 OUTPUT:
378 RETVAL 643 RETVAL
379 644
380struct ev_check *check (SV *cb) 645ev_check *check (SV *cb)
381 ALIAS: 646 ALIAS:
382 check_ns = 1 647 check_ns = 1
383 CODE: 648 CODE:
384 RETVAL = e_new (sizeof (struct ev_check), cb); 649 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
385 ev_check_set (RETVAL); 650 ev_check_set (RETVAL);
386 if (!ix) ev_check_start (RETVAL); 651 if (!ix) START (check, RETVAL);
387 OUTPUT: 652 OUTPUT:
388 RETVAL 653 RETVAL
389 654
655ev_fork *fork (SV *cb)
656 ALIAS:
657 fork_ns = 1
658 CODE:
659 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
660 ev_fork_set (RETVAL);
661 if (!ix) START (fork, RETVAL);
662 OUTPUT:
663 RETVAL
664
390struct ev_child *child (int pid, SV *cb) 665ev_child *child (int pid, int trace, SV *cb)
391 ALIAS: 666 ALIAS:
392 check_ns = 1 667 child_ns = 1
393 CODE: 668 CODE:
394 RETVAL = e_new (sizeof (struct ev_check), cb); 669 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
395 ev_child_set (RETVAL, pid); 670 ev_child_set (RETVAL, pid, trace);
396 if (!ix) ev_child_start (RETVAL); 671 if (!ix) START (child, RETVAL);
397 OUTPUT: 672 OUTPUT:
398 RETVAL 673 RETVAL
399 674
675ev_stat *stat (SV *path, NV interval, SV *cb)
676 ALIAS:
677 stat_ns = 1
678 CODE:
679 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
680 RETVAL->fh = newSVsv (path);
681 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
682 if (!ix) START (stat, RETVAL);
683 OUTPUT:
684 RETVAL
685
686ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
687 ALIAS:
688 embed_ns = 1
689 CODE:
690{
691 if (!(ev_backend (loop) & ev_embeddable_backends ()))
692 croak ("passed loop is not embeddable via EV::embed,");
693
694 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
695 RETVAL->fh = newSVsv (ST (0));
696 ev_embed_set (RETVAL, loop);
697 if (!ix) START (embed, RETVAL);
698}
699 OUTPUT:
700 RETVAL
701
702ev_async *async (SV *cb)
703 ALIAS:
704 async_ns = 1
705 CODE:
706 RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
707 ev_async_set (RETVAL);
708 if (!ix) START (async, RETVAL);
709 OUTPUT:
710 RETVAL
711
712void once (SV *fh, int events, SV *timeout, SV *cb)
713 CODE:
714 ev_once (
715 evapi.default_loop,
716 sv_fileno (fh), events,
717 SvOK (timeout) ? SvNV (timeout) : -1.,
718 e_once_cb,
719 newSVsv (cb)
720 );
400 721
401PROTOTYPES: DISABLE 722PROTOTYPES: DISABLE
402 723
403MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 724MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
404 725
405int ev_is_active (struct ev_watcher *w) 726int ev_is_active (ev_watcher *w)
406 727
728int ev_is_pending (ev_watcher *w)
729
730void ev_invoke (ev_watcher *w, int revents = EV_NONE)
731 C_ARGS: e_loop (w), w, revents
732
733int ev_clear_pending (ev_watcher *w)
734 C_ARGS: e_loop (w), w
735
736void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
737 C_ARGS: e_loop (w), w, revents
738
739int keepalive (ev_watcher *w, int new_value = 0)
740 CODE:
741{
742 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
743 new_value = new_value ? WFLAG_KEEPALIVE : 0;
744
745 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
746 {
747 REF (w);
748 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
749 UNREF (w);
750 }
751}
752 OUTPUT:
753 RETVAL
754
407SV *cb (struct ev_watcher *w, SV *new_cb = 0) 755SV *cb (ev_watcher *w, SV *new_cb = 0)
408 CODE: 756 CODE:
409{ 757{
410 RETVAL = newSVsv (w->cb_sv);
411
412 if (items > 1)
413 sv_setsv (w->cb_sv, new_cb);
414}
415 OUTPUT:
416 RETVAL
417
418void trigger (struct ev_watcher *w, int revents = EV_NONE)
419 CODE:
420 w->cb (w, revents);
421
422MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_
423
424void ev_io_start (struct ev_io *w)
425
426void ev_io_stop (struct ev_io *w)
427
428void DESTROY (struct ev_io *w)
429 CODE:
430 ev_io_stop (w);
431
432void set (struct ev_io *w, SV *fh, int events)
433 CODE:
434{
435 int active = w->active;
436 if (active) ev_io_stop (w);
437
438 sv_setsv (w->fh, fh);
439 ev_io_set (w, sv_fileno (w->fh), events);
440
441 if (active) ev_io_start (w);
442}
443
444SV *fh (struct ev_io *w, SV *new_fh = 0)
445 CODE:
446{
447 RETVAL = newSVsv (w->fh);
448
449 if (items > 1) 758 if (items > 1)
450 { 759 {
451 int active = w->active; 760 new_cb = e_get_cv (new_cb);
452 if (active) ev_io_stop (w); 761 RETVAL = newRV_noinc (w->cb_sv);
453 762 w->cb_sv = SvREFCNT_inc (new_cb);
454 sv_setsv (w->fh, new_fh);
455 ev_io_set (w, sv_fileno (w->fh), w->events);
456
457 if (active) ev_io_start (w);
458 } 763 }
764 else
765 RETVAL = newRV_inc (w->cb_sv);
459} 766}
460 OUTPUT: 767 OUTPUT:
461 RETVAL 768 RETVAL
462 769
463short events (struct ev_io *w, short new_events = EV_UNDEF) 770SV *data (ev_watcher *w, SV *new_data = 0)
464 CODE: 771 CODE:
465{ 772{
466 RETVAL = w->events; 773 RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
467 774
468 if (items > 1) 775 if (items > 1)
469 { 776 {
470 int active = w->active; 777 SvREFCNT_dec (w->data);
471 if (active) ev_io_stop (w); 778 w->data = newSVsv (new_data);
472
473 ev_io_set (w, w->fd, new_events);
474
475 if (active) ev_io_start (w);
476 } 779 }
477} 780}
478 OUTPUT: 781 OUTPUT:
479 RETVAL 782 RETVAL
480 783
784SV *loop (ev_watcher *w)
785 CODE:
786 RETVAL = newRV_inc (w->loop);
787 OUTPUT:
788 RETVAL
789
790int priority (ev_watcher *w, int new_priority = 0)
791 CODE:
792{
793 RETVAL = w->priority;
794
795 if (items > 1)
796 {
797 int active = ev_is_active (w);
798
799 if (active)
800 {
801 /* grrr. */
802 PUSHMARK (SP);
803 XPUSHs (ST (0));
804 PUTBACK;
805 call_method ("stop", G_DISCARD | G_VOID);
806 }
807
808 ev_set_priority (w, new_priority);
809
810 if (active)
811 {
812 PUSHMARK (SP);
813 XPUSHs (ST (0));
814 PUTBACK;
815 call_method ("start", G_DISCARD | G_VOID);
816 }
817 }
818}
819 OUTPUT:
820 RETVAL
821
822MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_
823
824void ev_io_start (ev_io *w)
825 CODE:
826 START (io, w);
827
828void ev_io_stop (ev_io *w)
829 CODE:
830 STOP (io, w);
831
832void DESTROY (ev_io *w)
833 CODE:
834 STOP (io, w);
835 e_destroy (w);
836
837void set (ev_io *w, SV *fh, int events)
838 CODE:
839{
840 int fd = sv_fileno (fh);
841 CHECK_FD (fh, fd);
842
843 sv_setsv (w->fh, fh);
844 RESET (io, w, (w, fd, events));
845}
846
847SV *fh (ev_io *w, SV *new_fh = 0)
848 CODE:
849{
850 if (items > 1)
851 {
852 int fd = sv_fileno (new_fh);
853 CHECK_FD (new_fh, fd);
854
855 RETVAL = w->fh;
856 w->fh = newSVsv (new_fh);
857
858 RESET (io, w, (w, fd, w->events));
859 }
860 else
861 RETVAL = newSVsv (w->fh);
862}
863 OUTPUT:
864 RETVAL
865
866int events (ev_io *w, int new_events = EV_UNDEF)
867 CODE:
868{
869 RETVAL = w->events;
870
871 if (items > 1)
872 RESET (io, w, (w, w->fd, new_events));
873}
874 OUTPUT:
875 RETVAL
876
481MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ 877MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
482 878
483void ev_signal_start (struct ev_signal *w) 879void ev_signal_start (ev_signal *w)
880 CODE:
881 START (signal, w);
484 882
485void ev_signal_stop (struct ev_signal *w) 883void ev_signal_stop (ev_signal *w)
884 CODE:
885 STOP (signal, w);
486 886
487void DESTROY (struct ev_signal *w) 887void DESTROY (ev_signal *w)
488 CODE: 888 CODE:
489 ev_signal_stop (w); 889 STOP (signal, w);
890 e_destroy (w);
490 891
491void set (struct ev_signal *w, SV *signal = 0) 892void set (ev_signal *w, SV *signal)
492 CODE: 893 CODE:
493{ 894{
494 Signal signum = sv_signum (signal); /* may croak here */ 895 Signal signum = sv_signum (signal);
495 int active = w->active; 896 CHECK_SIG (signal, signum);
496 897
497 if (active) ev_signal_stop (w); 898 RESET (signal, w, (w, signum));
498 ev_signal_set (w, signum);
499 if (active) ev_signal_start (w);
500} 899}
501 900
502MODULE = EV PACKAGE = EV::Time 901int signal (ev_signal *w, SV *new_signal = 0)
902 CODE:
903{
904 RETVAL = w->signum;
905
906 if (items > 1)
907 {
908 Signal signum = sv_signum (new_signal);
909 CHECK_SIG (new_signal, signum);
910
911 RESET (signal, w, (w, signum));
912 }
913}
914 OUTPUT:
915 RETVAL
503 916
504MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 917MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
505 918
506void ev_timer_start (struct ev_timer *w) 919void ev_timer_start (ev_timer *w)
507 INIT: 920 INIT:
508 CHECK_REPEAT (w->repeat); 921 CHECK_REPEAT (w->repeat);
922 CODE:
923 START (timer, w);
509 924
510void ev_timer_stop (struct ev_timer *w) 925void ev_timer_stop (ev_timer *w)
926 CODE:
927 STOP (timer, w);
511 928
512void ev_timer_again (struct ev_timer *w) 929void ev_timer_again (ev_timer *w)
513 INIT: 930 INIT:
514 CHECK_REPEAT (w->repeat); 931 CHECK_REPEAT (w->repeat);
932 CODE:
933 REF (w);
934 ev_timer_again (e_loop (w), w);
935 UNREF (w);
515 936
516void DESTROY (struct ev_timer *w) 937void DESTROY (ev_timer *w)
517 CODE: 938 CODE:
939 STOP (timer, w);
518 ev_timer_stop (w); 940 e_destroy (w);
519 941
520void set (struct ev_timer *w, NV after, NV repeat = 0.) 942void set (ev_timer *w, NV after, NV repeat = 0.)
521 INIT: 943 INIT:
522 CHECK_REPEAT (repeat); 944 CHECK_REPEAT (repeat);
523 CODE: 945 CODE:
524{
525 int active = w->active;
526 if (active) ev_timer_stop (w);
527 ev_timer_set (w, after, repeat); 946 RESET (timer, w, (w, after, repeat));
528 if (active) ev_timer_start (w);
529}
530 947
531MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 948MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
532 949
533void ev_periodic_start (struct ev_periodic *w) 950void ev_periodic_start (ev_periodic *w)
534 INIT: 951 INIT:
535 CHECK_REPEAT (w->interval); 952 CHECK_REPEAT (w->interval);
953 CODE:
954 START (periodic, w);
536 955
537void ev_periodic_stop (struct ev_periodic *w) 956void ev_periodic_stop (ev_periodic *w)
957 CODE:
958 STOP (periodic, w);
538 959
960void ev_periodic_again (ev_periodic *w)
961 CODE:
962 REF (w);
963 ev_periodic_again (e_loop (w), w);
964 UNREF (w);
965
539void DESTROY (struct ev_periodic *w) 966void DESTROY (ev_periodic *w)
540 CODE: 967 CODE:
541 ev_periodic_stop (w); 968 STOP (periodic, w);
969 e_destroy (w);
542 970
543void set (struct ev_periodic *w, NV at, NV interval = 0.) 971void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
544 INIT: 972 INIT:
545 CHECK_REPEAT (interval); 973 CHECK_REPEAT (interval);
546 CODE: 974 CODE:
547{ 975{
548 int active = w->active; 976 SvREFCNT_dec (w->fh);
549 if (active) ev_periodic_stop (w); 977 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
550 ev_periodic_set (w, at, interval); 978
551 if (active) ev_periodic_start (w); 979 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
552} 980}
981
982NV at (ev_periodic *w)
983 CODE:
984 RETVAL = ev_periodic_at (w);
985 OUTPUT:
986 RETVAL
553 987
554MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 988MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
555 989
556void ev_idle_start (struct ev_idle *w) 990void ev_idle_start (ev_idle *w)
991 CODE:
992 START (idle, w);
557 993
558void ev_idle_stop (struct ev_idle *w) 994void ev_idle_stop (ev_idle *w)
995 CODE:
996 STOP (idle, w);
559 997
560void DESTROY (struct ev_idle *w) 998void DESTROY (ev_idle *w)
561 CODE: 999 CODE:
1000 STOP (idle, w);
562 ev_idle_stop (w); 1001 e_destroy (w);
563 1002
564MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 1003MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
565 1004
566void ev_prepare_start (struct ev_prepare *w) 1005void ev_prepare_start (ev_prepare *w)
1006 CODE:
1007 START (prepare, w);
567 1008
568void ev_prepare_stop (struct ev_prepare *w) 1009void ev_prepare_stop (ev_prepare *w)
1010 CODE:
1011 STOP (prepare, w);
569 1012
570void DESTROY (struct ev_prepare *w) 1013void DESTROY (ev_prepare *w)
571 CODE: 1014 CODE:
572 ev_prepare_stop (w); 1015 STOP (prepare, w);
1016 e_destroy (w);
573 1017
574MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ 1018MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
575 1019
576void ev_check_start (struct ev_check *w) 1020void ev_check_start (ev_check *w)
1021 CODE:
1022 START (check, w);
577 1023
578void ev_check_stop (struct ev_check *w) 1024void ev_check_stop (ev_check *w)
1025 CODE:
1026 STOP (check, w);
579 1027
580void DESTROY (struct ev_check *w) 1028void DESTROY (ev_check *w)
581 CODE: 1029 CODE:
1030 STOP (check, w);
582 ev_check_stop (w); 1031 e_destroy (w);
1032
1033MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
1034
1035void ev_fork_start (ev_fork *w)
1036 CODE:
1037 START (fork, w);
1038
1039void ev_fork_stop (ev_fork *w)
1040 CODE:
1041 STOP (fork, w);
1042
1043void DESTROY (ev_fork *w)
1044 CODE:
1045 STOP (fork, w);
1046 e_destroy (w);
583 1047
584MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 1048MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
585 1049
586void ev_child_start (struct ev_child *w) 1050void ev_child_start (ev_child *w)
1051 CODE:
1052 START (child, w);
587 1053
588void ev_child_stop (struct ev_child *w) 1054void ev_child_stop (ev_child *w)
1055 CODE:
1056 STOP (child, w);
589 1057
590void DESTROY (struct ev_child *w) 1058void DESTROY (ev_child *w)
1059 CODE:
1060 STOP (child, w);
1061 e_destroy (w);
1062
1063void set (ev_child *w, int pid, int trace)
1064 CODE:
1065 RESET (child, w, (w, pid, trace));
1066
1067int pid (ev_child *w)
1068 ALIAS:
1069 rpid = 1
1070 rstatus = 2
1071 CODE:
1072 RETVAL = ix == 0 ? w->pid
1073 : ix == 1 ? w->rpid
1074 : w->rstatus;
1075 OUTPUT:
1076 RETVAL
1077
1078MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1079
1080void ev_stat_start (ev_stat *w)
1081 CODE:
1082 START (stat, w);
1083
1084void ev_stat_stop (ev_stat *w)
1085 CODE:
1086 STOP (stat, w);
1087
1088void DESTROY (ev_stat *w)
1089 CODE:
1090 STOP (stat, w);
1091 e_destroy (w);
1092
1093void set (ev_stat *w, SV *path, NV interval)
1094 CODE:
1095{
1096 sv_setsv (w->fh, path);
1097 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval));
1098}
1099
1100SV *path (ev_stat *w, SV *new_path = 0)
1101 CODE:
1102{
1103 RETVAL = SvREFCNT_inc (w->fh);
1104
1105 if (items > 1)
1106 {
1107 SvREFCNT_dec (w->fh);
1108 w->fh = newSVsv (new_path);
1109 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval));
1110 }
1111}
1112 OUTPUT:
1113 RETVAL
1114
1115NV interval (ev_stat *w, NV new_interval = 0.)
1116 CODE:
1117{
1118 RETVAL = w->interval;
1119
1120 if (items > 1)
1121 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval));
1122}
1123 OUTPUT:
1124 RETVAL
1125
1126void prev (ev_stat *w)
1127 ALIAS:
1128 stat = 1
1129 attr = 2
591 CODE: 1130 PPCODE:
1131{
1132 ev_statdata *s = ix ? &w->attr : &w->prev;
1133
1134 if (ix == 1)
1135 ev_stat_stat (e_loop (w), w);
1136 else if (!s->st_nlink)
1137 errno = ENOENT;
1138
1139 PL_statcache.st_dev = s->st_nlink;
1140 PL_statcache.st_ino = s->st_ino;
1141 PL_statcache.st_mode = s->st_mode;
1142 PL_statcache.st_nlink = s->st_nlink;
1143 PL_statcache.st_uid = s->st_uid;
1144 PL_statcache.st_gid = s->st_gid;
1145 PL_statcache.st_rdev = s->st_rdev;
1146 PL_statcache.st_size = s->st_size;
1147 PL_statcache.st_atime = s->st_atime;
1148 PL_statcache.st_mtime = s->st_mtime;
1149 PL_statcache.st_ctime = s->st_ctime;
1150
1151 if (GIMME_V == G_SCALAR)
1152 XPUSHs (boolSV (s->st_nlink));
1153 else if (GIMME_V == G_ARRAY && s->st_nlink)
1154 {
1155 EXTEND (SP, 13);
1156 PUSHs (sv_2mortal (newSViv (s->st_dev)));
1157 PUSHs (sv_2mortal (newSViv (s->st_ino)));
1158 PUSHs (sv_2mortal (newSVuv (s->st_mode)));
1159 PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
1160 PUSHs (sv_2mortal (newSViv (s->st_uid)));
1161 PUSHs (sv_2mortal (newSViv (s->st_gid)));
1162 PUSHs (sv_2mortal (newSViv (s->st_rdev)));
1163 PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
1164 PUSHs (sv_2mortal (newSVnv (s->st_atime)));
1165 PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
1166 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1167 PUSHs (sv_2mortal (newSVuv (4096)));
1168 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1169 }
1170}
1171
1172MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1173
1174void ev_embed_start (ev_embed *w)
1175 CODE:
1176 START (embed, w);
1177
1178void ev_embed_stop (ev_embed *w)
1179 CODE:
1180 STOP (embed, w);
1181
1182void DESTROY (ev_embed *w)
1183 CODE:
1184 STOP (embed, w);
592 ev_child_stop (w); 1185 e_destroy (w);
593 1186
594void set (struct ev_child *w, int pid) 1187void set (ev_embed *w, struct ev_loop *loop)
595 CODE: 1188 CODE:
596{ 1189{
597 int active = w->active; 1190 sv_setsv (w->fh, ST (1));
598 if (active) ev_child_stop (w); 1191 RESET (embed, w, (w, loop));
599 ev_child_set (w, pid);
600 if (active) ev_child_start (w);
601} 1192}
602 1193
603int status (struct ev_child *w) 1194SV *other (ev_embed *w)
604 CODE: 1195 CODE:
605 RETVAL = w->status; 1196 RETVAL = newSVsv (w->fh);
606 OUTPUT: 1197 OUTPUT:
607 RETVAL 1198 RETVAL
1199
1200void ev_embed_sweep (ev_embed *w)
1201 C_ARGS: e_loop (w), w
1202
1203MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1204
1205void ev_async_start (ev_async *w)
1206 CODE:
1207 START (async, w);
1208
1209void ev_async_stop (ev_async *w)
1210 CODE:
1211 STOP (async, w);
1212
1213void DESTROY (ev_async *w)
1214 CODE:
1215 STOP (async, w);
1216 e_destroy (w);
1217
1218void ev_async_send (ev_async *w)
1219 C_ARGS: e_loop (w), w
1220
1221SV *ev_async_async_pending (ev_async *w)
1222 CODE:
1223 RETVAL = boolSV (ev_async_pending (w));
1224 OUTPUT:
1225 RETVAL
1226
1227MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1228
1229SV *new (SV *klass, unsigned int flags = 0)
1230 CODE:
1231{
1232 struct ev_loop *loop = ev_loop_new (flags);
1233
1234 if (!loop)
1235 XSRETURN_UNDEF;
1236
1237 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1238}
1239 OUTPUT:
1240 RETVAL
1241
1242void DESTROY (struct ev_loop *loop)
1243 CODE:
1244 if (loop != evapi.default_loop) /* global destruction sucks */
1245 ev_loop_destroy (loop);
1246
1247void ev_loop_fork (struct ev_loop *loop)
1248
1249void ev_loop_verify (struct ev_loop *loop)
1250
1251NV ev_now (struct ev_loop *loop)
1252
1253void ev_now_update (struct ev_loop *loop)
1254
1255void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1256
1257void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1258
1259unsigned int ev_backend (struct ev_loop *loop)
1260
1261unsigned int ev_loop_count (struct ev_loop *loop)
1262
1263void ev_loop (struct ev_loop *loop, int flags = 0)
1264
1265void ev_unloop (struct ev_loop *loop, int how = 1)
1266
1267void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
608 1268
609#if 0 1269#if 0
610 1270
611MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 1271void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
612 1272 CODE:
613BOOT:
614{ 1273{
615 HV *stash = gv_stashpv ("EV::DNS", 1); 1274 Signal signum = sv_signum (signal);
1275 CHECK_SIG (signal, signum);
616 1276
617 static const struct { 1277 ev_feed_signal_event (loop, signum);
618 const char *name;
619 IV iv;
620 } *civ, const_iv[] = {
621# define const_iv(pfx, name) { # name, (IV) pfx ## name },
622 const_iv (DNS_, ERR_NONE)
623 const_iv (DNS_, ERR_FORMAT)
624 const_iv (DNS_, ERR_SERVERFAILED)
625 const_iv (DNS_, ERR_NOTEXIST)
626 const_iv (DNS_, ERR_NOTIMPL)
627 const_iv (DNS_, ERR_REFUSED)
628 const_iv (DNS_, ERR_TRUNCATED)
629 const_iv (DNS_, ERR_UNKNOWN)
630 const_iv (DNS_, ERR_TIMEOUT)
631 const_iv (DNS_, ERR_SHUTDOWN)
632 const_iv (DNS_, IPv4_A)
633 const_iv (DNS_, PTR)
634 const_iv (DNS_, IPv6_AAAA)
635 const_iv (DNS_, QUERY_NO_SEARCH)
636 const_iv (DNS_, OPTION_SEARCH)
637 const_iv (DNS_, OPTION_NAMESERVERS)
638 const_iv (DNS_, OPTION_MISC)
639 const_iv (DNS_, OPTIONS_ALL)
640 const_iv (DNS_, NO_SEARCH)
641 };
642
643 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
644 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
645} 1278}
646
647int evdns_init ()
648
649void evdns_shutdown (int fail_requests = 1)
650
651const char *evdns_err_to_string (int err)
652
653int evdns_nameserver_add (U32 address)
654
655int evdns_count_nameservers ()
656
657int evdns_clear_nameservers_and_suspend ()
658
659int evdns_resume ()
660
661int evdns_nameserver_ip_add (char *ip_as_string)
662
663int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
664 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
665
666int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
667 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
668
669int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
670 ALIAS:
671 evdns_resolve_reverse_ipv6 = 1
672 CODE:
673{
674 STRLEN len;
675 char *data = SvPVbyte (addr, len);
676 if (len != (ix ? 16 : 4))
677 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
678
679 RETVAL = ix
680 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
681 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
682}
683 OUTPUT:
684 RETVAL
685
686int evdns_set_option (char *option, char *val, int flags)
687
688int evdns_resolv_conf_parse (int flags, const char *filename)
689
690#ifdef MS_WINDOWS
691
692int evdns_config_windows_nameservers ()
693 1279
694#endif 1280#endif
695 1281
696void evdns_search_clear () 1282ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
697 1283 ALIAS:
698void evdns_search_add (char *domain) 1284 io_ns = 1
699 1285 CODE:
700void evdns_search_ndots_set (int ndots)
701
702
703MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
704
705BOOT:
706{ 1286{
707 HV *stash = gv_stashpv ("EV::HTTP", 1); 1287 int fd = sv_fileno (fh);
1288 CHECK_FD (fh, fd);
708 1289
709 static const struct { 1290 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
710 const char *name; 1291 RETVAL->fh = newSVsv (fh);
711 IV iv; 1292 ev_io_set (RETVAL, fd, events);
712 } *civ, const_iv[] = { 1293 if (!ix) START (io, RETVAL);
713# define const_iv(pfx, name) { # name, (IV) pfx ## name },
714 const_iv (HTTP_, OK)
715 const_iv (HTTP_, NOCONTENT)
716 const_iv (HTTP_, MOVEPERM)
717 const_iv (HTTP_, MOVETEMP)
718 const_iv (HTTP_, NOTMODIFIED)
719 const_iv (HTTP_, BADREQUEST)
720 const_iv (HTTP_, NOTFOUND)
721 const_iv (HTTP_, SERVUNAVAIL)
722 const_iv (EVHTTP_, REQ_OWN_CONNECTION)
723 const_iv (EVHTTP_, PROXY_REQUEST)
724 const_iv (EVHTTP_, REQ_GET)
725 const_iv (EVHTTP_, REQ_POST)
726 const_iv (EVHTTP_, REQ_HEAD)
727 const_iv (EVHTTP_, REQUEST)
728 const_iv (EVHTTP_, RESPONSE)
729 };
730
731 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
732 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
733} 1294}
1295 OUTPUT:
1296 RETVAL
734 1297
735MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_ 1298ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1299 ALIAS:
1300 timer_ns = 1
1301 INIT:
1302 CHECK_REPEAT (repeat);
1303 CODE:
1304 RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1305 ev_timer_set (RETVAL, after, repeat);
1306 if (!ix) START (timer, RETVAL);
1307 OUTPUT:
1308 RETVAL
736 1309
737#HttpRequest new (SV *klass, SV *cb) 1310SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1311 ALIAS:
1312 periodic_ns = 1
1313 INIT:
1314 CHECK_REPEAT (interval);
1315 CODE:
1316{
1317 ev_periodic *w;
1318 w = e_new (sizeof (ev_periodic), cb, ST (0));
1319 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1320 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
1321 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1322 if (!ix) START (periodic, w);
1323}
1324 OUTPUT:
1325 RETVAL
738 1326
739#void DESTROY (struct evhttp_request *req); 1327#if 0
1328
1329ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1330 ALIAS:
1331 signal_ns = 1
1332 CODE:
1333{
1334 Signal signum = sv_signum (signal);
1335 CHECK_SIG (signal, signum);
1336
1337 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1338 ev_signal_set (RETVAL, signum);
1339 if (!ix) START (signal, RETVAL);
1340}
1341 OUTPUT:
1342 RETVAL
740 1343
741#endif 1344#endif
742 1345
1346ev_idle *idle (struct ev_loop *loop, SV *cb)
1347 ALIAS:
1348 idle_ns = 1
1349 CODE:
1350 RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1351 ev_idle_set (RETVAL);
1352 if (!ix) START (idle, RETVAL);
1353 OUTPUT:
1354 RETVAL
743 1355
1356ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1357 ALIAS:
1358 prepare_ns = 1
1359 CODE:
1360 RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1361 ev_prepare_set (RETVAL);
1362 if (!ix) START (prepare, RETVAL);
1363 OUTPUT:
1364 RETVAL
744 1365
1366ev_check *check (struct ev_loop *loop, SV *cb)
1367 ALIAS:
1368 check_ns = 1
1369 CODE:
1370 RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1371 ev_check_set (RETVAL);
1372 if (!ix) START (check, RETVAL);
1373 OUTPUT:
1374 RETVAL
745 1375
1376ev_fork *fork (struct ev_loop *loop, SV *cb)
1377 ALIAS:
1378 fork_ns = 1
1379 CODE:
1380 RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1381 ev_fork_set (RETVAL);
1382 if (!ix) START (fork, RETVAL);
1383 OUTPUT:
1384 RETVAL
746 1385
1386ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1387 ALIAS:
1388 child_ns = 1
1389 CODE:
1390 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1391 ev_child_set (RETVAL, pid, trace);
1392 if (!ix) START (child, RETVAL);
1393 OUTPUT:
1394 RETVAL
747 1395
1396ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1397 ALIAS:
1398 stat_ns = 1
1399 CODE:
1400 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1401 RETVAL->fh = newSVsv (path);
1402 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1403 if (!ix) START (stat, RETVAL);
1404 OUTPUT:
1405 RETVAL
748 1406
1407ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1408 ALIAS:
1409 embed_ns = 1
1410 CODE:
1411{
1412 if (!(ev_backend (other) & ev_embeddable_backends ()))
1413 croak ("passed loop is not embeddable via EV::embed,");
749 1414
1415 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1416 RETVAL->fh = newSVsv (ST (1));
1417 ev_embed_set (RETVAL, other);
1418 if (!ix) START (embed, RETVAL);
1419}
1420 OUTPUT:
1421 RETVAL
1422
1423ev_async *async (struct ev_loop *loop, SV *cb)
1424 ALIAS:
1425 async_ns = 1
1426 CODE:
1427 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1428 ev_async_set (RETVAL);
1429 if (!ix) START (async, RETVAL);
1430 OUTPUT:
1431 RETVAL
1432
1433void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1434 CODE:
1435 ev_once (
1436 loop,
1437 sv_fileno (fh), events,
1438 SvOK (timeout) ? SvNV (timeout) : -1.,
1439 e_once_cb,
1440 newSVsv (cb)
1441 );
1442

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines