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

Comparing EV/EV.xs (file contents):
Revision 1.84 by root, Sat Dec 1 15:32:53 2007 UTC vs.
Revision 1.94 by root, Thu Dec 20 09:32:19 2007 UTC

3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define EV_PROTOTYPES 1 7#define EV_PROTOTYPES 1
8#define EV_H <ev.h>
8#include "EV/EVAPI.h" 9#include "EV/EVAPI.h"
9 10
10/* fix perl api breakage */ 11/* fix perl api breakage */
11#undef signal 12#undef signal
12#undef sigaction 13#undef sigaction
17# define NFDBITS PERL_NFDBITS 18# define NFDBITS PERL_NFDBITS
18# define fd_mask Perl_fd_mask 19# define fd_mask Perl_fd_mask
19#endif 20#endif
20/* due to bugs in OS X we have to use libev/ explicitly here */ 21/* due to bugs in OS X we have to use libev/ explicitly here */
21#include "libev/ev.c" 22#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 23
36#ifndef _WIN32 24#ifndef _WIN32
37# include <pthread.h> 25# include <pthread.h>
38#endif 26#endif
39 27
28#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
29
40#define WFLAG_KEEPALIVE 1 30#define WFLAG_KEEPALIVE 1
41 31
42#define UNREF(w) \ 32#define UNREF(w) \
43 if (!((w)->flags & WFLAG_KEEPALIVE) \ 33 if (!((w)->flags & WFLAG_KEEPALIVE) \
44 && !ev_is_active (w)) \ 34 && !ev_is_active (w)) \
45 ev_unref (); 35 ev_unref (e_loop (w));
46 36
47#define REF(w) \ 37#define REF(w) \
48 if (!((w)->flags & WFLAG_KEEPALIVE) \ 38 if (!((w)->flags & WFLAG_KEEPALIVE) \
49 && ev_is_active (w)) \ 39 && ev_is_active (w)) \
50 ev_ref (); 40 ev_ref (e_loop (w));
51 41
52#define START(type,w) \ 42#define START(type,w) \
53 do { \ 43 do { \
54 UNREF (w); \ 44 UNREF (w); \
55 ev_ ## type ## _start (w); \ 45 ev_ ## type ## _start (e_loop (w), w); \
56 } while (0) 46 } while (0)
57 47
58#define STOP(type,w) \ 48#define STOP(type,w) \
59 do { \ 49 do { \
60 REF (w); \ 50 REF (w); \
61 ev_ ## type ## _stop (w); \ 51 ev_ ## type ## _stop (e_loop (w), w); \
62 } while (0) 52 } while (0)
63 53
64#define RESET(type,w,seta) \ 54#define RESET(type,w,seta) \
65 do { \ 55 do { \
66 int active = ev_is_active (w); \ 56 int active = ev_is_active (w); \
69 if (active) START (type, w); \ 59 if (active) START (type, w); \
70 } while (0) 60 } while (0)
71 61
72typedef int Signal; 62typedef int Signal;
73 63
64static SV *default_loop_sv;
65
74static struct EVAPI evapi; 66static struct EVAPI evapi;
75 67
76static HV 68static HV
69 *stash_loop,
77 *stash_watcher, 70 *stash_watcher,
78 *stash_io, 71 *stash_io,
79 *stash_timer, 72 *stash_timer,
80 *stash_periodic, 73 *stash_periodic,
81 *stash_signal, 74 *stash_signal,
113} 106}
114 107
115///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
116// Event 109// Event
117 110
118static void e_cb (ev_watcher *w, int revents); 111static void e_cb (EV_P_ ev_watcher *w, int revents);
119 112
120static int 113static int
121sv_fileno (SV *fh) 114sv_fileno (SV *fh)
122{ 115{
123 SvGETMAGIC (fh); 116 SvGETMAGIC (fh);
133 126
134 return -1; 127 return -1;
135} 128}
136 129
137static void * 130static void *
138e_new (int size, SV *cb_sv) 131e_new (int size, SV *cb_sv, SV *loop)
139{ 132{
140 ev_watcher *w; 133 ev_watcher *w;
141 SV *self = NEWSV (0, size); 134 SV *self = NEWSV (0, size);
142 SvPOK_only (self); 135 SvPOK_only (self);
143 SvCUR_set (self, size); 136 SvCUR_set (self, size);
144 137
145 w = (ev_watcher *)SvPVX (self); 138 w = (ev_watcher *)SvPVX (self);
146 139
147 ev_init (w, e_cb); 140 ev_init (w, e_cb);
148 141
142 w->loop = SvREFCNT_inc (SvRV (loop));
149 w->flags = WFLAG_KEEPALIVE; 143 w->flags = WFLAG_KEEPALIVE;
150 w->data = 0; 144 w->data = 0;
151 w->fh = 0; 145 w->fh = 0;
152 w->cb_sv = newSVsv (cb_sv); 146 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv);
153 w->self = self; 147 w->self = self;
154 148
155 return (void *)w; 149 return (void *)w;
156} 150}
157 151
158static void 152static void
159e_destroy (void *w_) 153e_destroy (void *w_)
160{ 154{
161 ev_watcher *w = (ev_watcher *)w_; 155 ev_watcher *w = (ev_watcher *)w_;
162 156
157 SvREFCNT_dec (w->loop ); w->loop = 0;
163 SvREFCNT_dec (w->fh ); w->fh = 0; 158 SvREFCNT_dec (w->fh ); w->fh = 0;
164 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 159 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
165 SvREFCNT_dec (w->data ); w->data = 0; 160 SvREFCNT_dec (w->data ); w->data = 0;
166} 161}
167 162
183} 178}
184 179
185static SV *sv_events_cache; 180static SV *sv_events_cache;
186 181
187static void 182static void
188e_cb (ev_watcher *w, int revents) 183e_cb (EV_P_ ev_watcher *w, int revents)
189{ 184{
190 dSP; 185 dSP;
191 I32 mark = SP - PL_stack_base; 186 I32 mark = SP - PL_stack_base;
192 SV *sv_self, *sv_events; 187 SV *sv_self, *sv_events;
193 188
256 else 251 else
257 sv_events_cache = sv_events; 252 sv_events_cache = sv_events;
258 253
259 if (SvTRUE (ERRSV)) 254 if (SvTRUE (ERRSV))
260 { 255 {
256 SPAGAIN;
261 PUSHMARK (SP); 257 PUSHMARK (SP);
262 PUTBACK; 258 PUTBACK;
263 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 259 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
264 } 260 }
265 261
307 FREETMPS; 303 FREETMPS;
308 LEAVE; 304 LEAVE;
309 305
310 return retval; 306 return retval;
311} 307}
312
313/////////////////////////////////////////////////////////////////////////////
314// DNS
315
316#ifndef _WIN32
317static void
318dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
319{
320 dSP;
321 SV *cb = (SV *)arg;
322
323 ENTER;
324 SAVETMPS;
325 PUSHMARK (SP);
326 EXTEND (SP, count + 3);
327 PUSHs (sv_2mortal (newSViv (result)));
328
329 if (result == DNS_ERR_NONE && ttl >= 0)
330 {
331 int i;
332
333 PUSHs (sv_2mortal (newSViv (type)));
334 PUSHs (sv_2mortal (newSViv (ttl)));
335
336 for (i = 0; i < count; ++i)
337 switch (type)
338 {
339 case DNS_IPv6_AAAA:
340 PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16)));
341 break;
342 case DNS_IPv4_A:
343 PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4)));
344 break;
345 case DNS_PTR:
346 PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0)));
347 break;
348 }
349 }
350
351 PUTBACK;
352 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
353
354 FREETMPS;
355
356 if (SvTRUE (ERRSV))
357 {
358 PUSHMARK (SP);
359 PUTBACK;
360 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
361 }
362
363 LEAVE;
364}
365#endif
366 308
367#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 309#define CHECK_REPEAT(repeat) if (repeat < 0.) \
368 croak (# repeat " value must be >= 0"); 310 croak (# repeat " value must be >= 0");
369 311
370#define CHECK_FD(fh,fd) if ((fd) < 0) \ 312#define CHECK_FD(fh,fd) if ((fd) < 0) \
419 }; 361 };
420 362
421 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 363 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
422 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 364 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
423 365
366 stash_loop = gv_stashpv ("EV::Loop" , 1);
424 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 367 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
425 stash_io = gv_stashpv ("EV::IO" , 1); 368 stash_io = gv_stashpv ("EV::IO" , 1);
426 stash_timer = gv_stashpv ("EV::Timer" , 1); 369 stash_timer = gv_stashpv ("EV::Timer" , 1);
427 stash_periodic = gv_stashpv ("EV::Periodic", 1); 370 stash_periodic = gv_stashpv ("EV::Periodic", 1);
428 stash_signal = gv_stashpv ("EV::Signal" , 1); 371 stash_signal = gv_stashpv ("EV::Signal" , 1);
430 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 373 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
431 stash_check = gv_stashpv ("EV::Check" , 1); 374 stash_check = gv_stashpv ("EV::Check" , 1);
432 stash_child = gv_stashpv ("EV::Child" , 1); 375 stash_child = gv_stashpv ("EV::Child" , 1);
433 stash_embed = gv_stashpv ("EV::Embed" , 1); 376 stash_embed = gv_stashpv ("EV::Embed" , 1);
434 stash_stat = gv_stashpv ("EV::Stat" , 1); 377 stash_stat = gv_stashpv ("EV::Stat" , 1);
378 stash_fork = gv_stashpv ("EV::Fork" , 1);
435 379
436 { 380 {
437 SV *sv = perl_get_sv ("EV::API", TRUE); 381 SV *sv = perl_get_sv ("EV::API", TRUE);
438 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 382 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
439 383
440 /* the poor man's shared library emulator */ 384 /* the poor man's shared library emulator */
441 evapi.ver = EV_API_VERSION; 385 evapi.ver = EV_API_VERSION;
442 evapi.rev = EV_API_REVISION; 386 evapi.rev = EV_API_REVISION;
443 evapi.sv_fileno = sv_fileno; 387 evapi.sv_fileno = sv_fileno;
444 evapi.sv_signum = sv_signum; 388 evapi.sv_signum = sv_signum;
389 evapi.supported_backends = ev_supported_backends ();
390 evapi.recommended_backends = ev_recommended_backends ();
391 evapi.embeddable_backends = ev_embeddable_backends ();
392 evapi.time = ev_time;
393 evapi.loop_new = ev_loop_new;
394 evapi.loop_destroy = ev_loop_destroy;
395 evapi.loop_fork = ev_loop_fork;
396 evapi.loop_count = ev_loop_count;
445 evapi.now = ev_now; 397 evapi.now = ev_now;
446 evapi.backend = ev_backend; 398 evapi.backend = ev_backend;
447 evapi.unloop = ev_unloop; 399 evapi.unloop = ev_unloop;
448 evapi.ref = ev_ref; 400 evapi.ref = ev_ref;
449 evapi.unref = ev_unref; 401 evapi.unref = ev_unref;
450 evapi.time = ev_time;
451 evapi.loop = ev_loop; 402 evapi.loop = ev_loop;
452 evapi.once = ev_once; 403 evapi.once = ev_once;
453 evapi.io_start = ev_io_start; 404 evapi.io_start = ev_io_start;
454 evapi.io_stop = ev_io_stop; 405 evapi.io_stop = ev_io_stop;
455 evapi.timer_start = ev_timer_start; 406 evapi.timer_start = ev_timer_start;
456 evapi.timer_stop = ev_timer_stop; 407 evapi.timer_stop = ev_timer_stop;
457 evapi.timer_again = ev_timer_again; 408 evapi.timer_again = ev_timer_again;
458 evapi.periodic_start = ev_periodic_start; 409 evapi.periodic_start = ev_periodic_start;
459 evapi.periodic_stop = ev_periodic_stop; 410 evapi.periodic_stop = ev_periodic_stop;
460 evapi.signal_start = ev_signal_start; 411 evapi.signal_start = ev_signal_start;
461 evapi.signal_stop = ev_signal_stop; 412 evapi.signal_stop = ev_signal_stop;
462 evapi.idle_start = ev_idle_start; 413 evapi.idle_start = ev_idle_start;
463 evapi.idle_stop = ev_idle_stop; 414 evapi.idle_stop = ev_idle_stop;
464 evapi.prepare_start = ev_prepare_start; 415 evapi.prepare_start = ev_prepare_start;
465 evapi.prepare_stop = ev_prepare_stop; 416 evapi.prepare_stop = ev_prepare_stop;
466 evapi.check_start = ev_check_start; 417 evapi.check_start = ev_check_start;
467 evapi.check_stop = ev_check_stop; 418 evapi.check_stop = ev_check_stop;
468 evapi.child_start = ev_child_start; 419 evapi.child_start = ev_child_start;
469 evapi.child_stop = ev_child_stop; 420 evapi.child_stop = ev_child_stop;
470 evapi.stat_start = ev_stat_start; 421 evapi.stat_start = ev_stat_start;
471 evapi.stat_stop = ev_stat_stop; 422 evapi.stat_stop = ev_stat_stop;
472 evapi.stat_stat = ev_stat_stat; 423 evapi.stat_stat = ev_stat_stat;
424 evapi.embed_start = ev_embed_start;
425 evapi.embed_stop = ev_embed_stop;
426 evapi.embed_sweep = ev_embed_sweep;
427 evapi.fork_start = ev_fork_start;
428 evapi.fork_stop = ev_fork_stop;
429 evapi.clear_pending = ev_clear_pending;
430 evapi.invoke = ev_invoke;
473 431
474 sv_setiv (sv, (IV)&evapi); 432 sv_setiv (sv, (IV)&evapi);
475 SvREADONLY_on (sv); 433 SvREADONLY_on (sv);
476 } 434 }
477#ifndef _WIN32 435#ifndef _WIN32
478 pthread_atfork (0, 0, ev_default_fork); 436 pthread_atfork (0, 0, ev_default_fork);
479#endif 437#endif
480} 438}
481 439
440SV *ev_default_loop (unsigned int flags = ev_supported_backends ())
441 CODE:
442{
443 if (!default_loop_sv)
444 {
445 evapi.default_loop = ev_default_loop (flags);
446
447 if (!evapi.default_loop)
448 XSRETURN_UNDEF;
449
450 default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
451 }
452
453 RETVAL = newSVsv (default_loop_sv);
454}
455 OUTPUT:
456 RETVAL
457
458NV ev_time ()
459
482NV ev_now () 460NV ev_now ()
461 C_ARGS: evapi.default_loop
483 462
484unsigned int ev_backend () 463unsigned int ev_backend ()
464 C_ARGS: evapi.default_loop
485 465
486NV ev_time () 466unsigned int ev_loop_count ()
487 467 C_ARGS: evapi.default_loop
488unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
489 468
490void ev_loop (int flags = 0) 469void ev_loop (int flags = 0)
470 C_ARGS: evapi.default_loop, flags
491 471
492void ev_unloop (int how = 1) 472void ev_unloop (int how = 1)
473 C_ARGS: evapi.default_loop, how
474
475void ev_feed_fd_event (int fd, int revents = EV_NONE)
476 C_ARGS: evapi.default_loop, fd, revents
477
478void ev_feed_signal_event (SV *signal)
479 CODE:
480{
481 Signal signum = sv_signum (signal);
482 CHECK_SIG (signal, signum);
483
484 ev_feed_signal_event (evapi.default_loop, signum);
485}
493 486
494ev_io *io (SV *fh, int events, SV *cb) 487ev_io *io (SV *fh, int events, SV *cb)
495 ALIAS: 488 ALIAS:
496 io_ns = 1 489 io_ns = 1
497 CODE: 490 CODE:
498{ 491{
499 int fd = sv_fileno (fh); 492 int fd = sv_fileno (fh);
500 CHECK_FD (fh, fd); 493 CHECK_FD (fh, fd);
501 494
502 RETVAL = e_new (sizeof (ev_io), cb); 495 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
503 RETVAL->fh = newSVsv (fh); 496 RETVAL->fh = newSVsv (fh);
504 ev_io_set (RETVAL, fd, events); 497 ev_io_set (RETVAL, fd, events);
505 if (!ix) START (io, RETVAL); 498 if (!ix) START (io, RETVAL);
506} 499}
507 OUTPUT: 500 OUTPUT:
511 ALIAS: 504 ALIAS:
512 timer_ns = 1 505 timer_ns = 1
513 INIT: 506 INIT:
514 CHECK_REPEAT (repeat); 507 CHECK_REPEAT (repeat);
515 CODE: 508 CODE:
516 RETVAL = e_new (sizeof (ev_timer), cb); 509 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
517 ev_timer_set (RETVAL, after, repeat); 510 ev_timer_set (RETVAL, after, repeat);
518 if (!ix) START (timer, RETVAL); 511 if (!ix) START (timer, RETVAL);
519 OUTPUT: 512 OUTPUT:
520 RETVAL 513 RETVAL
521 514
525 INIT: 518 INIT:
526 CHECK_REPEAT (interval); 519 CHECK_REPEAT (interval);
527 CODE: 520 CODE:
528{ 521{
529 ev_periodic *w; 522 ev_periodic *w;
530 w = e_new (sizeof (ev_periodic), cb); 523 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
531 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 524 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
532 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 525 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
533 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 526 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
534 if (!ix) START (periodic, w); 527 if (!ix) START (periodic, w);
535} 528}
542 CODE: 535 CODE:
543{ 536{
544 Signal signum = sv_signum (signal); 537 Signal signum = sv_signum (signal);
545 CHECK_SIG (signal, signum); 538 CHECK_SIG (signal, signum);
546 539
547 RETVAL = e_new (sizeof (ev_signal), cb); 540 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
548 ev_signal_set (RETVAL, signum); 541 ev_signal_set (RETVAL, signum);
549 if (!ix) START (signal, RETVAL); 542 if (!ix) START (signal, RETVAL);
550} 543}
551 OUTPUT: 544 OUTPUT:
552 RETVAL 545 RETVAL
553 546
554ev_idle *idle (SV *cb) 547ev_idle *idle (SV *cb)
555 ALIAS: 548 ALIAS:
556 idle_ns = 1 549 idle_ns = 1
557 CODE: 550 CODE:
558 RETVAL = e_new (sizeof (ev_idle), cb); 551 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
559 ev_idle_set (RETVAL); 552 ev_idle_set (RETVAL);
560 if (!ix) START (idle, RETVAL); 553 if (!ix) START (idle, RETVAL);
561 OUTPUT: 554 OUTPUT:
562 RETVAL 555 RETVAL
563 556
564ev_prepare *prepare (SV *cb) 557ev_prepare *prepare (SV *cb)
565 ALIAS: 558 ALIAS:
566 prepare_ns = 1 559 prepare_ns = 1
567 CODE: 560 CODE:
568 RETVAL = e_new (sizeof (ev_prepare), cb); 561 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
569 ev_prepare_set (RETVAL); 562 ev_prepare_set (RETVAL);
570 if (!ix) START (prepare, RETVAL); 563 if (!ix) START (prepare, RETVAL);
571 OUTPUT: 564 OUTPUT:
572 RETVAL 565 RETVAL
573 566
574ev_check *check (SV *cb) 567ev_check *check (SV *cb)
575 ALIAS: 568 ALIAS:
576 check_ns = 1 569 check_ns = 1
577 CODE: 570 CODE:
578 RETVAL = e_new (sizeof (ev_check), cb); 571 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
579 ev_check_set (RETVAL); 572 ev_check_set (RETVAL);
580 if (!ix) START (check, RETVAL); 573 if (!ix) START (check, RETVAL);
581 OUTPUT: 574 OUTPUT:
582 RETVAL 575 RETVAL
583 576
577ev_fork *fork (SV *cb)
578 ALIAS:
579 fork_ns = 1
580 CODE:
581 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
582 ev_fork_set (RETVAL);
583 if (!ix) START (fork, RETVAL);
584 OUTPUT:
585 RETVAL
586
584ev_child *child (int pid, SV *cb) 587ev_child *child (int pid, SV *cb)
585 ALIAS: 588 ALIAS:
586 child_ns = 1 589 child_ns = 1
587 CODE: 590 CODE:
588 RETVAL = e_new (sizeof (ev_child), cb); 591 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
589 ev_child_set (RETVAL, pid); 592 ev_child_set (RETVAL, pid);
590 if (!ix) START (child, RETVAL); 593 if (!ix) START (child, RETVAL);
591 OUTPUT: 594 OUTPUT:
592 RETVAL 595 RETVAL
593 596
594ev_stat *stat (SV *path, NV interval, SV *cb) 597ev_stat *stat (SV *path, NV interval, SV *cb)
595 ALIAS: 598 ALIAS:
596 stat_ns = 1 599 stat_ns = 1
597 CODE: 600 CODE:
598 RETVAL = e_new (sizeof (ev_stat), cb); 601 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
599 RETVAL->fh = newSVsv (path); 602 RETVAL->fh = newSVsv (path);
600 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 603 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
601 if (!ix) START (stat, RETVAL); 604 if (!ix) START (stat, RETVAL);
602 OUTPUT: 605 OUTPUT:
603 RETVAL 606 RETVAL
604 607
608ev_embed *embed (struct ev_loop *loop, SV *cb)
609 ALIAS:
610 embed_ns = 1
611 CODE:
612 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
613 RETVAL->fh = newSVsv (ST (0));
614 ev_embed_set (RETVAL, loop);
615 if (!ix) START (embed, RETVAL);
616 OUTPUT:
617 RETVAL
618
605void once (SV *fh, int events, SV *timeout, SV *cb) 619void once (SV *fh, int events, SV *timeout, SV *cb)
606 CODE: 620 CODE:
607 ev_once ( 621 ev_once (
622 evapi.default_loop,
608 sv_fileno (fh), events, 623 sv_fileno (fh), events,
609 SvOK (timeout) ? SvNV (timeout) : -1., 624 SvOK (timeout) ? SvNV (timeout) : -1.,
610 e_once_cb, 625 e_once_cb,
611 newSVsv (cb) 626 newSVsv (cb)
612 ); 627 );
616MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 631MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
617 632
618int ev_is_active (ev_watcher *w) 633int ev_is_active (ev_watcher *w)
619 634
620int ev_is_pending (ev_watcher *w) 635int ev_is_pending (ev_watcher *w)
636
637void ev_invoke (ev_watcher *w, int revents = EV_NONE)
638 C_ARGS: e_loop (w), w, revents
639
640int ev_clear_pending (ev_watcher *w)
641 C_ARGS: e_loop (w), w
642
643void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
644 C_ARGS: e_loop (w), w, revents
621 645
622int keepalive (ev_watcher *w, int new_value = 0) 646int keepalive (ev_watcher *w, int new_value = 0)
623 CODE: 647 CODE:
624{ 648{
625 RETVAL = w->flags & WFLAG_KEEPALIVE; 649 RETVAL = w->flags & WFLAG_KEEPALIVE;
658 } 682 }
659} 683}
660 OUTPUT: 684 OUTPUT:
661 RETVAL 685 RETVAL
662 686
663void trigger (ev_watcher *w, int revents = EV_NONE)
664 CODE:
665 w->cb (w, revents);
666
667int priority (ev_watcher *w, int new_priority = 0) 687int priority (ev_watcher *w, int new_priority = 0)
668 CODE: 688 CODE:
669{ 689{
670 RETVAL = w->priority; 690 RETVAL = w->priority;
671 691
672 if (items > 1) 692 if (items > 1)
673 { 693 {
674 int active = ev_is_active (w); 694 int active = ev_is_active (w);
675
676 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
677 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
678 695
679 if (active) 696 if (active)
680 { 697 {
681 /* grrr. */ 698 /* grrr. */
682 PUSHMARK (SP); 699 PUSHMARK (SP);
683 XPUSHs (ST (0)); 700 XPUSHs (ST (0));
701 PUTBACK;
684 call_method ("stop", G_DISCARD | G_VOID); 702 call_method ("stop", G_DISCARD | G_VOID);
685 } 703 }
686 704
687 ev_set_priority (w, new_priority); 705 ev_set_priority (w, new_priority);
688 706
689 if (active) 707 if (active)
690 { 708 {
691 PUSHMARK (SP); 709 PUSHMARK (SP);
692 XPUSHs (ST (0)); 710 XPUSHs (ST (0));
711 PUTBACK;
693 call_method ("start", G_DISCARD | G_VOID); 712 call_method ("start", G_DISCARD | G_VOID);
694 } 713 }
695 } 714 }
696} 715}
697 OUTPUT: 716 OUTPUT:
807void ev_timer_again (ev_timer *w) 826void ev_timer_again (ev_timer *w)
808 INIT: 827 INIT:
809 CHECK_REPEAT (w->repeat); 828 CHECK_REPEAT (w->repeat);
810 CODE: 829 CODE:
811 REF (w); 830 REF (w);
812 ev_timer_again (w); 831 ev_timer_again (e_loop (w), w);
813 UNREF (w); 832 UNREF (w);
814 833
815void DESTROY (ev_timer *w) 834void DESTROY (ev_timer *w)
816 CODE: 835 CODE:
817 STOP (timer, w); 836 STOP (timer, w);
821 INIT: 840 INIT:
822 CHECK_REPEAT (repeat); 841 CHECK_REPEAT (repeat);
823 CODE: 842 CODE:
824 RESET (timer, w, (w, after, repeat)); 843 RESET (timer, w, (w, after, repeat));
825 844
845NV at (ev_timer *w)
846 CODE:
847 RETVAL = w->at;
848 OUTPUT:
849 RETVAL
850
826MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 851MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
827 852
828void ev_periodic_start (ev_periodic *w) 853void ev_periodic_start (ev_periodic *w)
829 INIT: 854 INIT:
830 CHECK_REPEAT (w->interval); 855 CHECK_REPEAT (w->interval);
836 STOP (periodic, w); 861 STOP (periodic, w);
837 862
838void ev_periodic_again (ev_periodic *w) 863void ev_periodic_again (ev_periodic *w)
839 CODE: 864 CODE:
840 REF (w); 865 REF (w);
841 ev_periodic_again (w); 866 ev_periodic_again (e_loop (w), w);
842 UNREF (w); 867 UNREF (w);
843 868
844void DESTROY (ev_periodic *w) 869void DESTROY (ev_periodic *w)
845 CODE: 870 CODE:
846 STOP (periodic, w); 871 STOP (periodic, w);
855 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 880 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
856 881
857 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 882 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
858} 883}
859 884
885NV at (ev_periodic *w)
886 CODE:
887 RETVAL = w->at;
888 OUTPUT:
889 RETVAL
890
860MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 891MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
861 892
862void ev_idle_start (ev_idle *w) 893void ev_idle_start (ev_idle *w)
863 CODE: 894 CODE:
864 START (idle, w); 895 START (idle, w);
898 STOP (check, w); 929 STOP (check, w);
899 930
900void DESTROY (ev_check *w) 931void DESTROY (ev_check *w)
901 CODE: 932 CODE:
902 STOP (check, w); 933 STOP (check, w);
934 e_destroy (w);
935
936MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
937
938void ev_fork_start (ev_fork *w)
939 CODE:
940 START (fork, w);
941
942void ev_fork_stop (ev_fork *w)
943 CODE:
944 STOP (fork, w);
945
946void DESTROY (ev_fork *w)
947 CODE:
948 STOP (fork, w);
903 e_destroy (w); 949 e_destroy (w);
904 950
905MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 951MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
906 952
907void ev_child_start (ev_child *w) 953void ev_child_start (ev_child *w)
996 PPCODE: 1042 PPCODE:
997{ 1043{
998 ev_statdata *s = ix ? &w->attr : &w->prev; 1044 ev_statdata *s = ix ? &w->attr : &w->prev;
999 1045
1000 if (ix == 1) 1046 if (ix == 1)
1001 ev_stat_stat (w); 1047 ev_stat_stat (e_loop (w), w);
1002 else if (!s->st_nlink) 1048 else if (!s->st_nlink)
1003 errno = ENOENT; 1049 errno = ENOENT;
1004 1050
1005 PL_statcache.st_dev = s->st_nlink; 1051 PL_statcache.st_dev = s->st_nlink;
1006 PL_statcache.st_ino = s->st_ino; 1052 PL_statcache.st_ino = s->st_ino;
1033 PUSHs (sv_2mortal (newSVuv (4096))); 1079 PUSHs (sv_2mortal (newSVuv (4096)));
1034 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 1080 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1035 } 1081 }
1036} 1082}
1037 1083
1038#ifndef _WIN32
1039
1040MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 1084MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1041 1085
1042BOOT: 1086void ev_embed_start (ev_embed *w)
1043{ 1087 CODE:
1044 HV *stash = gv_stashpv ("EV::DNS", 1); 1088 START (embed, w);
1045 1089
1046 static const struct { 1090void ev_embed_stop (ev_embed *w)
1047 const char *name; 1091 CODE:
1048 IV iv; 1092 STOP (embed, w);
1049 } *civ, const_iv[] = {
1050# define const_iv(pfx, name) { # name, (IV) pfx ## name },
1051 const_iv (DNS_, ERR_NONE)
1052 const_iv (DNS_, ERR_FORMAT)
1053 const_iv (DNS_, ERR_SERVERFAILED)
1054 const_iv (DNS_, ERR_NOTEXIST)
1055 const_iv (DNS_, ERR_NOTIMPL)
1056 const_iv (DNS_, ERR_REFUSED)
1057 const_iv (DNS_, ERR_TRUNCATED)
1058 const_iv (DNS_, ERR_UNKNOWN)
1059 const_iv (DNS_, ERR_TIMEOUT)
1060 const_iv (DNS_, ERR_SHUTDOWN)
1061 const_iv (DNS_, IPv4_A)
1062 const_iv (DNS_, PTR)
1063 const_iv (DNS_, IPv6_AAAA)
1064 const_iv (DNS_, QUERY_NO_SEARCH)
1065 const_iv (DNS_, OPTION_SEARCH)
1066 const_iv (DNS_, OPTION_NAMESERVERS)
1067 const_iv (DNS_, OPTION_MISC)
1068 const_iv (DNS_, OPTIONS_ALL)
1069 const_iv (DNS_, NO_SEARCH)
1070 };
1071 1093
1072 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1094void DESTROY (ev_embed *w)
1073 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1095 CODE:
1074} 1096 STOP (embed, w);
1097 e_destroy (w);
1075 1098
1076int evdns_init () 1099void set (ev_embed *w, struct ev_loop *loop)
1077 1100 CODE:
1078void evdns_shutdown (int fail_requests = 1)
1079
1080const char *evdns_err_to_string (int err)
1081
1082int evdns_nameserver_add (U32 address)
1083
1084int evdns_count_nameservers ()
1085
1086int evdns_clear_nameservers_and_suspend ()
1087
1088int evdns_resume ()
1089
1090int evdns_nameserver_ip_add (char *ip_as_string)
1091
1092int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
1093 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1094
1095int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
1096 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1097
1098int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
1099 ALIAS:
1100 evdns_resolve_reverse_ipv6 = 1
1101 CODE:
1102{ 1101{
1103 STRLEN len; 1102 sv_setsv (w->fh, ST (1));
1104 char *data = SvPVbyte (addr, len); 1103 RESET (embed, w, (w, loop));
1105 if (len != (ix ? 16 : 4)) 1104}
1106 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
1107 1105
1106MODULE = EV PACKAGE = EV::Loop PREFIX = ev_loop_
1107
1108SV *new (SV *klass, unsigned int flags = ev_supported_backends ())
1109 CODE:
1110{
1111 struct ev_loop *loop = ev_loop_new (flags);
1112
1113 if (!loop)
1114 XSRETURN_UNDEF;
1115
1116 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
1117}
1118 OUTPUT:
1108 RETVAL = ix 1119 RETVAL
1109 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
1110 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
1111}
1112 OUTPUT:
1113 RETVAL
1114 1120
1115int evdns_set_option (char *option, char *val, int flags) 1121void DESTROY (struct ev_loop *loop)
1122 CODE:
1123 if (loop != evapi.default_loop) /* global destruction sucks */
1124 ev_loop_destroy (loop);
1116 1125
1117int evdns_resolv_conf_parse (int flags, const char *filename) 1126ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1118 1127 ALIAS:
1119#ifdef _WIN32 1128 io_ns = 1
1120 1129 CODE:
1121int evdns_config_windows_nameservers ()
1122
1123#endif
1124
1125void evdns_search_clear ()
1126
1127void evdns_search_add (char *domain)
1128
1129void evdns_search_ndots_set (int ndots)
1130
1131#if 0
1132
1133MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1134
1135BOOT:
1136{ 1130{
1137 HV *stash = gv_stashpv ("EV::HTTP", 1); 1131 int fd = sv_fileno (fh);
1132 CHECK_FD (fh, fd);
1138 1133
1139 static const struct { 1134 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1140 const char *name; 1135 RETVAL->fh = newSVsv (fh);
1141 IV iv; 1136 ev_io_set (RETVAL, fd, events);
1142 } *civ, const_iv[] = { 1137 if (!ix) START (io, RETVAL);
1143# define const_iv(pfx, name) { # name, (IV) pfx ## name },
1144 const_iv (HTTP_, OK)
1145 const_iv (HTTP_, NOCONTENT)
1146 const_iv (HTTP_, MOVEPERM)
1147 const_iv (HTTP_, MOVETEMP)
1148 const_iv (HTTP_, NOTMODIFIED)
1149 const_iv (HTTP_, BADREQUEST)
1150 const_iv (HTTP_, NOTFOUND)
1151 const_iv (HTTP_, SERVUNAVAIL)
1152 const_iv (EVHTTP_, REQ_OWN_CONNECTION)
1153 const_iv (EVHTTP_, PROXY_REQUEST)
1154 const_iv (EVHTTP_, REQ_GET)
1155 const_iv (EVHTTP_, REQ_POST)
1156 const_iv (EVHTTP_, REQ_HEAD)
1157 const_iv (EVHTTP_, REQUEST)
1158 const_iv (EVHTTP_, RESPONSE)
1159 };
1160
1161 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1162 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1163} 1138}
1139 OUTPUT:
1140 RETVAL
1164 1141
1165MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
1166
1167#HttpRequest new (SV *klass, SV *cb)
1168
1169#void DESTROY (struct evhttp_request *req);
1170
1171#endif
1172
1173#endif
1174
1175
1176
1177
1178
1179
1180

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines