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.105 by root, Thu Jan 31 20:10:28 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.async_start = ev_async_start;
432 evapi.async_stop = ev_async_stop;
433 evapi.async_send = ev_async_send;
434 evapi.clear_pending = ev_clear_pending;
435 evapi.invoke = ev_invoke;
407 436
408 sv_setiv (sv, (IV)&evapi); 437 sv_setiv (sv, (IV)&evapi);
409 SvREADONLY_on (sv); 438 SvREADONLY_on (sv);
410 } 439 }
411#ifndef _WIN32 440#ifndef _WIN32
412 pthread_atfork (0, 0, ev_default_fork); 441 pthread_atfork (0, 0, ev_default_fork);
413#endif 442#endif
414} 443}
415 444
445SV *ev_default_loop (unsigned int flags = 0)
446 CODE:
447{
448 if (!default_loop_sv)
449 {
450 evapi.default_loop = ev_default_loop (flags);
451
452 if (!evapi.default_loop)
453 XSRETURN_UNDEF;
454
455 default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
456 }
457
458 RETVAL = newSVsv (default_loop_sv);
459}
460 OUTPUT:
461 RETVAL
462
463void ev_default_destroy ()
464 CODE:
465 ev_default_destroy ();
466 SvREFCNT_dec (default_loop_sv);
467 default_loop_sv = 0;
468
469unsigned int ev_supported_backends ()
470
471unsigned int ev_recommended_backends ()
472
473unsigned int ev_embeddable_backends ()
474
475NV ev_time ()
476
416NV ev_now () 477NV ev_now ()
478 C_ARGS: evapi.default_loop
417 479
418unsigned int ev_backend () 480unsigned int ev_backend ()
481 C_ARGS: evapi.default_loop
419 482
420NV ev_time () 483unsigned int ev_loop_count ()
484 C_ARGS: evapi.default_loop
421 485
422unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) 486void ev_set_io_collect_interval (NV interval)
487 C_ARGS: evapi.default_loop, interval
488
489void ev_set_timeout_collect_interval (NV interval)
490 C_ARGS: evapi.default_loop, interval
423 491
424void ev_loop (int flags = 0) 492void ev_loop (int flags = 0)
493 C_ARGS: evapi.default_loop, flags
425 494
426void ev_unloop (int how = 1) 495void ev_unloop (int how = EVUNLOOP_ONE)
496 C_ARGS: evapi.default_loop, how
497
498void ev_feed_fd_event (int fd, int revents = EV_NONE)
499 C_ARGS: evapi.default_loop, fd, revents
500
501void ev_feed_signal_event (SV *signal)
502 CODE:
503{
504 Signal signum = sv_signum (signal);
505 CHECK_SIG (signal, signum);
506
507 ev_feed_signal_event (evapi.default_loop, signum);
508}
427 509
428ev_io *io (SV *fh, int events, SV *cb) 510ev_io *io (SV *fh, int events, SV *cb)
429 ALIAS: 511 ALIAS:
430 io_ns = 1 512 io_ns = 1
431 CODE: 513 CODE:
432{ 514{
433 int fd = sv_fileno (fh); 515 int fd = sv_fileno (fh);
434 CHECK_FD (fh, fd); 516 CHECK_FD (fh, fd);
435 517
436 RETVAL = e_new (sizeof (ev_io), cb); 518 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
437 RETVAL->fh = newSVsv (fh); 519 RETVAL->fh = newSVsv (fh);
438 ev_io_set (RETVAL, fd, events); 520 ev_io_set (RETVAL, fd, events);
439 if (!ix) START (io, RETVAL); 521 if (!ix) START (io, RETVAL);
440} 522}
441 OUTPUT: 523 OUTPUT:
445 ALIAS: 527 ALIAS:
446 timer_ns = 1 528 timer_ns = 1
447 INIT: 529 INIT:
448 CHECK_REPEAT (repeat); 530 CHECK_REPEAT (repeat);
449 CODE: 531 CODE:
450 RETVAL = e_new (sizeof (ev_timer), cb); 532 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
451 ev_timer_set (RETVAL, after, repeat); 533 ev_timer_set (RETVAL, after, repeat);
452 if (!ix) START (timer, RETVAL); 534 if (!ix) START (timer, RETVAL);
453 OUTPUT: 535 OUTPUT:
454 RETVAL 536 RETVAL
455 537
459 INIT: 541 INIT:
460 CHECK_REPEAT (interval); 542 CHECK_REPEAT (interval);
461 CODE: 543 CODE:
462{ 544{
463 ev_periodic *w; 545 ev_periodic *w;
464 w = e_new (sizeof (ev_periodic), cb); 546 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
465 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 547 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
466 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 548 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
467 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 549 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
468 if (!ix) START (periodic, w); 550 if (!ix) START (periodic, w);
469} 551}
476 CODE: 558 CODE:
477{ 559{
478 Signal signum = sv_signum (signal); 560 Signal signum = sv_signum (signal);
479 CHECK_SIG (signal, signum); 561 CHECK_SIG (signal, signum);
480 562
481 RETVAL = e_new (sizeof (ev_signal), cb); 563 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
482 ev_signal_set (RETVAL, signum); 564 ev_signal_set (RETVAL, signum);
483 if (!ix) START (signal, RETVAL); 565 if (!ix) START (signal, RETVAL);
484} 566}
485 OUTPUT: 567 OUTPUT:
486 RETVAL 568 RETVAL
487 569
488ev_idle *idle (SV *cb) 570ev_idle *idle (SV *cb)
489 ALIAS: 571 ALIAS:
490 idle_ns = 1 572 idle_ns = 1
491 CODE: 573 CODE:
492 RETVAL = e_new (sizeof (ev_idle), cb); 574 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
493 ev_idle_set (RETVAL); 575 ev_idle_set (RETVAL);
494 if (!ix) START (idle, RETVAL); 576 if (!ix) START (idle, RETVAL);
495 OUTPUT: 577 OUTPUT:
496 RETVAL 578 RETVAL
497 579
498ev_prepare *prepare (SV *cb) 580ev_prepare *prepare (SV *cb)
499 ALIAS: 581 ALIAS:
500 prepare_ns = 1 582 prepare_ns = 1
501 CODE: 583 CODE:
502 RETVAL = e_new (sizeof (ev_prepare), cb); 584 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
503 ev_prepare_set (RETVAL); 585 ev_prepare_set (RETVAL);
504 if (!ix) START (prepare, RETVAL); 586 if (!ix) START (prepare, RETVAL);
505 OUTPUT: 587 OUTPUT:
506 RETVAL 588 RETVAL
507 589
508ev_check *check (SV *cb) 590ev_check *check (SV *cb)
509 ALIAS: 591 ALIAS:
510 check_ns = 1 592 check_ns = 1
511 CODE: 593 CODE:
512 RETVAL = e_new (sizeof (ev_check), cb); 594 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
513 ev_check_set (RETVAL); 595 ev_check_set (RETVAL);
514 if (!ix) START (check, RETVAL); 596 if (!ix) START (check, RETVAL);
515 OUTPUT: 597 OUTPUT:
516 RETVAL 598 RETVAL
517 599
600ev_fork *fork (SV *cb)
601 ALIAS:
602 fork_ns = 1
603 CODE:
604 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
605 ev_fork_set (RETVAL);
606 if (!ix) START (fork, RETVAL);
607 OUTPUT:
608 RETVAL
609
518ev_child *child (int pid, SV *cb) 610ev_child *child (int pid, int trace, SV *cb)
519 ALIAS: 611 ALIAS:
520 child_ns = 1 612 child_ns = 1
521 CODE: 613 CODE:
522 RETVAL = e_new (sizeof (ev_child), cb); 614 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
523 ev_child_set (RETVAL, pid); 615 ev_child_set (RETVAL, pid, trace);
524 if (!ix) START (child, RETVAL); 616 if (!ix) START (child, RETVAL);
525 OUTPUT: 617 OUTPUT:
526 RETVAL 618 RETVAL
527 619
528ev_stat *stat (SV *path, NV interval, SV *cb) 620ev_stat *stat (SV *path, NV interval, SV *cb)
529 ALIAS: 621 ALIAS:
530 stat_ns = 1 622 stat_ns = 1
531 CODE: 623 CODE:
532 RETVAL = e_new (sizeof (ev_stat), cb); 624 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
533 RETVAL->fh = newSVsv (path); 625 RETVAL->fh = newSVsv (path);
534 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 626 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
535 if (!ix) START (stat, RETVAL); 627 if (!ix) START (stat, RETVAL);
536 OUTPUT: 628 OUTPUT:
537 RETVAL 629 RETVAL
538 630
631ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef)
632 ALIAS:
633 embed_ns = 1
634 CODE:
635{
636 if (!(ev_backend (loop) & ev_embeddable_backends ()))
637 croak ("passed loop is not embeddable via EV::embed,");
638
639 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
640 RETVAL->fh = newSVsv (ST (0));
641 ev_embed_set (RETVAL, loop);
642
643 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
644
645 if (!ix) START (embed, RETVAL);
646}
647 OUTPUT:
648 RETVAL
649
539void once (SV *fh, int events, SV *timeout, SV *cb) 650void once (SV *fh, int events, SV *timeout, SV *cb)
540 CODE: 651 CODE:
541 ev_once ( 652 ev_once (
653 evapi.default_loop,
542 sv_fileno (fh), events, 654 sv_fileno (fh), events,
543 SvOK (timeout) ? SvNV (timeout) : -1., 655 SvOK (timeout) ? SvNV (timeout) : -1.,
544 e_once_cb, 656 e_once_cb,
545 newSVsv (cb) 657 newSVsv (cb)
546 ); 658 );
551 663
552int ev_is_active (ev_watcher *w) 664int ev_is_active (ev_watcher *w)
553 665
554int ev_is_pending (ev_watcher *w) 666int ev_is_pending (ev_watcher *w)
555 667
668void ev_invoke (ev_watcher *w, int revents = EV_NONE)
669 C_ARGS: e_loop (w), w, revents
670
671int ev_clear_pending (ev_watcher *w)
672 C_ARGS: e_loop (w), w
673
674void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
675 C_ARGS: e_loop (w), w, revents
676
556int keepalive (ev_watcher *w, int new_value = 0) 677int keepalive (ev_watcher *w, int new_value = 0)
557 CODE: 678 CODE:
558{ 679{
559 RETVAL = w->flags & WFLAG_KEEPALIVE; 680 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
560 new_value = new_value ? WFLAG_KEEPALIVE : 0; 681 new_value = new_value ? WFLAG_KEEPALIVE : 0;
561 682
562 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 683 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
563 { 684 {
564 REF (w); 685 REF (w);
565 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 686 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
566 UNREF (w); 687 UNREF (w);
567 } 688 }
568} 689}
569 OUTPUT: 690 OUTPUT:
570 RETVAL 691 RETVAL
592 } 713 }
593} 714}
594 OUTPUT: 715 OUTPUT:
595 RETVAL 716 RETVAL
596 717
597void trigger (ev_watcher *w, int revents = EV_NONE) 718SV *loop (ev_watcher *w)
598 CODE: 719 CODE:
599 w->cb (w, revents); 720 RETVAL = newRV_inc (w->loop);
721 OUTPUT:
722 RETVAL
600 723
601int priority (ev_watcher *w, int new_priority = 0) 724int priority (ev_watcher *w, int new_priority = 0)
602 CODE: 725 CODE:
603{ 726{
604 RETVAL = w->priority; 727 RETVAL = w->priority;
605 728
606 if (items > 1) 729 if (items > 1)
607 { 730 {
608 int active = ev_is_active (w); 731 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 732
613 if (active) 733 if (active)
614 { 734 {
615 /* grrr. */ 735 /* grrr. */
616 PUSHMARK (SP); 736 PUSHMARK (SP);
617 XPUSHs (ST (0)); 737 XPUSHs (ST (0));
738 PUTBACK;
618 call_method ("stop", G_DISCARD | G_VOID); 739 call_method ("stop", G_DISCARD | G_VOID);
619 } 740 }
620 741
621 ev_set_priority (w, new_priority); 742 ev_set_priority (w, new_priority);
622 743
623 if (active) 744 if (active)
624 { 745 {
625 PUSHMARK (SP); 746 PUSHMARK (SP);
626 XPUSHs (ST (0)); 747 XPUSHs (ST (0));
748 PUTBACK;
627 call_method ("start", G_DISCARD | G_VOID); 749 call_method ("start", G_DISCARD | G_VOID);
628 } 750 }
629 } 751 }
630} 752}
631 OUTPUT: 753 OUTPUT:
741void ev_timer_again (ev_timer *w) 863void ev_timer_again (ev_timer *w)
742 INIT: 864 INIT:
743 CHECK_REPEAT (w->repeat); 865 CHECK_REPEAT (w->repeat);
744 CODE: 866 CODE:
745 REF (w); 867 REF (w);
746 ev_timer_again (w); 868 ev_timer_again (e_loop (w), w);
747 UNREF (w); 869 UNREF (w);
748 870
749void DESTROY (ev_timer *w) 871void DESTROY (ev_timer *w)
750 CODE: 872 CODE:
751 STOP (timer, w); 873 STOP (timer, w);
755 INIT: 877 INIT:
756 CHECK_REPEAT (repeat); 878 CHECK_REPEAT (repeat);
757 CODE: 879 CODE:
758 RESET (timer, w, (w, after, repeat)); 880 RESET (timer, w, (w, after, repeat));
759 881
882NV at (ev_timer *w)
883 CODE:
884 RETVAL = w->at;
885 OUTPUT:
886 RETVAL
887
760MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 888MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
761 889
762void ev_periodic_start (ev_periodic *w) 890void ev_periodic_start (ev_periodic *w)
763 INIT: 891 INIT:
764 CHECK_REPEAT (w->interval); 892 CHECK_REPEAT (w->interval);
770 STOP (periodic, w); 898 STOP (periodic, w);
771 899
772void ev_periodic_again (ev_periodic *w) 900void ev_periodic_again (ev_periodic *w)
773 CODE: 901 CODE:
774 REF (w); 902 REF (w);
775 ev_periodic_again (w); 903 ev_periodic_again (e_loop (w), w);
776 UNREF (w); 904 UNREF (w);
777 905
778void DESTROY (ev_periodic *w) 906void DESTROY (ev_periodic *w)
779 CODE: 907 CODE:
780 STOP (periodic, w); 908 STOP (periodic, w);
789 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 917 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
790 918
791 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 919 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
792} 920}
793 921
922NV at (ev_periodic *w)
923 CODE:
924 RETVAL = w->at;
925 OUTPUT:
926 RETVAL
927
794MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 928MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
795 929
796void ev_idle_start (ev_idle *w) 930void ev_idle_start (ev_idle *w)
797 CODE: 931 CODE:
798 START (idle, w); 932 START (idle, w);
804void DESTROY (ev_idle *w) 938void DESTROY (ev_idle *w)
805 CODE: 939 CODE:
806 STOP (idle, w); 940 STOP (idle, w);
807 e_destroy (w); 941 e_destroy (w);
808 942
809MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 943MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
810 944
811void ev_prepare_start (ev_prepare *w) 945void ev_prepare_start (ev_prepare *w)
812 CODE: 946 CODE:
813 START (prepare, w); 947 START (prepare, w);
814 948
834void DESTROY (ev_check *w) 968void DESTROY (ev_check *w)
835 CODE: 969 CODE:
836 STOP (check, w); 970 STOP (check, w);
837 e_destroy (w); 971 e_destroy (w);
838 972
973MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
974
975void ev_fork_start (ev_fork *w)
976 CODE:
977 START (fork, w);
978
979void ev_fork_stop (ev_fork *w)
980 CODE:
981 STOP (fork, w);
982
983void DESTROY (ev_fork *w)
984 CODE:
985 STOP (fork, w);
986 e_destroy (w);
987
839MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 988MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
840 989
841void ev_child_start (ev_child *w) 990void ev_child_start (ev_child *w)
842 CODE: 991 CODE:
843 START (child, w); 992 START (child, w);
849void DESTROY (ev_child *w) 998void DESTROY (ev_child *w)
850 CODE: 999 CODE:
851 STOP (child, w); 1000 STOP (child, w);
852 e_destroy (w); 1001 e_destroy (w);
853 1002
854void set (ev_child *w, int pid) 1003void set (ev_child *w, int pid, int trace)
855 CODE: 1004 CODE:
856 RESET (child, w, (w, pid)); 1005 RESET (child, w, (w, pid, trace));
857 1006
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) 1007int pid (ev_child *w)
871 ALIAS: 1008 ALIAS:
872 rpid = 1 1009 rpid = 1
1010 rstatus = 2
873 CODE: 1011 CODE:
874 RETVAL = ix ? w->rpid : w->rstatus; 1012 RETVAL = ix == 0 ? w->pid
1013 : ix == 1 ? w->rpid
1014 : w->rstatus;
875 OUTPUT: 1015 OUTPUT:
876 RETVAL 1016 RETVAL
877 1017
878MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1018MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
879 1019
930 PPCODE: 1070 PPCODE:
931{ 1071{
932 ev_statdata *s = ix ? &w->attr : &w->prev; 1072 ev_statdata *s = ix ? &w->attr : &w->prev;
933 1073
934 if (ix == 1) 1074 if (ix == 1)
935 ev_stat_stat (w); 1075 ev_stat_stat (e_loop (w), w);
936 else if (!s->st_nlink) 1076 else if (!s->st_nlink)
937 errno = ENOENT; 1077 errno = ENOENT;
938 1078
939 PL_statcache.st_dev = s->st_nlink; 1079 PL_statcache.st_dev = s->st_nlink;
940 PL_statcache.st_ino = s->st_ino; 1080 PL_statcache.st_ino = s->st_ino;
967 PUSHs (sv_2mortal (newSVuv (4096))); 1107 PUSHs (sv_2mortal (newSVuv (4096)));
968 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 1108 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
969 } 1109 }
970} 1110}
971 1111
1112MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1113
1114void ev_embed_start (ev_embed *w)
1115 CODE:
1116 START (embed, w);
1117
1118void ev_embed_stop (ev_embed *w)
1119 CODE:
1120 STOP (embed, w);
1121
1122void DESTROY (ev_embed *w)
1123 CODE:
1124 STOP (embed, w);
1125 e_destroy (w);
1126
1127void set (ev_embed *w, struct ev_loop *loop)
1128 CODE:
1129{
1130 sv_setsv (w->fh, ST (1));
1131 RESET (embed, w, (w, loop));
1132}
1133
1134SV *other (ev_embed *w)
1135 CODE:
1136 RETVAL = newSVsv (w->fh);
1137 OUTPUT:
1138 RETVAL
1139
1140MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1141
1142SV *new (SV *klass, unsigned int flags = 0)
1143 CODE:
1144{
1145 struct ev_loop *loop = ev_loop_new (flags);
1146
1147 if (!loop)
1148 XSRETURN_UNDEF;
1149
1150 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1151}
1152 OUTPUT:
1153 RETVAL
1154
1155void DESTROY (struct ev_loop *loop)
1156 CODE:
1157 if (loop != evapi.default_loop) /* global destruction sucks */
1158 ev_loop_destroy (loop);
1159
1160void ev_loop_fork (struct ev_loop *loop)
1161
1162NV ev_now (struct ev_loop *loop)
1163
1164void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1165
1166void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1167
1168unsigned int ev_backend (struct ev_loop *loop)
1169
1170unsigned int ev_loop_count (struct ev_loop *loop)
1171
1172void ev_loop (struct ev_loop *loop, int flags = 0)
1173
1174void ev_unloop (struct ev_loop *loop, int how = 1)
1175
1176void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1177
972#if 0 1178#if 0
973 1179
974MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1180void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
975 1181 CODE:
976BOOT:
977{ 1182{
978 HV *stash = gv_stashpv ("EV::HTTP", 1); 1183 Signal signum = sv_signum (signal);
1184 CHECK_SIG (signal, signum);
979 1185
980 static const struct { 1186 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} 1187}
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 1188
1012#endif 1189#endif
1013 1190
1191ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1192 ALIAS:
1193 io_ns = 1
1194 CODE:
1195{
1196 int fd = sv_fileno (fh);
1197 CHECK_FD (fh, fd);
1014 1198
1199 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1200 RETVAL->fh = newSVsv (fh);
1201 ev_io_set (RETVAL, fd, events);
1202 if (!ix) START (io, RETVAL);
1203}
1204 OUTPUT:
1205 RETVAL
1015 1206
1207ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1208 ALIAS:
1209 timer_ns = 1
1210 INIT:
1211 CHECK_REPEAT (repeat);
1212 CODE:
1213 RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1214 ev_timer_set (RETVAL, after, repeat);
1215 if (!ix) START (timer, RETVAL);
1216 OUTPUT:
1217 RETVAL
1016 1218
1219SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1220 ALIAS:
1221 periodic_ns = 1
1222 INIT:
1223 CHECK_REPEAT (interval);
1224 CODE:
1225{
1226 ev_periodic *w;
1227 w = e_new (sizeof (ev_periodic), cb, ST (0));
1228 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1229 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
1230 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1231 if (!ix) START (periodic, w);
1232}
1233 OUTPUT:
1234 RETVAL
1017 1235
1236#if 0
1018 1237
1238ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1239 ALIAS:
1240 signal_ns = 1
1241 CODE:
1242{
1243 Signal signum = sv_signum (signal);
1244 CHECK_SIG (signal, signum);
1019 1245
1246 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1247 ev_signal_set (RETVAL, signum);
1248 if (!ix) START (signal, RETVAL);
1249}
1250 OUTPUT:
1251 RETVAL
1020 1252
1253#endif
1254
1255ev_idle *idle (struct ev_loop *loop, SV *cb)
1256 ALIAS:
1257 idle_ns = 1
1258 CODE:
1259 RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1260 ev_idle_set (RETVAL);
1261 if (!ix) START (idle, RETVAL);
1262 OUTPUT:
1263 RETVAL
1264
1265ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1266 ALIAS:
1267 prepare_ns = 1
1268 CODE:
1269 RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1270 ev_prepare_set (RETVAL);
1271 if (!ix) START (prepare, RETVAL);
1272 OUTPUT:
1273 RETVAL
1274
1275ev_check *check (struct ev_loop *loop, SV *cb)
1276 ALIAS:
1277 check_ns = 1
1278 CODE:
1279 RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1280 ev_check_set (RETVAL);
1281 if (!ix) START (check, RETVAL);
1282 OUTPUT:
1283 RETVAL
1284
1285ev_fork *fork (struct ev_loop *loop, SV *cb)
1286 ALIAS:
1287 fork_ns = 1
1288 CODE:
1289 RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1290 ev_fork_set (RETVAL);
1291 if (!ix) START (fork, RETVAL);
1292 OUTPUT:
1293 RETVAL
1294
1295ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1296 ALIAS:
1297 child_ns = 1
1298 CODE:
1299 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1300 ev_child_set (RETVAL, pid, trace);
1301 if (!ix) START (child, RETVAL);
1302 OUTPUT:
1303 RETVAL
1304
1305ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1306 ALIAS:
1307 stat_ns = 1
1308 CODE:
1309 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1310 RETVAL->fh = newSVsv (path);
1311 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1312 if (!ix) START (stat, RETVAL);
1313 OUTPUT:
1314 RETVAL
1315
1316ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef)
1317 ALIAS:
1318 embed_ns = 1
1319 CODE:
1320{
1321 if (!(ev_backend (other) & ev_embeddable_backends ()))
1322 croak ("passed loop is not embeddable via EV::embed,");
1323
1324 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1325 RETVAL->fh = newSVsv (ST (1));
1326 ev_embed_set (RETVAL, other);
1327
1328 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1329
1330 if (!ix) START (embed, RETVAL);
1331}
1332 OUTPUT:
1333 RETVAL
1334
1335void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1336 CODE:
1337 ev_once (
1338 loop,
1339 sv_fileno (fh), events,
1340 SvOK (timeout) ? SvNV (timeout) : -1.,
1341 e_once_cb,
1342 newSVsv (cb)
1343 );
1344

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines