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

Comparing EV/EV.xs (file contents):
Revision 1.85 by root, Sat Dec 1 22:51:34 2007 UTC vs.
Revision 1.104 by root, Fri Jan 25 15:45:08 2008 UTC

3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define EV_PROTOTYPES 1 7#define EV_PROTOTYPES 1
8#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
9#define EV_H <ev.h>
8#include "EV/EVAPI.h" 10#include "EV/EVAPI.h"
9 11
10/* fix perl api breakage */ 12/* fix perl api breakage */
11#undef signal 13#undef signal
12#undef sigaction 14#undef sigaction
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
24#ifndef _WIN32 25#ifndef _WIN32
25# include <pthread.h> 26# include <pthread.h>
26#endif 27#endif
27 28
29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
30
28#define WFLAG_KEEPALIVE 1 31#define WFLAG_KEEPALIVE 1
29 32
30#define UNREF(w) \ 33#define UNREF(w) \
31 if (!((w)->flags & WFLAG_KEEPALIVE) \ 34 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
32 && !ev_is_active (w)) \ 35 && !ev_is_active (w)) \
33 ev_unref (); 36 ev_unref (e_loop (w));
34 37
35#define REF(w) \ 38#define REF(w) \
36 if (!((w)->flags & WFLAG_KEEPALIVE) \ 39 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
37 && ev_is_active (w)) \ 40 && ev_is_active (w)) \
38 ev_ref (); 41 ev_ref (e_loop (w));
39 42
40#define START(type,w) \ 43#define START(type,w) \
41 do { \ 44 do { \
42 UNREF (w); \ 45 UNREF (w); \
43 ev_ ## type ## _start (w); \ 46 ev_ ## type ## _start (e_loop (w), w); \
44 } while (0) 47 } while (0)
45 48
46#define STOP(type,w) \ 49#define STOP(type,w) \
47 do { \ 50 do { \
48 REF (w); \ 51 REF (w); \
49 ev_ ## type ## _stop (w); \ 52 ev_ ## type ## _stop (e_loop (w), w); \
50 } while (0) 53 } while (0)
51 54
52#define RESET(type,w,seta) \ 55#define RESET(type,w,seta) \
53 do { \ 56 do { \
54 int active = ev_is_active (w); \ 57 int active = ev_is_active (w); \
57 if (active) START (type, w); \ 60 if (active) START (type, w); \
58 } while (0) 61 } while (0)
59 62
60typedef int Signal; 63typedef int Signal;
61 64
65static SV *default_loop_sv;
66
62static struct EVAPI evapi; 67static struct EVAPI evapi;
63 68
64static HV 69static HV
70 *stash_loop,
65 *stash_watcher, 71 *stash_watcher,
66 *stash_io, 72 *stash_io,
67 *stash_timer, 73 *stash_timer,
68 *stash_periodic, 74 *stash_periodic,
69 *stash_signal, 75 *stash_signal,
101} 107}
102 108
103///////////////////////////////////////////////////////////////////////////// 109/////////////////////////////////////////////////////////////////////////////
104// Event 110// Event
105 111
106static void e_cb (ev_watcher *w, int revents); 112static void e_cb (EV_P_ ev_watcher *w, int revents);
107 113
108static int 114static int
109sv_fileno (SV *fh) 115sv_fileno (SV *fh)
110{ 116{
111 SvGETMAGIC (fh); 117 SvGETMAGIC (fh);
121 127
122 return -1; 128 return -1;
123} 129}
124 130
125static void * 131static void *
126e_new (int size, SV *cb_sv) 132e_new (int size, SV *cb_sv, SV *loop)
127{ 133{
128 ev_watcher *w; 134 ev_watcher *w;
129 SV *self = NEWSV (0, size); 135 SV *self = NEWSV (0, size);
130 SvPOK_only (self); 136 SvPOK_only (self);
131 SvCUR_set (self, size); 137 SvCUR_set (self, size);
132 138
133 w = (ev_watcher *)SvPVX (self); 139 w = (ev_watcher *)SvPVX (self);
134 140
135 ev_init (w, e_cb); 141 ev_init (w, e_cb);
136 142
143 w->loop = SvREFCNT_inc (SvRV (loop));
137 w->flags = WFLAG_KEEPALIVE; 144 w->e_flags = WFLAG_KEEPALIVE;
138 w->data = 0; 145 w->data = 0;
139 w->fh = 0; 146 w->fh = 0;
140 w->cb_sv = newSVsv (cb_sv); 147 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv);
141 w->self = self; 148 w->self = self;
142 149
143 return (void *)w; 150 return (void *)w;
144} 151}
145 152
146static void 153static void
147e_destroy (void *w_) 154e_destroy (void *w_)
148{ 155{
149 ev_watcher *w = (ev_watcher *)w_; 156 ev_watcher *w = (ev_watcher *)w_;
150 157
158 SvREFCNT_dec (w->loop ); w->loop = 0;
151 SvREFCNT_dec (w->fh ); w->fh = 0; 159 SvREFCNT_dec (w->fh ); w->fh = 0;
152 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 160 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
153 SvREFCNT_dec (w->data ); w->data = 0; 161 SvREFCNT_dec (w->data ); w->data = 0;
154} 162}
155 163
171} 179}
172 180
173static SV *sv_events_cache; 181static SV *sv_events_cache;
174 182
175static void 183static void
176e_cb (ev_watcher *w, int revents) 184e_cb (EV_P_ ev_watcher *w, int revents)
177{ 185{
178 dSP; 186 dSP;
179 I32 mark = SP - PL_stack_base; 187 I32 mark = SP - PL_stack_base;
180 SV *sv_self, *sv_events; 188 SV *sv_self, *sv_events;
181 189
244 else 252 else
245 sv_events_cache = sv_events; 253 sv_events_cache = sv_events;
246 254
247 if (SvTRUE (ERRSV)) 255 if (SvTRUE (ERRSV))
248 { 256 {
257 SPAGAIN;
249 PUSHMARK (SP); 258 PUSHMARK (SP);
250 PUTBACK; 259 PUTBACK;
251 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 260 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
252 } 261 }
253 262
353 }; 362 };
354 363
355 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 364 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
356 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 365 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
357 366
367 stash_loop = gv_stashpv ("EV::Loop" , 1);
358 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 368 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
359 stash_io = gv_stashpv ("EV::IO" , 1); 369 stash_io = gv_stashpv ("EV::IO" , 1);
360 stash_timer = gv_stashpv ("EV::Timer" , 1); 370 stash_timer = gv_stashpv ("EV::Timer" , 1);
361 stash_periodic = gv_stashpv ("EV::Periodic", 1); 371 stash_periodic = gv_stashpv ("EV::Periodic", 1);
362 stash_signal = gv_stashpv ("EV::Signal" , 1); 372 stash_signal = gv_stashpv ("EV::Signal" , 1);
364 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 374 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
365 stash_check = gv_stashpv ("EV::Check" , 1); 375 stash_check = gv_stashpv ("EV::Check" , 1);
366 stash_child = gv_stashpv ("EV::Child" , 1); 376 stash_child = gv_stashpv ("EV::Child" , 1);
367 stash_embed = gv_stashpv ("EV::Embed" , 1); 377 stash_embed = gv_stashpv ("EV::Embed" , 1);
368 stash_stat = gv_stashpv ("EV::Stat" , 1); 378 stash_stat = gv_stashpv ("EV::Stat" , 1);
379 stash_fork = gv_stashpv ("EV::Fork" , 1);
369 380
370 { 381 {
371 SV *sv = perl_get_sv ("EV::API", TRUE); 382 SV *sv = perl_get_sv ("EV::API", TRUE);
372 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 383 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
373 384
374 /* the poor man's shared library emulator */ 385 /* the poor man's shared library emulator */
375 evapi.ver = EV_API_VERSION; 386 evapi.ver = EV_API_VERSION;
376 evapi.rev = EV_API_REVISION; 387 evapi.rev = EV_API_REVISION;
377 evapi.sv_fileno = sv_fileno; 388 evapi.sv_fileno = sv_fileno;
378 evapi.sv_signum = sv_signum; 389 evapi.sv_signum = sv_signum;
390 evapi.supported_backends = ev_supported_backends ();
391 evapi.recommended_backends = ev_recommended_backends ();
392 evapi.embeddable_backends = ev_embeddable_backends ();
393 evapi.time = ev_time;
394 evapi.sleep = ev_sleep;
395 evapi.loop_new = ev_loop_new;
396 evapi.loop_destroy = ev_loop_destroy;
397 evapi.loop_fork = ev_loop_fork;
398 evapi.loop_count = ev_loop_count;
379 evapi.now = ev_now; 399 evapi.now = ev_now;
380 evapi.backend = ev_backend; 400 evapi.backend = ev_backend;
381 evapi.unloop = ev_unloop; 401 evapi.unloop = ev_unloop;
382 evapi.ref = ev_ref; 402 evapi.ref = ev_ref;
383 evapi.unref = ev_unref; 403 evapi.unref = ev_unref;
384 evapi.time = ev_time;
385 evapi.loop = ev_loop; 404 evapi.loop = ev_loop;
386 evapi.once = ev_once; 405 evapi.once = ev_once;
387 evapi.io_start = ev_io_start; 406 evapi.io_start = ev_io_start;
388 evapi.io_stop = ev_io_stop; 407 evapi.io_stop = ev_io_stop;
389 evapi.timer_start = ev_timer_start; 408 evapi.timer_start = ev_timer_start;
390 evapi.timer_stop = ev_timer_stop; 409 evapi.timer_stop = ev_timer_stop;
391 evapi.timer_again = ev_timer_again; 410 evapi.timer_again = ev_timer_again;
392 evapi.periodic_start = ev_periodic_start; 411 evapi.periodic_start = ev_periodic_start;
393 evapi.periodic_stop = ev_periodic_stop; 412 evapi.periodic_stop = ev_periodic_stop;
394 evapi.signal_start = ev_signal_start; 413 evapi.signal_start = ev_signal_start;
395 evapi.signal_stop = ev_signal_stop; 414 evapi.signal_stop = ev_signal_stop;
396 evapi.idle_start = ev_idle_start; 415 evapi.idle_start = ev_idle_start;
397 evapi.idle_stop = ev_idle_stop; 416 evapi.idle_stop = ev_idle_stop;
398 evapi.prepare_start = ev_prepare_start; 417 evapi.prepare_start = ev_prepare_start;
399 evapi.prepare_stop = ev_prepare_stop; 418 evapi.prepare_stop = ev_prepare_stop;
400 evapi.check_start = ev_check_start; 419 evapi.check_start = ev_check_start;
401 evapi.check_stop = ev_check_stop; 420 evapi.check_stop = ev_check_stop;
402 evapi.child_start = ev_child_start; 421 evapi.child_start = ev_child_start;
403 evapi.child_stop = ev_child_stop; 422 evapi.child_stop = ev_child_stop;
404 evapi.stat_start = ev_stat_start; 423 evapi.stat_start = ev_stat_start;
405 evapi.stat_stop = ev_stat_stop; 424 evapi.stat_stop = ev_stat_stop;
406 evapi.stat_stat = ev_stat_stat; 425 evapi.stat_stat = ev_stat_stat;
426 evapi.embed_start = ev_embed_start;
427 evapi.embed_stop = ev_embed_stop;
428 evapi.embed_sweep = ev_embed_sweep;
429 evapi.fork_start = ev_fork_start;
430 evapi.fork_stop = ev_fork_stop;
431 evapi.clear_pending = ev_clear_pending;
432 evapi.invoke = ev_invoke;
407 433
408 sv_setiv (sv, (IV)&evapi); 434 sv_setiv (sv, (IV)&evapi);
409 SvREADONLY_on (sv); 435 SvREADONLY_on (sv);
410 } 436 }
411#ifndef _WIN32 437#ifndef _WIN32
412 pthread_atfork (0, 0, ev_default_fork); 438 pthread_atfork (0, 0, ev_default_fork);
413#endif 439#endif
414} 440}
415 441
442SV *ev_default_loop (unsigned int flags = 0)
443 CODE:
444{
445 if (!default_loop_sv)
446 {
447 evapi.default_loop = ev_default_loop (flags);
448
449 if (!evapi.default_loop)
450 XSRETURN_UNDEF;
451
452 default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
453 }
454
455 RETVAL = newSVsv (default_loop_sv);
456}
457 OUTPUT:
458 RETVAL
459
460void ev_default_destroy ()
461 CODE:
462 ev_default_destroy ();
463 SvREFCNT_dec (default_loop_sv);
464 default_loop_sv = 0;
465
466unsigned int ev_supported_backends ()
467
468unsigned int ev_recommended_backends ()
469
470unsigned int ev_embeddable_backends ()
471
472NV ev_time ()
473
416NV ev_now () 474NV ev_now ()
475 C_ARGS: evapi.default_loop
417 476
418unsigned int ev_backend () 477unsigned int ev_backend ()
478 C_ARGS: evapi.default_loop
419 479
420NV ev_time () 480unsigned int ev_loop_count ()
481 C_ARGS: evapi.default_loop
421 482
422unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) 483void ev_set_io_collect_interval (NV interval)
484 C_ARGS: evapi.default_loop, interval
485
486void ev_set_timeout_collect_interval (NV interval)
487 C_ARGS: evapi.default_loop, interval
423 488
424void ev_loop (int flags = 0) 489void ev_loop (int flags = 0)
490 C_ARGS: evapi.default_loop, flags
425 491
426void ev_unloop (int how = 1) 492void ev_unloop (int how = EVUNLOOP_ONE)
493 C_ARGS: evapi.default_loop, how
494
495void ev_feed_fd_event (int fd, int revents = EV_NONE)
496 C_ARGS: evapi.default_loop, fd, revents
497
498void ev_feed_signal_event (SV *signal)
499 CODE:
500{
501 Signal signum = sv_signum (signal);
502 CHECK_SIG (signal, signum);
503
504 ev_feed_signal_event (evapi.default_loop, signum);
505}
427 506
428ev_io *io (SV *fh, int events, SV *cb) 507ev_io *io (SV *fh, int events, SV *cb)
429 ALIAS: 508 ALIAS:
430 io_ns = 1 509 io_ns = 1
431 CODE: 510 CODE:
432{ 511{
433 int fd = sv_fileno (fh); 512 int fd = sv_fileno (fh);
434 CHECK_FD (fh, fd); 513 CHECK_FD (fh, fd);
435 514
436 RETVAL = e_new (sizeof (ev_io), cb); 515 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
437 RETVAL->fh = newSVsv (fh); 516 RETVAL->fh = newSVsv (fh);
438 ev_io_set (RETVAL, fd, events); 517 ev_io_set (RETVAL, fd, events);
439 if (!ix) START (io, RETVAL); 518 if (!ix) START (io, RETVAL);
440} 519}
441 OUTPUT: 520 OUTPUT:
445 ALIAS: 524 ALIAS:
446 timer_ns = 1 525 timer_ns = 1
447 INIT: 526 INIT:
448 CHECK_REPEAT (repeat); 527 CHECK_REPEAT (repeat);
449 CODE: 528 CODE:
450 RETVAL = e_new (sizeof (ev_timer), cb); 529 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
451 ev_timer_set (RETVAL, after, repeat); 530 ev_timer_set (RETVAL, after, repeat);
452 if (!ix) START (timer, RETVAL); 531 if (!ix) START (timer, RETVAL);
453 OUTPUT: 532 OUTPUT:
454 RETVAL 533 RETVAL
455 534
459 INIT: 538 INIT:
460 CHECK_REPEAT (interval); 539 CHECK_REPEAT (interval);
461 CODE: 540 CODE:
462{ 541{
463 ev_periodic *w; 542 ev_periodic *w;
464 w = e_new (sizeof (ev_periodic), cb); 543 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
465 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 544 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
466 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 545 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
467 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 546 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
468 if (!ix) START (periodic, w); 547 if (!ix) START (periodic, w);
469} 548}
476 CODE: 555 CODE:
477{ 556{
478 Signal signum = sv_signum (signal); 557 Signal signum = sv_signum (signal);
479 CHECK_SIG (signal, signum); 558 CHECK_SIG (signal, signum);
480 559
481 RETVAL = e_new (sizeof (ev_signal), cb); 560 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
482 ev_signal_set (RETVAL, signum); 561 ev_signal_set (RETVAL, signum);
483 if (!ix) START (signal, RETVAL); 562 if (!ix) START (signal, RETVAL);
484} 563}
485 OUTPUT: 564 OUTPUT:
486 RETVAL 565 RETVAL
487 566
488ev_idle *idle (SV *cb) 567ev_idle *idle (SV *cb)
489 ALIAS: 568 ALIAS:
490 idle_ns = 1 569 idle_ns = 1
491 CODE: 570 CODE:
492 RETVAL = e_new (sizeof (ev_idle), cb); 571 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
493 ev_idle_set (RETVAL); 572 ev_idle_set (RETVAL);
494 if (!ix) START (idle, RETVAL); 573 if (!ix) START (idle, RETVAL);
495 OUTPUT: 574 OUTPUT:
496 RETVAL 575 RETVAL
497 576
498ev_prepare *prepare (SV *cb) 577ev_prepare *prepare (SV *cb)
499 ALIAS: 578 ALIAS:
500 prepare_ns = 1 579 prepare_ns = 1
501 CODE: 580 CODE:
502 RETVAL = e_new (sizeof (ev_prepare), cb); 581 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
503 ev_prepare_set (RETVAL); 582 ev_prepare_set (RETVAL);
504 if (!ix) START (prepare, RETVAL); 583 if (!ix) START (prepare, RETVAL);
505 OUTPUT: 584 OUTPUT:
506 RETVAL 585 RETVAL
507 586
508ev_check *check (SV *cb) 587ev_check *check (SV *cb)
509 ALIAS: 588 ALIAS:
510 check_ns = 1 589 check_ns = 1
511 CODE: 590 CODE:
512 RETVAL = e_new (sizeof (ev_check), cb); 591 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
513 ev_check_set (RETVAL); 592 ev_check_set (RETVAL);
514 if (!ix) START (check, RETVAL); 593 if (!ix) START (check, RETVAL);
515 OUTPUT: 594 OUTPUT:
516 RETVAL 595 RETVAL
517 596
597ev_fork *fork (SV *cb)
598 ALIAS:
599 fork_ns = 1
600 CODE:
601 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
602 ev_fork_set (RETVAL);
603 if (!ix) START (fork, RETVAL);
604 OUTPUT:
605 RETVAL
606
518ev_child *child (int pid, SV *cb) 607ev_child *child (int pid, int trace, SV *cb)
519 ALIAS: 608 ALIAS:
520 child_ns = 1 609 child_ns = 1
521 CODE: 610 CODE:
522 RETVAL = e_new (sizeof (ev_child), cb); 611 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
523 ev_child_set (RETVAL, pid); 612 ev_child_set (RETVAL, pid, trace);
524 if (!ix) START (child, RETVAL); 613 if (!ix) START (child, RETVAL);
525 OUTPUT: 614 OUTPUT:
526 RETVAL 615 RETVAL
527 616
528ev_stat *stat (SV *path, NV interval, SV *cb) 617ev_stat *stat (SV *path, NV interval, SV *cb)
529 ALIAS: 618 ALIAS:
530 stat_ns = 1 619 stat_ns = 1
531 CODE: 620 CODE:
532 RETVAL = e_new (sizeof (ev_stat), cb); 621 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
533 RETVAL->fh = newSVsv (path); 622 RETVAL->fh = newSVsv (path);
534 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 623 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
535 if (!ix) START (stat, RETVAL); 624 if (!ix) START (stat, RETVAL);
536 OUTPUT: 625 OUTPUT:
537 RETVAL 626 RETVAL
538 627
628ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef)
629 ALIAS:
630 embed_ns = 1
631 CODE:
632{
633 if (!(ev_backend (loop) & ev_embeddable_backends ()))
634 croak ("passed loop is not embeddable via EV::embed,");
635
636 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
637 RETVAL->fh = newSVsv (ST (0));
638 ev_embed_set (RETVAL, loop);
639
640 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
641
642 if (!ix) START (embed, RETVAL);
643}
644 OUTPUT:
645 RETVAL
646
539void once (SV *fh, int events, SV *timeout, SV *cb) 647void once (SV *fh, int events, SV *timeout, SV *cb)
540 CODE: 648 CODE:
541 ev_once ( 649 ev_once (
650 evapi.default_loop,
542 sv_fileno (fh), events, 651 sv_fileno (fh), events,
543 SvOK (timeout) ? SvNV (timeout) : -1., 652 SvOK (timeout) ? SvNV (timeout) : -1.,
544 e_once_cb, 653 e_once_cb,
545 newSVsv (cb) 654 newSVsv (cb)
546 ); 655 );
551 660
552int ev_is_active (ev_watcher *w) 661int ev_is_active (ev_watcher *w)
553 662
554int ev_is_pending (ev_watcher *w) 663int ev_is_pending (ev_watcher *w)
555 664
665void ev_invoke (ev_watcher *w, int revents = EV_NONE)
666 C_ARGS: e_loop (w), w, revents
667
668int ev_clear_pending (ev_watcher *w)
669 C_ARGS: e_loop (w), w
670
671void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
672 C_ARGS: e_loop (w), w, revents
673
556int keepalive (ev_watcher *w, int new_value = 0) 674int keepalive (ev_watcher *w, int new_value = 0)
557 CODE: 675 CODE:
558{ 676{
559 RETVAL = w->flags & WFLAG_KEEPALIVE; 677 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
560 new_value = new_value ? WFLAG_KEEPALIVE : 0; 678 new_value = new_value ? WFLAG_KEEPALIVE : 0;
561 679
562 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 680 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
563 { 681 {
564 REF (w); 682 REF (w);
565 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 683 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
566 UNREF (w); 684 UNREF (w);
567 } 685 }
568} 686}
569 OUTPUT: 687 OUTPUT:
570 RETVAL 688 RETVAL
592 } 710 }
593} 711}
594 OUTPUT: 712 OUTPUT:
595 RETVAL 713 RETVAL
596 714
597void trigger (ev_watcher *w, int revents = EV_NONE) 715SV *loop (ev_watcher *w)
598 CODE: 716 CODE:
599 w->cb (w, revents); 717 RETVAL = newRV_inc (w->loop);
718 OUTPUT:
719 RETVAL
600 720
601int priority (ev_watcher *w, int new_priority = 0) 721int priority (ev_watcher *w, int new_priority = 0)
602 CODE: 722 CODE:
603{ 723{
604 RETVAL = w->priority; 724 RETVAL = w->priority;
605 725
606 if (items > 1) 726 if (items > 1)
607 { 727 {
608 int active = ev_is_active (w); 728 int active = ev_is_active (w);
609
610 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
611 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
612 729
613 if (active) 730 if (active)
614 { 731 {
615 /* grrr. */ 732 /* grrr. */
616 PUSHMARK (SP); 733 PUSHMARK (SP);
617 XPUSHs (ST (0)); 734 XPUSHs (ST (0));
735 PUTBACK;
618 call_method ("stop", G_DISCARD | G_VOID); 736 call_method ("stop", G_DISCARD | G_VOID);
619 } 737 }
620 738
621 ev_set_priority (w, new_priority); 739 ev_set_priority (w, new_priority);
622 740
623 if (active) 741 if (active)
624 { 742 {
625 PUSHMARK (SP); 743 PUSHMARK (SP);
626 XPUSHs (ST (0)); 744 XPUSHs (ST (0));
745 PUTBACK;
627 call_method ("start", G_DISCARD | G_VOID); 746 call_method ("start", G_DISCARD | G_VOID);
628 } 747 }
629 } 748 }
630} 749}
631 OUTPUT: 750 OUTPUT:
741void ev_timer_again (ev_timer *w) 860void ev_timer_again (ev_timer *w)
742 INIT: 861 INIT:
743 CHECK_REPEAT (w->repeat); 862 CHECK_REPEAT (w->repeat);
744 CODE: 863 CODE:
745 REF (w); 864 REF (w);
746 ev_timer_again (w); 865 ev_timer_again (e_loop (w), w);
747 UNREF (w); 866 UNREF (w);
748 867
749void DESTROY (ev_timer *w) 868void DESTROY (ev_timer *w)
750 CODE: 869 CODE:
751 STOP (timer, w); 870 STOP (timer, w);
755 INIT: 874 INIT:
756 CHECK_REPEAT (repeat); 875 CHECK_REPEAT (repeat);
757 CODE: 876 CODE:
758 RESET (timer, w, (w, after, repeat)); 877 RESET (timer, w, (w, after, repeat));
759 878
879NV at (ev_timer *w)
880 CODE:
881 RETVAL = w->at;
882 OUTPUT:
883 RETVAL
884
760MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 885MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
761 886
762void ev_periodic_start (ev_periodic *w) 887void ev_periodic_start (ev_periodic *w)
763 INIT: 888 INIT:
764 CHECK_REPEAT (w->interval); 889 CHECK_REPEAT (w->interval);
770 STOP (periodic, w); 895 STOP (periodic, w);
771 896
772void ev_periodic_again (ev_periodic *w) 897void ev_periodic_again (ev_periodic *w)
773 CODE: 898 CODE:
774 REF (w); 899 REF (w);
775 ev_periodic_again (w); 900 ev_periodic_again (e_loop (w), w);
776 UNREF (w); 901 UNREF (w);
777 902
778void DESTROY (ev_periodic *w) 903void DESTROY (ev_periodic *w)
779 CODE: 904 CODE:
780 STOP (periodic, w); 905 STOP (periodic, w);
789 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 914 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
790 915
791 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 916 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
792} 917}
793 918
919NV at (ev_periodic *w)
920 CODE:
921 RETVAL = w->at;
922 OUTPUT:
923 RETVAL
924
794MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 925MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
795 926
796void ev_idle_start (ev_idle *w) 927void ev_idle_start (ev_idle *w)
797 CODE: 928 CODE:
798 START (idle, w); 929 START (idle, w);
804void DESTROY (ev_idle *w) 935void DESTROY (ev_idle *w)
805 CODE: 936 CODE:
806 STOP (idle, w); 937 STOP (idle, w);
807 e_destroy (w); 938 e_destroy (w);
808 939
809MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 940MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
810 941
811void ev_prepare_start (ev_prepare *w) 942void ev_prepare_start (ev_prepare *w)
812 CODE: 943 CODE:
813 START (prepare, w); 944 START (prepare, w);
814 945
834void DESTROY (ev_check *w) 965void DESTROY (ev_check *w)
835 CODE: 966 CODE:
836 STOP (check, w); 967 STOP (check, w);
837 e_destroy (w); 968 e_destroy (w);
838 969
970MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
971
972void ev_fork_start (ev_fork *w)
973 CODE:
974 START (fork, w);
975
976void ev_fork_stop (ev_fork *w)
977 CODE:
978 STOP (fork, w);
979
980void DESTROY (ev_fork *w)
981 CODE:
982 STOP (fork, w);
983 e_destroy (w);
984
839MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 985MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
840 986
841void ev_child_start (ev_child *w) 987void ev_child_start (ev_child *w)
842 CODE: 988 CODE:
843 START (child, w); 989 START (child, w);
849void DESTROY (ev_child *w) 995void DESTROY (ev_child *w)
850 CODE: 996 CODE:
851 STOP (child, w); 997 STOP (child, w);
852 e_destroy (w); 998 e_destroy (w);
853 999
854void set (ev_child *w, int pid) 1000void set (ev_child *w, int pid, int trace)
855 CODE: 1001 CODE:
856 RESET (child, w, (w, pid)); 1002 RESET (child, w, (w, pid, trace));
857 1003
858int pid (ev_child *w, int new_pid = 0)
859 CODE:
860{
861 RETVAL = w->pid;
862
863 if (items > 1)
864 RESET (child, w, (w, new_pid));
865}
866 OUTPUT:
867 RETVAL
868
869
870int rstatus (ev_child *w) 1004int pid (ev_child *w)
871 ALIAS: 1005 ALIAS:
872 rpid = 1 1006 rpid = 1
1007 rstatus = 2
873 CODE: 1008 CODE:
874 RETVAL = ix ? w->rpid : w->rstatus; 1009 RETVAL = ix == 0 ? w->pid
1010 : ix == 1 ? w->rpid
1011 : w->rstatus;
875 OUTPUT: 1012 OUTPUT:
876 RETVAL 1013 RETVAL
877 1014
878MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1015MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
879 1016
930 PPCODE: 1067 PPCODE:
931{ 1068{
932 ev_statdata *s = ix ? &w->attr : &w->prev; 1069 ev_statdata *s = ix ? &w->attr : &w->prev;
933 1070
934 if (ix == 1) 1071 if (ix == 1)
935 ev_stat_stat (w); 1072 ev_stat_stat (e_loop (w), w);
936 else if (!s->st_nlink) 1073 else if (!s->st_nlink)
937 errno = ENOENT; 1074 errno = ENOENT;
938 1075
939 PL_statcache.st_dev = s->st_nlink; 1076 PL_statcache.st_dev = s->st_nlink;
940 PL_statcache.st_ino = s->st_ino; 1077 PL_statcache.st_ino = s->st_ino;
967 PUSHs (sv_2mortal (newSVuv (4096))); 1104 PUSHs (sv_2mortal (newSVuv (4096)));
968 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 1105 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
969 } 1106 }
970} 1107}
971 1108
1109MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1110
1111void ev_embed_start (ev_embed *w)
1112 CODE:
1113 START (embed, w);
1114
1115void ev_embed_stop (ev_embed *w)
1116 CODE:
1117 STOP (embed, w);
1118
1119void DESTROY (ev_embed *w)
1120 CODE:
1121 STOP (embed, w);
1122 e_destroy (w);
1123
1124void set (ev_embed *w, struct ev_loop *loop)
1125 CODE:
1126{
1127 sv_setsv (w->fh, ST (1));
1128 RESET (embed, w, (w, loop));
1129}
1130
1131SV *other (ev_embed *w)
1132 CODE:
1133 RETVAL = newSVsv (w->fh);
1134 OUTPUT:
1135 RETVAL
1136
1137MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1138
1139SV *new (SV *klass, unsigned int flags = 0)
1140 CODE:
1141{
1142 struct ev_loop *loop = ev_loop_new (flags);
1143
1144 if (!loop)
1145 XSRETURN_UNDEF;
1146
1147 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1148}
1149 OUTPUT:
1150 RETVAL
1151
1152void DESTROY (struct ev_loop *loop)
1153 CODE:
1154 if (loop != evapi.default_loop) /* global destruction sucks */
1155 ev_loop_destroy (loop);
1156
1157void ev_loop_fork (struct ev_loop *loop)
1158
1159NV ev_now (struct ev_loop *loop)
1160
1161void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1162
1163void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1164
1165unsigned int ev_backend (struct ev_loop *loop)
1166
1167unsigned int ev_loop_count (struct ev_loop *loop)
1168
1169void ev_loop (struct ev_loop *loop, int flags = 0)
1170
1171void ev_unloop (struct ev_loop *loop, int how = 1)
1172
1173void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1174
972#if 0 1175#if 0
973 1176
974MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1177void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
975 1178 CODE:
976BOOT:
977{ 1179{
978 HV *stash = gv_stashpv ("EV::HTTP", 1); 1180 Signal signum = sv_signum (signal);
1181 CHECK_SIG (signal, signum);
979 1182
980 static const struct { 1183 ev_feed_signal_event (loop, signum);
981 const char *name;
982 IV iv;
983 } *civ, const_iv[] = {
984# define const_iv(pfx, name) { # name, (IV) pfx ## name },
985 const_iv (HTTP_, OK)
986 const_iv (HTTP_, NOCONTENT)
987 const_iv (HTTP_, MOVEPERM)
988 const_iv (HTTP_, MOVETEMP)
989 const_iv (HTTP_, NOTMODIFIED)
990 const_iv (HTTP_, BADREQUEST)
991 const_iv (HTTP_, NOTFOUND)
992 const_iv (HTTP_, SERVUNAVAIL)
993 const_iv (EVHTTP_, REQ_OWN_CONNECTION)
994 const_iv (EVHTTP_, PROXY_REQUEST)
995 const_iv (EVHTTP_, REQ_GET)
996 const_iv (EVHTTP_, REQ_POST)
997 const_iv (EVHTTP_, REQ_HEAD)
998 const_iv (EVHTTP_, REQUEST)
999 const_iv (EVHTTP_, RESPONSE)
1000 };
1001
1002 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1003 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1004} 1184}
1005
1006MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
1007
1008#HttpRequest new (SV *klass, SV *cb)
1009
1010#void DESTROY (struct evhttp_request *req);
1011 1185
1012#endif 1186#endif
1013 1187
1188ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1189 ALIAS:
1190 io_ns = 1
1191 CODE:
1192{
1193 int fd = sv_fileno (fh);
1194 CHECK_FD (fh, fd);
1014 1195
1196 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1197 RETVAL->fh = newSVsv (fh);
1198 ev_io_set (RETVAL, fd, events);
1199 if (!ix) START (io, RETVAL);
1200}
1201 OUTPUT:
1202 RETVAL
1015 1203
1204ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1205 ALIAS:
1206 timer_ns = 1
1207 INIT:
1208 CHECK_REPEAT (repeat);
1209 CODE:
1210 RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1211 ev_timer_set (RETVAL, after, repeat);
1212 if (!ix) START (timer, RETVAL);
1213 OUTPUT:
1214 RETVAL
1016 1215
1216SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1217 ALIAS:
1218 periodic_ns = 1
1219 INIT:
1220 CHECK_REPEAT (interval);
1221 CODE:
1222{
1223 ev_periodic *w;
1224 w = e_new (sizeof (ev_periodic), cb, ST (0));
1225 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1226 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
1227 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1228 if (!ix) START (periodic, w);
1229}
1230 OUTPUT:
1231 RETVAL
1017 1232
1233#if 0
1018 1234
1235ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1236 ALIAS:
1237 signal_ns = 1
1238 CODE:
1239{
1240 Signal signum = sv_signum (signal);
1241 CHECK_SIG (signal, signum);
1019 1242
1243 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1244 ev_signal_set (RETVAL, signum);
1245 if (!ix) START (signal, RETVAL);
1246}
1247 OUTPUT:
1248 RETVAL
1020 1249
1250#endif
1251
1252ev_idle *idle (struct ev_loop *loop, SV *cb)
1253 ALIAS:
1254 idle_ns = 1
1255 CODE:
1256 RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1257 ev_idle_set (RETVAL);
1258 if (!ix) START (idle, RETVAL);
1259 OUTPUT:
1260 RETVAL
1261
1262ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1263 ALIAS:
1264 prepare_ns = 1
1265 CODE:
1266 RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1267 ev_prepare_set (RETVAL);
1268 if (!ix) START (prepare, RETVAL);
1269 OUTPUT:
1270 RETVAL
1271
1272ev_check *check (struct ev_loop *loop, SV *cb)
1273 ALIAS:
1274 check_ns = 1
1275 CODE:
1276 RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1277 ev_check_set (RETVAL);
1278 if (!ix) START (check, RETVAL);
1279 OUTPUT:
1280 RETVAL
1281
1282ev_fork *fork (struct ev_loop *loop, SV *cb)
1283 ALIAS:
1284 fork_ns = 1
1285 CODE:
1286 RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1287 ev_fork_set (RETVAL);
1288 if (!ix) START (fork, RETVAL);
1289 OUTPUT:
1290 RETVAL
1291
1292ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1293 ALIAS:
1294 child_ns = 1
1295 CODE:
1296 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1297 ev_child_set (RETVAL, pid, trace);
1298 if (!ix) START (child, RETVAL);
1299 OUTPUT:
1300 RETVAL
1301
1302ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1303 ALIAS:
1304 stat_ns = 1
1305 CODE:
1306 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1307 RETVAL->fh = newSVsv (path);
1308 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1309 if (!ix) START (stat, RETVAL);
1310 OUTPUT:
1311 RETVAL
1312
1313ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef)
1314 ALIAS:
1315 embed_ns = 1
1316 CODE:
1317{
1318 if (!(ev_backend (other) & ev_embeddable_backends ()))
1319 croak ("passed loop is not embeddable via EV::embed,");
1320
1321 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1322 RETVAL->fh = newSVsv (ST (1));
1323 ev_embed_set (RETVAL, other);
1324
1325 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1326
1327 if (!ix) START (embed, RETVAL);
1328}
1329 OUTPUT:
1330 RETVAL
1331
1332void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1333 CODE:
1334 ev_once (
1335 loop,
1336 sv_fileno (fh), events,
1337 SvOK (timeout) ? SvNV (timeout) : -1.,
1338 e_once_cb,
1339 newSVsv (cb)
1340 );
1341

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines