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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines