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

Comparing EV/EV.xs (file contents):
Revision 1.138 by root, Wed Apr 14 00:17:22 2010 UTC vs.
Revision 1.165 by root, Fri Apr 5 21:04:30 2013 UTC

13sv_fileno (SV *fh) 13sv_fileno (SV *fh)
14{ 14{
15 return s_fileno (fh, 0); 15 return s_fileno (fh, 0);
16} 16}
17 17
18#ifndef GvCV_set
19# define GvCV_set(gv,cv) GvCV (gv) = cv
20#endif
21
18#define EV_STANDALONE 1 22#define EV_STANDALONE 1
19#define EV_PROTOTYPES 1 23#define EV_PROTOTYPES 1
20#define EV_USE_NANOSLEEP EV_USE_MONOTONIC 24#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
25#define EV_USE_FLOOR 1
26#define EV_API_STATIC
21#define EV_H <ev.h> 27#define EV_H <ev.h>
22#define EV_CONFIG_H error 28#define EV_CONFIG_H error
23#include "EV/EVAPI.h" 29#include "EV/EVAPI.h"
24 30
25#define EV_SELECT_IS_WINSOCKET 0 31#define EV_SELECT_IS_WINSOCKET 0
29# define fd_mask Perl_fd_mask 35# define fd_mask Perl_fd_mask
30#endif 36#endif
31/* due to bugs in OS X we have to use libev/ explicitly here */ 37/* due to bugs in OS X we have to use libev/ explicitly here */
32#include "libev/ev.c" 38#include "libev/ev.c"
33 39
34#ifndef _WIN32 40#if !defined _WIN32 && !defined _MINIX
35# include <pthread.h> 41# include <pthread.h>
36#endif 42#endif
37 43
38#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) 44#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop))
39#define e_flags(w) ((ev_watcher *)(w))->e_flags 45#define e_flags(w) ((ev_watcher *)(w))->e_flags
41#define e_fh(w) ((ev_watcher *)(w))->fh 47#define e_fh(w) ((ev_watcher *)(w))->fh
42#define e_data(w) ((ev_watcher *)(w))->data 48#define e_data(w) ((ev_watcher *)(w))->data
43 49
44#define WFLAG_KEEPALIVE 1 50#define WFLAG_KEEPALIVE 1
45#define WFLAG_UNREFED 2 /* has been unref'ed */ 51#define WFLAG_UNREFED 2 /* has been unref'ed */
52#define WFLAG_NOARGS 4 /* do not pass anything to the callback */
46 53
47#define UNREF(w) \ 54#define UNREF(w) \
48 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ 55 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
49 && ev_is_active (w)) \ 56 && ev_is_active (w)) \
50 { \ 57 { \
120 *stash_idle, 127 *stash_idle,
121 *stash_prepare, 128 *stash_prepare,
122 *stash_check, 129 *stash_check,
123 *stash_embed, 130 *stash_embed,
124 *stash_fork, 131 *stash_fork,
132 *stash_cleanup,
125 *stash_async; 133 *stash_async;
126 134
127///////////////////////////////////////////////////////////////////////////// 135/////////////////////////////////////////////////////////////////////////////
128// Event 136// Event
129 137
130static void e_cb (EV_P_ ev_watcher *w, int revents); 138static void e_cb (EV_P_ ev_watcher *w, int revents);
131 139
132void * 140static void *
133e_new (int size, SV *cb_sv, SV *loop) 141e_new (int size, SV *cb_sv, SV *loop)
134{ 142{
135 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0; 143 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0;
136 ev_watcher *w; 144 ev_watcher *w;
137 SV *self = NEWSV (0, size); 145 SV *self = NEWSV (0, size);
192 /* libev might have stopped the watcher */ 200 /* libev might have stopped the watcher */
193 if (expect_false (w->e_flags & WFLAG_UNREFED) 201 if (expect_false (w->e_flags & WFLAG_UNREFED)
194 && !ev_is_active (w)) 202 && !ev_is_active (w))
195 REF (w); 203 REF (w);
196 204
197 if (expect_true (sv_self_cache)) 205 PUSHMARK (SP);
206
207 if (!expect_true (e_flags (w) & WFLAG_NOARGS))
198 { 208 {
209 if (expect_true (sv_self_cache))
210 {
199 sv_self = sv_self_cache; sv_self_cache = 0; 211 sv_self = sv_self_cache; sv_self_cache = 0;
200 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); 212 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
213 }
214 else
215 {
216 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */
217 SvREADONLY_on (sv_self);
218 }
219
220 if (expect_true (sv_events_cache))
221 {
222 sv_events = sv_events_cache; sv_events_cache = 0;
223 SvIV_set (sv_events, revents);
224 SvIOK_only (sv_events);
225 }
226 else
227 {
228 sv_events = newSViv (revents);
229 SvREADONLY_on (sv_events);
230 }
231
232 EXTEND (SP, 2);
233 PUSHs (sv_self);
234 PUSHs (sv_events);
235
236 PUTBACK;
237 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
238
239 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
240 SvREFCNT_dec (sv_self);
241 else
242 {
243 SvREFCNT_dec (SvRV (sv_self));
244 SvRV_set (sv_self, &PL_sv_undef);
245 sv_self_cache = sv_self;
246 }
247
248 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
249 SvREFCNT_dec (sv_events);
250 else
251 sv_events_cache = sv_events;
201 } 252 }
202 else 253 else
203 { 254 {
204 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ 255 PUTBACK;
205 SvREADONLY_on (sv_self); 256 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
206 } 257 }
207
208 if (expect_true (sv_events_cache))
209 {
210 sv_events = sv_events_cache; sv_events_cache = 0;
211 SvIV_set (sv_events, revents);
212 }
213 else
214 {
215 sv_events = newSViv (revents);
216 SvREADONLY_on (sv_events);
217 }
218
219 PUSHMARK (SP);
220 EXTEND (SP, 2);
221 PUSHs (sv_self);
222 PUSHs (sv_events);
223
224 PUTBACK;
225 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
226
227 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
228 SvREFCNT_dec (sv_self);
229 else
230 {
231 SvREFCNT_dec (SvRV (sv_self));
232 SvRV_set (sv_self, &PL_sv_undef);
233 sv_self_cache = sv_self;
234 }
235
236 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
237 SvREFCNT_dec (sv_events);
238 else
239 sv_events_cache = sv_events;
240 258
241 if (expect_false (SvTRUE (ERRSV))) 259 if (expect_false (SvTRUE (ERRSV)))
242 { 260 {
243 SPAGAIN; 261 SPAGAIN;
244 PUSHMARK (SP); 262 PUSHMARK (SP);
340 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); 358 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
341 359
342#define CHECK_SIG(sv,num) if ((num) < 0) \ 360#define CHECK_SIG(sv,num) if ((num) < 0) \
343 croak ("illegal signal number or name: %s", SvPV_nolen (sv)); 361 croak ("illegal signal number or name: %s", SvPV_nolen (sv));
344 362
363static void
364default_fork (void)
365{
366 ev_loop_fork (EV_DEFAULT_UC);
367}
368
345///////////////////////////////////////////////////////////////////////////// 369/////////////////////////////////////////////////////////////////////////////
346// XS interface functions 370// XS interface functions
347 371
348MODULE = EV PACKAGE = EV PREFIX = ev_ 372MODULE = EV PACKAGE = EV PREFIX = ev_
349 373
364 const_iv (EV_, UNDEF) 388 const_iv (EV_, UNDEF)
365 const_iv (EV_, NONE) 389 const_iv (EV_, NONE)
366 const_iv (EV_, READ) 390 const_iv (EV_, READ)
367 const_iv (EV_, WRITE) 391 const_iv (EV_, WRITE)
368 const_iv (EV_, IO) 392 const_iv (EV_, IO)
369 const_iv (EV_, TIMEOUT) /* deprecated */
370 const_iv (EV_, TIMER) 393 const_iv (EV_, TIMER)
371 const_iv (EV_, PERIODIC) 394 const_iv (EV_, PERIODIC)
372 const_iv (EV_, SIGNAL) 395 const_iv (EV_, SIGNAL)
373 const_iv (EV_, CHILD) 396 const_iv (EV_, CHILD)
374 const_iv (EV_, STAT) 397 const_iv (EV_, STAT)
375 const_iv (EV_, IDLE) 398 const_iv (EV_, IDLE)
376 const_iv (EV_, PREPARE) 399 const_iv (EV_, PREPARE)
377 const_iv (EV_, CHECK) 400 /*const_iv (EV_, CHECK) needs special tretament */
378 const_iv (EV_, EMBED) 401 const_iv (EV_, EMBED)
379 const_iv (EV_, FORK) 402 const_iv (EV_, FORK)
403 const_iv (EV_, CLEANUP)
380 const_iv (EV_, ASYNC) 404 const_iv (EV_, ASYNC)
381 const_iv (EV_, CUSTOM) 405 const_iv (EV_, CUSTOM)
382 const_iv (EV_, ERROR) 406 const_iv (EV_, ERROR)
383 407
384 const_iv (EV, LOOP_NONBLOCK)
385 const_iv (EV, LOOP_ONESHOT)
386
387 const_iv (EV, UNLOOP_CANCEL) 408 const_iv (EV, RUN_NOWAIT)
388 const_iv (EV, UNLOOP_ONE) 409 const_iv (EV, RUN_ONCE)
410
411 const_iv (EV, BREAK_CANCEL)
412 const_iv (EV, BREAK_ONE)
389 const_iv (EV, UNLOOP_ALL) 413 const_iv (EV, BREAK_ALL)
390
391 const_iv (EV, BACKEND_SELECT) 414 const_iv (EV, BACKEND_SELECT)
392 const_iv (EV, BACKEND_POLL) 415 const_iv (EV, BACKEND_POLL)
393 const_iv (EV, BACKEND_EPOLL) 416 const_iv (EV, BACKEND_EPOLL)
394 const_iv (EV, BACKEND_KQUEUE) 417 const_iv (EV, BACKEND_KQUEUE)
395 const_iv (EV, BACKEND_DEVPOLL) 418 const_iv (EV, BACKEND_DEVPOLL)
396 const_iv (EV, BACKEND_PORT) 419 const_iv (EV, BACKEND_PORT)
397 const_iv (EV, BACKEND_ALL) 420 const_iv (EV, BACKEND_ALL)
421 const_iv (EV, BACKEND_MASK)
398 const_iv (EV, FLAG_AUTO) 422 const_iv (EV, FLAG_AUTO)
399 const_iv (EV, FLAG_FORKCHECK) 423 const_iv (EV, FLAG_FORKCHECK)
400 const_iv (EV, FLAG_SIGNALFD) 424 const_iv (EV, FLAG_SIGNALFD)
425 const_iv (EV, FLAG_NOSIGMASK)
401 const_iv (EV, FLAG_NOENV) 426 const_iv (EV, FLAG_NOENV)
402 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
403 const_iv (EV, FLAG_NOINOTIFY) 427 const_iv (EV, FLAG_NOINOTIFY)
404 428
405 const_iv (EV_, VERSION_MAJOR) 429 const_iv (EV_, VERSION_MAJOR)
406 const_iv (EV_, VERSION_MINOR) 430 const_iv (EV_, VERSION_MINOR)
431#if EV_COMPAT3
432 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
433 const_iv (EV_, TIMEOUT)
434 const_iv (EV, LOOP_NONBLOCK)
435 const_iv (EV, LOOP_ONESHOT)
436 const_iv (EV, UNLOOP_CANCEL)
437 const_iv (EV, UNLOOP_ONE)
438 const_iv (EV, UNLOOP_ALL)
439#endif
407 }; 440 };
408 441
409 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 442 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
410 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 443 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
444
445 /* since this clashes with perl CHECK blocks, */
446 /* but we are interested in constants, */
447 /* and not blocks, we treat CHECK specially. */
448 {
449 /* the local $^W = 0 takes care of the warning */
450 CV *cv = newCONSTSUB (stash, "CHECK", newSViv (EV_CHECK));
451 /* now we need to re-set the gv, in case it was hijacked */
452 GvCV_set (gv_fetchpv ("EV::CHECK", GV_ADD, SVt_PVCV), cv);
453 }
411 454
412 stash_loop = gv_stashpv ("EV::Loop" , 1); 455 stash_loop = gv_stashpv ("EV::Loop" , 1);
413 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 456 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
414 stash_io = gv_stashpv ("EV::IO" , 1); 457 stash_io = gv_stashpv ("EV::IO" , 1);
415 stash_timer = gv_stashpv ("EV::Timer" , 1); 458 stash_timer = gv_stashpv ("EV::Timer" , 1);
420 stash_check = gv_stashpv ("EV::Check" , 1); 463 stash_check = gv_stashpv ("EV::Check" , 1);
421 stash_child = gv_stashpv ("EV::Child" , 1); 464 stash_child = gv_stashpv ("EV::Child" , 1);
422 stash_embed = gv_stashpv ("EV::Embed" , 1); 465 stash_embed = gv_stashpv ("EV::Embed" , 1);
423 stash_stat = gv_stashpv ("EV::Stat" , 1); 466 stash_stat = gv_stashpv ("EV::Stat" , 1);
424 stash_fork = gv_stashpv ("EV::Fork" , 1); 467 stash_fork = gv_stashpv ("EV::Fork" , 1);
468 stash_cleanup = gv_stashpv ("EV::Cleanup" , 1);
425 stash_async = gv_stashpv ("EV::Async" , 1); 469 stash_async = gv_stashpv ("EV::Async" , 1);
426 470
427 { 471 {
428 SV *sv = perl_get_sv ("EV::API", TRUE); 472 SV *sv = perl_get_sv ("EV::API", TRUE);
429 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 473 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
448 evapi.now = ev_now; 492 evapi.now = ev_now;
449 evapi.now_update = ev_now_update; 493 evapi.now_update = ev_now_update;
450 evapi.suspend = ev_suspend; 494 evapi.suspend = ev_suspend;
451 evapi.resume = ev_resume; 495 evapi.resume = ev_resume;
452 evapi.backend = ev_backend; 496 evapi.backend = ev_backend;
453 evapi.unloop = ev_unloop; 497 evapi.break_ = ev_break;
454 evapi.invoke_pending = ev_invoke_pending; 498 evapi.invoke_pending = ev_invoke_pending;
455 evapi.pending_count = ev_pending_count; 499 evapi.pending_count = ev_pending_count;
456 evapi.verify = ev_verify; 500 evapi.verify = ev_verify;
457 evapi.set_loop_release_cb = ev_set_loop_release_cb; 501 evapi.set_loop_release_cb = ev_set_loop_release_cb;
458 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; 502 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
459 evapi.ref = ev_ref; 503 evapi.ref = ev_ref;
460 evapi.unref = ev_unref; 504 evapi.unref = ev_unref;
461 evapi.loop = ev_loop; 505 evapi.run = ev_run;
462 evapi.once = ev_once; 506 evapi.once = ev_once;
463 evapi.io_start = ev_io_start; 507 evapi.io_start = ev_io_start;
464 evapi.io_stop = ev_io_stop; 508 evapi.io_stop = ev_io_stop;
465 evapi.timer_start = ev_timer_start; 509 evapi.timer_start = ev_timer_start;
466 evapi.timer_stop = ev_timer_stop; 510 evapi.timer_stop = ev_timer_stop;
474 evapi.idle_stop = ev_idle_stop; 518 evapi.idle_stop = ev_idle_stop;
475 evapi.prepare_start = ev_prepare_start; 519 evapi.prepare_start = ev_prepare_start;
476 evapi.prepare_stop = ev_prepare_stop; 520 evapi.prepare_stop = ev_prepare_stop;
477 evapi.check_start = ev_check_start; 521 evapi.check_start = ev_check_start;
478 evapi.check_stop = ev_check_stop; 522 evapi.check_stop = ev_check_stop;
523#if EV_CHILD_ENABLE
479 evapi.child_start = ev_child_start; 524 evapi.child_start = ev_child_start;
480 evapi.child_stop = ev_child_stop; 525 evapi.child_stop = ev_child_stop;
526#endif
481 evapi.stat_start = ev_stat_start; 527 evapi.stat_start = ev_stat_start;
482 evapi.stat_stop = ev_stat_stop; 528 evapi.stat_stop = ev_stat_stop;
483 evapi.stat_stat = ev_stat_stat; 529 evapi.stat_stat = ev_stat_stat;
484 evapi.embed_start = ev_embed_start; 530 evapi.embed_start = ev_embed_start;
485 evapi.embed_stop = ev_embed_stop; 531 evapi.embed_stop = ev_embed_stop;
486 evapi.embed_sweep = ev_embed_sweep; 532 evapi.embed_sweep = ev_embed_sweep;
487 evapi.fork_start = ev_fork_start; 533 evapi.fork_start = ev_fork_start;
488 evapi.fork_stop = ev_fork_stop; 534 evapi.fork_stop = ev_fork_stop;
535 evapi.cleanup_start = ev_cleanup_start;
536 evapi.cleanup_stop = ev_cleanup_stop;
489 evapi.async_start = ev_async_start; 537 evapi.async_start = ev_async_start;
490 evapi.async_stop = ev_async_stop; 538 evapi.async_stop = ev_async_stop;
491 evapi.async_send = ev_async_send; 539 evapi.async_send = ev_async_send;
492 evapi.clear_pending = ev_clear_pending; 540 evapi.clear_pending = ev_clear_pending;
493 evapi.invoke = ev_invoke; 541 evapi.invoke = ev_invoke;
494 542
495 sv_setiv (sv, (IV)&evapi); 543 sv_setiv (sv, (IV)&evapi);
496 SvREADONLY_on (sv); 544 SvREADONLY_on (sv);
497 } 545 }
498#ifndef _WIN32 546#if !defined _WIN32 && !defined _MINIX
547#if __linux
548 int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
549 __register_atfork (0, 0, default_fork, 0);
550#else
499 pthread_atfork (0, 0, ev_default_fork); 551 pthread_atfork (0, 0, default_fork);
552#endif
500#endif 553#endif
501} 554}
502 555
503SV *ev_default_loop (unsigned int flags = 0) 556SV *ev_default_loop (unsigned int flags = 0)
504 CODE: 557 CODE:
518 OUTPUT: 571 OUTPUT:
519 RETVAL 572 RETVAL
520 573
521void ev_default_destroy () 574void ev_default_destroy ()
522 CODE: 575 CODE:
523 ev_default_destroy (); 576 ev_loop_destroy (EV_DEFAULT_UC);
524 SvREFCNT_dec (default_loop_sv); 577 SvREFCNT_dec (default_loop_sv);
525 default_loop_sv = 0; 578 default_loop_sv = 0;
526 579
527unsigned int ev_supported_backends () 580unsigned int ev_supported_backends ()
528 581
532 585
533void ev_sleep (NV interval) 586void ev_sleep (NV interval)
534 587
535NV ev_time () 588NV ev_time ()
536 589
590void ev_feed_signal (SV *signal)
591 CODE:
592{
593 Signal signum = s_signum (signal);
594 CHECK_SIG (signal, signum);
595
596 ev_feed_signal (signum);
597}
598
537NV ev_now () 599NV ev_now ()
538 C_ARGS: evapi.default_loop 600 C_ARGS: evapi.default_loop
539 601
540void ev_now_update () 602void ev_now_update ()
541 C_ARGS: evapi.default_loop 603 C_ARGS: evapi.default_loop
548 610
549unsigned int ev_backend () 611unsigned int ev_backend ()
550 C_ARGS: evapi.default_loop 612 C_ARGS: evapi.default_loop
551 613
552void ev_verify () 614void ev_verify ()
615 ALIAS:
616 loop_verify = 1
553 C_ARGS: evapi.default_loop 617 C_ARGS: evapi.default_loop
554 618
555unsigned int ev_iteration () 619unsigned int ev_iteration ()
620 ALIAS:
621 loop_count = 1
556 C_ARGS: evapi.default_loop 622 C_ARGS: evapi.default_loop
557 623
558unsigned int ev_depth () 624unsigned int ev_depth ()
625 ALIAS:
626 loop_depth = 1
559 C_ARGS: evapi.default_loop 627 C_ARGS: evapi.default_loop
560 628
561void ev_set_io_collect_interval (NV interval) 629void ev_set_io_collect_interval (NV interval)
562 C_ARGS: evapi.default_loop, interval 630 C_ARGS: evapi.default_loop, interval
563 631
564void ev_set_timeout_collect_interval (NV interval) 632void ev_set_timeout_collect_interval (NV interval)
565 C_ARGS: evapi.default_loop, interval 633 C_ARGS: evapi.default_loop, interval
566 634
567void ev_loop (int flags = 0) 635int ev_run (int flags = 0)
636 ALIAS:
637 loop = 1
568 C_ARGS: evapi.default_loop, flags 638 C_ARGS: evapi.default_loop, flags
569 639
570void ev_unloop (int how = EVUNLOOP_ONE) 640void ev_break (int how = EVBREAK_ONE)
641 ALIAS:
642 unloop = 1
571 C_ARGS: evapi.default_loop, how 643 C_ARGS: evapi.default_loop, how
572 644
573void ev_feed_fd_event (int fd, int revents = EV_NONE) 645void ev_feed_fd_event (int fd, int revents = EV_NONE)
574 C_ARGS: evapi.default_loop, fd, revents 646 C_ARGS: evapi.default_loop, fd, revents
575 647
576void ev_feed_signal_event (SV *signal) 648void ev_feed_signal_event (SV *signal)
577 CODE: 649 CODE:
578{ 650{
579 Signal signum = s_signum (signal); 651 Signal signum = s_signum (signal);
580 CHECK_SIG (signal, signum); 652 CHECK_SIG (signal, signum);
581 653
582 ev_feed_signal_event (evapi.default_loop, signum); 654 ev_feed_signal_event (evapi.default_loop, signum);
583} 655}
584 656
594 _ae_io = 2 666 _ae_io = 2
595 CODE: 667 CODE:
596{ 668{
597 int fd = s_fileno (fh, events & EV_WRITE); 669 int fd = s_fileno (fh, events & EV_WRITE);
598 CHECK_FD (fh, fd); 670 CHECK_FD (fh, fd);
671 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
672 e_fh (RETVAL) = newSVsv (fh);
599 673
600 if (ix == 2) 674 if (ix == 2)
601 { 675 {
602 ix = 0;
603 events = events ? EV_WRITE : EV_READ; 676 events = events ? EV_WRITE : EV_READ;
677 e_flags (RETVAL) |= WFLAG_NOARGS;
604 } 678 }
605 679
606 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
607 e_fh (RETVAL) = newSVsv (fh);
608 ev_io_set (RETVAL, fd, events); 680 ev_io_set (RETVAL, fd, events);
609 if (!ix) START (io, RETVAL); 681 if (ix != 1) START (io, RETVAL);
610} 682}
611 OUTPUT: 683 OUTPUT:
612 RETVAL 684 RETVAL
613 685
614ev_timer *timer (NV after, NV repeat, SV *cb) 686ev_timer *timer (NV after, NV repeat, SV *cb)
693 ev_fork_set (RETVAL); 765 ev_fork_set (RETVAL);
694 if (!ix) START (fork, RETVAL); 766 if (!ix) START (fork, RETVAL);
695 OUTPUT: 767 OUTPUT:
696 RETVAL 768 RETVAL
697 769
770#if CLEANUP_ENABLED
771
772ev_cleanup *cleanup (SV *cb)
773 ALIAS:
774 cleanup_ns = 1
775 CODE:
776 RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
777 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
778 ev_cleanup_set (RETVAL);
779 if (!ix) START (cleanup, RETVAL);
780 OUTPUT:
781 RETVAL
782
783#endif
784
698ev_child *child (int pid, int trace, SV *cb) 785ev_child *child (int pid, int trace, SV *cb)
699 ALIAS: 786 ALIAS:
700 child_ns = 1 787 child_ns = 1
701 CODE: 788 CODE:
789#if EV_CHILD_ENABLE
702 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 790 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
703 ev_child_set (RETVAL, pid, trace); 791 ev_child_set (RETVAL, pid, trace);
704 if (!ix) START (child, RETVAL); 792 if (!ix) START (child, RETVAL);
793#else
794 croak ("EV::child watchers not supported on this platform");
795#endif
705 OUTPUT: 796 OUTPUT:
706 RETVAL 797 RETVAL
798
707 799
708ev_stat *stat (SV *path, NV interval, SV *cb) 800ev_stat *stat (SV *path, NV interval, SV *cb)
709 ALIAS: 801 ALIAS:
710 stat_ns = 1 802 stat_ns = 1
711 CODE: 803 CODE:
714 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval); 806 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
715 if (!ix) START (stat, RETVAL); 807 if (!ix) START (stat, RETVAL);
716 OUTPUT: 808 OUTPUT:
717 RETVAL 809 RETVAL
718 810
811#ifndef EV_NO_LOOPS
812
719ev_embed *embed (struct ev_loop *loop, SV *cb = 0) 813ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
720 ALIAS: 814 ALIAS:
721 embed_ns = 1 815 embed_ns = 1
722 CODE: 816 CODE:
723{ 817{
729 ev_embed_set (RETVAL, loop); 823 ev_embed_set (RETVAL, loop);
730 if (!ix) START (embed, RETVAL); 824 if (!ix) START (embed, RETVAL);
731} 825}
732 OUTPUT: 826 OUTPUT:
733 RETVAL 827 RETVAL
828
829#endif
734 830
735ev_async *async (SV *cb) 831ev_async *async (SV *cb)
736 ALIAS: 832 ALIAS:
737 async_ns = 1 833 async_ns = 1
738 CODE: 834 CODE:
1077void DESTROY (ev_fork *w) 1173void DESTROY (ev_fork *w)
1078 CODE: 1174 CODE:
1079 STOP (fork, w); 1175 STOP (fork, w);
1080 e_destroy (w); 1176 e_destroy (w);
1081 1177
1178#if CLEANUP_ENABLED
1179
1180MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1181
1182void ev_cleanup_start (ev_cleanup *w)
1183 CODE:
1184 START (cleanup, w);
1185
1186void ev_cleanup_stop (ev_cleanup *w)
1187 CODE:
1188 STOP (cleanup, w);
1189
1190void DESTROY (ev_cleanup *w)
1191 CODE:
1192 STOP (cleanup, w);
1193 SvREFCNT_inc (w->loop); /* has been dec'ed on creation */
1194 e_destroy (w);
1195
1196int keepalive (ev_watcher *w, SV *new_value = 0)
1197 CODE:
1198 RETVAL = 1;
1199 OUTPUT:
1200 RETVAL
1201
1202#endif
1203
1082MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 1204MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1205
1206#if EV_CHILD_ENABLE
1083 1207
1084void ev_child_start (ev_child *w) 1208void ev_child_start (ev_child *w)
1085 CODE: 1209 CODE:
1086 START (child, w); 1210 START (child, w);
1087 1211
1106 RETVAL = ix == 0 ? w->pid 1230 RETVAL = ix == 0 ? w->pid
1107 : ix == 1 ? w->rpid 1231 : ix == 1 ? w->rpid
1108 : w->rstatus; 1232 : w->rstatus;
1109 OUTPUT: 1233 OUTPUT:
1110 RETVAL 1234 RETVAL
1235
1236#endif
1111 1237
1112MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1238MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1113 1239
1114void ev_stat_start (ev_stat *w) 1240void ev_stat_start (ev_stat *w)
1115 CODE: 1241 CODE:
1256 CODE: 1382 CODE:
1257 RETVAL = boolSV (ev_async_pending (w)); 1383 RETVAL = boolSV (ev_async_pending (w));
1258 OUTPUT: 1384 OUTPUT:
1259 RETVAL 1385 RETVAL
1260 1386
1387#ifndef EV_NO_LOOPS
1388
1261MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1389MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1262 1390
1263SV *new (SV *klass, unsigned int flags = 0) 1391SV *new (SV *klass, unsigned int flags = 0)
1264 CODE: 1392 CODE:
1265{ 1393{
1273 OUTPUT: 1401 OUTPUT:
1274 RETVAL 1402 RETVAL
1275 1403
1276void DESTROY (struct ev_loop *loop) 1404void DESTROY (struct ev_loop *loop)
1277 CODE: 1405 CODE:
1278 if (loop != evapi.default_loop) /* global destruction sucks */ 1406 /* 1. the default loop shouldn't be freed by destroying it's perl loop object */
1407 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1408 if (loop != evapi.default_loop)
1279 ev_loop_destroy (loop); 1409 ev_loop_destroy (loop);
1280 1410
1281void ev_loop_fork (struct ev_loop *loop) 1411void ev_loop_fork (struct ev_loop *loop)
1282 1412
1413NV ev_now (struct ev_loop *loop)
1414
1415void ev_now_update (struct ev_loop *loop)
1416
1417void ev_suspend (struct ev_loop *loop)
1418
1419void ev_resume (struct ev_loop *loop)
1420
1421void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1422
1423void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1424
1425unsigned int ev_backend (struct ev_loop *loop)
1426
1283void ev_verify (struct ev_loop *loop) 1427void ev_verify (struct ev_loop *loop)
1284 1428 ALIAS:
1285NV ev_now (struct ev_loop *loop) 1429 loop_verify = 1
1286
1287void ev_now_update (struct ev_loop *loop)
1288
1289void ev_suspend (struct ev_loop *loop)
1290
1291void ev_resume (struct ev_loop *loop)
1292
1293void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1294
1295void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1296
1297unsigned int ev_backend (struct ev_loop *loop)
1298 1430
1299unsigned int ev_iteration (struct ev_loop *loop) 1431unsigned int ev_iteration (struct ev_loop *loop)
1432 ALIAS:
1433 loop_count = 1
1300 1434
1301unsigned int ev_depth (struct ev_loop *loop) 1435unsigned int ev_depth (struct ev_loop *loop)
1436 ALIAS:
1437 loop_depth = 1
1302 1438
1303void ev_loop (struct ev_loop *loop, int flags = 0) 1439int ev_run (struct ev_loop *loop, int flags = 0)
1440 ALIAS:
1441 loop = 1
1304 1442
1305void ev_unloop (struct ev_loop *loop, int how = 1) 1443void ev_break (struct ev_loop *loop, int how = 1)
1444 ALIAS:
1445 unloop = 1
1306 1446
1307void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) 1447void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1308 1448
1309unsigned int ev_pending_count (struct ev_loop *loop) 1449unsigned int ev_pending_count (struct ev_loop *loop)
1310 1450
1313#if 0 1453#if 0
1314 1454
1315void ev_feed_signal_event (struct ev_loop *loop, SV *signal) 1455void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1316 CODE: 1456 CODE:
1317{ 1457{
1318 Signal signum = s_signum (signal); 1458 Signal signum = s_signum (signal);
1319 CHECK_SIG (signal, signum); 1459 CHECK_SIG (signal, signum);
1320 1460
1321 ev_feed_signal_event (loop, signum); 1461 ev_feed_signal_event (loop, signum);
1322} 1462}
1323 1463
1356 periodic_ns = 1 1496 periodic_ns = 1
1357 INIT: 1497 INIT:
1358 CHECK_REPEAT (interval); 1498 CHECK_REPEAT (interval);
1359 CODE: 1499 CODE:
1360{ 1500{
1361 ev_periodic *w; 1501 ev_periodic *w;
1362 w = e_new (sizeof (ev_periodic), cb, ST (0)); 1502 w = e_new (sizeof (ev_periodic), cb, ST (0));
1363 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 1503 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1364 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); 1504 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
1365 RETVAL = e_bless ((ev_watcher *)w, stash_periodic); 1505 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1366 if (!ix) START (periodic, w); 1506 if (!ix) START (periodic, w);
1371ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) 1511ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1372 ALIAS: 1512 ALIAS:
1373 signal_ns = 1 1513 signal_ns = 1
1374 CODE: 1514 CODE:
1375{ 1515{
1376 Signal signum = s_signum (signal); 1516 Signal signum = s_signum (signal);
1377 CHECK_SIG (signal, signum); 1517 CHECK_SIG (signal, signum);
1378 1518
1379 RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); 1519 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1380 ev_signal_set (RETVAL, signum); 1520 ev_signal_set (RETVAL, signum);
1381 if (!ix) START_SIGNAL (RETVAL); 1521 if (!ix) START_SIGNAL (RETVAL);
1421 ev_fork_set (RETVAL); 1561 ev_fork_set (RETVAL);
1422 if (!ix) START (fork, RETVAL); 1562 if (!ix) START (fork, RETVAL);
1423 OUTPUT: 1563 OUTPUT:
1424 RETVAL 1564 RETVAL
1425 1565
1566#if CLEANUP_ENABLED
1567
1568ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1569 ALIAS:
1570 cleanup_ns = 1
1571 CODE:
1572 RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1573 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
1574 ev_cleanup_set (RETVAL);
1575 if (!ix) START (cleanup, RETVAL);
1576 OUTPUT:
1577 RETVAL
1578
1579#endif
1580
1426ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) 1581ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1427 ALIAS: 1582 ALIAS:
1428 child_ns = 1 1583 child_ns = 1
1429 CODE: 1584 CODE:
1585#if EV_CHILD_ENABLE
1430 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1586 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1431 ev_child_set (RETVAL, pid, trace); 1587 ev_child_set (RETVAL, pid, trace);
1432 if (!ix) START (child, RETVAL); 1588 if (!ix) START (child, RETVAL);
1589#else
1590 croak ("EV::child watchers not supported on this platform");
1591#endif
1433 OUTPUT: 1592 OUTPUT:
1434 RETVAL 1593 RETVAL
1435 1594
1436ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1595ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1437 ALIAS: 1596 ALIAS:
1478 SvOK (timeout) ? SvNV (timeout) : -1., 1637 SvOK (timeout) ? SvNV (timeout) : -1.,
1479 e_once_cb, 1638 e_once_cb,
1480 newSVsv (cb) 1639 newSVsv (cb)
1481 ); 1640 );
1482 1641
1642#endif
1643

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines