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

Comparing EV/EV.xs (file contents):
Revision 1.102 by root, Sat Dec 22 16:37:08 2007 UTC vs.
Revision 1.124 by root, Mon Jun 29 18:46:52 2009 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6
7/* fix perl api breakage */
8#undef signal
9#undef sigaction
6 10
7#define EV_PROTOTYPES 1 11#define EV_PROTOTYPES 1
8#define EV_USE_NANOSLEEP EV_USE_MONOTONIC 12#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
9#define EV_H <ev.h> 13#define EV_H <ev.h>
10#include "EV/EVAPI.h" 14#include "EV/EVAPI.h"
11
12/* fix perl api breakage */
13#undef signal
14#undef sigaction
15 15
16#define EV_SELECT_IS_WINSOCKET 0 16#define EV_SELECT_IS_WINSOCKET 0
17#ifdef _WIN32 17#ifdef _WIN32
18# define EV_SELECT_USE_FD_SET 0 18# define EV_SELECT_USE_FD_SET 0
19# define NFDBITS PERL_NFDBITS 19# define NFDBITS PERL_NFDBITS
24 24
25#ifndef _WIN32 25#ifndef _WIN32
26# include <pthread.h> 26# include <pthread.h>
27#endif 27#endif
28 28
29/* 5.10.0 */
30#ifndef SvREFCNT_inc_NN
31# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv)
32#endif
33
34/* 5.6.x */
35#ifndef SvRV_set
36# define SvRV_set(a,b) SvRV ((a)) = (b)
37#endif
38
29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 39#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
30 40
31#define WFLAG_KEEPALIVE 1 41#define WFLAG_KEEPALIVE 1
42#define WFLAG_UNREFED 2 /* has been unref'ed */
32 43
33#define UNREF(w) \ 44#define UNREF(w) \
34 if (!((w)->flags & WFLAG_KEEPALIVE) \ 45 if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
35 && !ev_is_active (w)) \ 46 && ev_is_active (w)) \
47 { \
36 ev_unref (e_loop (w)); 48 ev_unref (e_loop (w)); \
49 (w)->e_flags |= WFLAG_UNREFED; \
50 }
37 51
38#define REF(w) \ 52#define REF(w) \
39 if (!((w)->flags & WFLAG_KEEPALIVE) \ 53 if ((w)->e_flags & WFLAG_UNREFED) \
40 && ev_is_active (w)) \ 54 { \
55 (w)->e_flags &= ~WFLAG_UNREFED; \
41 ev_ref (e_loop (w)); 56 ev_ref (e_loop (w)); \
57 }
42 58
43#define START(type,w) \ 59#define START(type,w) \
44 do { \ 60 do { \
61 ev_ ## type ## _start (e_loop (w), w); \
45 UNREF (w); \ 62 UNREF (w); \
46 ev_ ## type ## _start (e_loop (w), w); \
47 } while (0) 63 } while (0)
48 64
49#define STOP(type,w) \ 65#define STOP(type,w) \
50 do { \ 66 do { \
51 REF (w); \ 67 REF (w); \
52 ev_ ## type ## _stop (e_loop (w), w); \ 68 ev_ ## type ## _stop (e_loop (w), w); \
53 } while (0) 69 } while (0)
54 70
55#define RESET(type,w,seta) \ 71#define RESET(type,w,seta) \
56 do { \ 72 do { \
57 int active = ev_is_active (w); \ 73 int active = ev_is_active (w); \
77 *stash_stat, 93 *stash_stat,
78 *stash_idle, 94 *stash_idle,
79 *stash_prepare, 95 *stash_prepare,
80 *stash_check, 96 *stash_check,
81 *stash_embed, 97 *stash_embed,
82 *stash_fork; 98 *stash_fork,
99 *stash_async;
83 100
84#ifndef SIG_SIZE 101#ifndef SIG_SIZE
85/* kudos to Slaven Rezic for the idea */ 102/* kudos to Slaven Rezic for the idea */
86static char sig_size [] = { SIG_NUM }; 103static char sig_size [] = { SIG_NUM };
87# define SIG_SIZE (sizeof (sig_size) + 1) 104# define SIG_SIZE (sizeof (sig_size) + 1)
126 return SvIV (fh); 143 return SvIV (fh);
127 144
128 return -1; 145 return -1;
129} 146}
130 147
148static SV *
149e_get_cv (SV *cb_sv)
150{
151 HV *st;
152 GV *gvp;
153 CV *cv = sv_2cv (cb_sv, &st, &gvp, 0);
154
155 if (!cv)
156 croak ("EV watcher callback must be a CODE reference");
157
158 return (SV *)cv;
159}
160
131static void * 161static void *
132e_new (int size, SV *cb_sv, SV *loop) 162e_new (int size, SV *cb_sv, SV *loop)
133{ 163{
164 SV *cv = cb_sv ? e_get_cv (cb_sv) : 0;
134 ev_watcher *w; 165 ev_watcher *w;
135 SV *self = NEWSV (0, size); 166 SV *self = NEWSV (0, size);
136 SvPOK_only (self); 167 SvPOK_only (self);
137 SvCUR_set (self, size); 168 SvCUR_set (self, size);
138 169
139 w = (ev_watcher *)SvPVX (self); 170 w = (ev_watcher *)SvPVX (self);
140 171
141 ev_init (w, e_cb); 172 ev_init (w, cv ? e_cb : 0);
142 173
143 w->loop = SvREFCNT_inc (SvRV (loop)); 174 w->loop = SvREFCNT_inc (SvRV (loop));
144 w->flags = WFLAG_KEEPALIVE; 175 w->e_flags = WFLAG_KEEPALIVE;
145 w->data = 0; 176 w->data = 0;
146 w->fh = 0; 177 w->fh = 0;
147 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); 178 w->cb_sv = SvREFCNT_inc (cv);
148 w->self = self; 179 w->self = self;
149 180
150 return (void *)w; 181 return (void *)w;
151} 182}
152 183
153static void 184static void
176 } 207 }
177 208
178 return rv; 209 return rv;
179} 210}
180 211
181static SV *sv_events_cache; 212static SV *sv_self_cache, *sv_events_cache;
182 213
183static void 214static void
184e_cb (EV_P_ ev_watcher *w, int revents) 215e_cb (EV_P_ ev_watcher *w, int revents)
185{ 216{
186 dSP; 217 dSP;
187 I32 mark = SP - PL_stack_base; 218 I32 mark = SP - PL_stack_base;
188 SV *sv_self, *sv_events; 219 SV *sv_self, *sv_events;
189 220
221 /* libev might have stopped the watcher */
222 if (expect_false (w->e_flags & WFLAG_UNREFED)
223 && !ev_is_active (w))
224 REF (w);
225
226 if (expect_true (sv_self_cache))
227 {
228 sv_self = sv_self_cache; sv_self_cache = 0;
229 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
230 }
231 else
232 {
190 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 233 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
234 SvREADONLY_on (sv_self);
235 }
236
237 if (expect_true (sv_events_cache))
238 {
239 sv_events = sv_events_cache; sv_events_cache = 0;
240 SvIV_set (sv_events, revents);
241 }
242 else
243 {
244 sv_events = newSViv (revents);
245 SvREADONLY_on (sv_events);
246 }
247
248 PUSHMARK (SP);
249 EXTEND (SP, 2);
250 PUSHs (sv_self);
251 PUSHs (sv_events);
252
253 PUTBACK;
254 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
255
256 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
257 SvREFCNT_dec (sv_self);
258 else
259 {
260 SvREFCNT_dec (SvRV (sv_self));
261 SvRV_set (sv_self, &PL_sv_undef);
262 sv_self_cache = sv_self;
263 }
264
265 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
266 SvREFCNT_dec (sv_events);
267 else
268 sv_events_cache = sv_events;
269
270 if (expect_false (SvTRUE (ERRSV)))
271 {
272 SPAGAIN;
273 PUSHMARK (SP);
274 PUTBACK;
275 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
276 }
277
278 SP = PL_stack_base + mark;
279 PUTBACK;
280}
281
282static void
283e_once_cb (int revents, void *arg)
284{
285 dSP;
286 I32 mark = SP - PL_stack_base;
287 SV *sv_events;
191 288
192 if (sv_events_cache) 289 if (sv_events_cache)
193 { 290 {
194 sv_events = sv_events_cache; sv_events_cache = 0; 291 sv_events = sv_events_cache; sv_events_cache = 0;
195 SvIV_set (sv_events, revents); 292 SvIV_set (sv_events, revents);
196 } 293 }
197 else 294 else
198 sv_events = newSViv (revents); 295 sv_events = newSViv (revents);
199 296
200 PUSHMARK (SP); 297 PUSHMARK (SP);
201 EXTEND (SP, 2);
202 PUSHs (sv_self);
203 PUSHs (sv_events); 298 XPUSHs (sv_events);
204 299
205 PUTBACK; 300 PUTBACK;
206 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 301 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
207 302
208 SvREFCNT_dec (sv_self); 303 SvREFCNT_dec ((SV *)arg);
209 304
210 if (sv_events_cache) 305 if (sv_events_cache)
211 SvREFCNT_dec (sv_events); 306 SvREFCNT_dec (sv_events);
212 else 307 else
213 sv_events_cache = sv_events; 308 sv_events_cache = sv_events;
222 317
223 SP = PL_stack_base + mark; 318 SP = PL_stack_base + mark;
224 PUTBACK; 319 PUTBACK;
225} 320}
226 321
227static void
228e_once_cb (int revents, void *arg)
229{
230 dSP;
231 I32 mark = SP - PL_stack_base;
232 SV *sv_events;
233
234 if (sv_events_cache)
235 {
236 sv_events = sv_events_cache; sv_events_cache = 0;
237 SvIV_set (sv_events, revents);
238 }
239 else
240 sv_events = newSViv (revents);
241
242 PUSHMARK (SP);
243 XPUSHs (sv_events);
244
245 PUTBACK;
246 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
247
248 SvREFCNT_dec ((SV *)arg);
249
250 if (sv_events_cache)
251 SvREFCNT_dec (sv_events);
252 else
253 sv_events_cache = sv_events;
254
255 if (SvTRUE (ERRSV))
256 {
257 SPAGAIN;
258 PUSHMARK (SP);
259 PUTBACK;
260 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
261 }
262
263 SP = PL_stack_base + mark;
264 PUTBACK;
265}
266
267static ev_tstamp 322static ev_tstamp
268e_periodic_cb (ev_periodic *w, ev_tstamp now) 323e_periodic_cb (ev_periodic *w, ev_tstamp now)
269{ 324{
270 ev_tstamp retval; 325 ev_tstamp retval;
271 int count; 326 int count;
335 const_iv (EV_, MINPRI) 390 const_iv (EV_, MINPRI)
336 const_iv (EV_, MAXPRI) 391 const_iv (EV_, MAXPRI)
337 392
338 const_iv (EV_, UNDEF) 393 const_iv (EV_, UNDEF)
339 const_iv (EV_, NONE) 394 const_iv (EV_, NONE)
340 const_iv (EV_, TIMEOUT)
341 const_iv (EV_, READ) 395 const_iv (EV_, READ)
342 const_iv (EV_, WRITE) 396 const_iv (EV_, WRITE)
397 const_iv (EV_, IO)
398 const_iv (EV_, TIMEOUT)
399 const_iv (EV_, TIMER)
400 const_iv (EV_, PERIODIC)
343 const_iv (EV_, SIGNAL) 401 const_iv (EV_, SIGNAL)
402 const_iv (EV_, CHILD)
403 const_iv (EV_, STAT)
344 const_iv (EV_, IDLE) 404 const_iv (EV_, IDLE)
405 const_iv (EV_, PREPARE)
345 const_iv (EV_, CHECK) 406 const_iv (EV_, CHECK)
407 const_iv (EV_, EMBED)
408 const_iv (EV_, FORK)
409 const_iv (EV_, ASYNC)
410 const_iv (EV_, CUSTOM)
346 const_iv (EV_, ERROR) 411 const_iv (EV_, ERROR)
347 412
413 const_iv (EV, LOOP_NONBLOCK)
348 const_iv (EV, LOOP_ONESHOT) 414 const_iv (EV, LOOP_ONESHOT)
415
349 const_iv (EV, LOOP_NONBLOCK) 416 const_iv (EV, UNLOOP_CANCEL)
350 const_iv (EV, UNLOOP_ONE) 417 const_iv (EV, UNLOOP_ONE)
351 const_iv (EV, UNLOOP_ALL) 418 const_iv (EV, UNLOOP_ALL)
352 419
353 const_iv (EV, BACKEND_SELECT) 420 const_iv (EV, BACKEND_SELECT)
354 const_iv (EV, BACKEND_POLL) 421 const_iv (EV, BACKEND_POLL)
357 const_iv (EV, BACKEND_DEVPOLL) 424 const_iv (EV, BACKEND_DEVPOLL)
358 const_iv (EV, BACKEND_PORT) 425 const_iv (EV, BACKEND_PORT)
359 const_iv (EV, FLAG_AUTO) 426 const_iv (EV, FLAG_AUTO)
360 const_iv (EV, FLAG_NOENV) 427 const_iv (EV, FLAG_NOENV)
361 const_iv (EV, FLAG_FORKCHECK) 428 const_iv (EV, FLAG_FORKCHECK)
429
430 const_iv (EV_, VERSION_MAJOR)
431 const_iv (EV_, VERSION_MINOR)
362 }; 432 };
363 433
364 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 434 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
365 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 435 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
366 436
375 stash_check = gv_stashpv ("EV::Check" , 1); 445 stash_check = gv_stashpv ("EV::Check" , 1);
376 stash_child = gv_stashpv ("EV::Child" , 1); 446 stash_child = gv_stashpv ("EV::Child" , 1);
377 stash_embed = gv_stashpv ("EV::Embed" , 1); 447 stash_embed = gv_stashpv ("EV::Embed" , 1);
378 stash_stat = gv_stashpv ("EV::Stat" , 1); 448 stash_stat = gv_stashpv ("EV::Stat" , 1);
379 stash_fork = gv_stashpv ("EV::Fork" , 1); 449 stash_fork = gv_stashpv ("EV::Fork" , 1);
450 stash_async = gv_stashpv ("EV::Async" , 1);
380 451
381 { 452 {
382 SV *sv = perl_get_sv ("EV::API", TRUE); 453 SV *sv = perl_get_sv ("EV::API", TRUE);
383 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 454 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
384 455
388 evapi.sv_fileno = sv_fileno; 459 evapi.sv_fileno = sv_fileno;
389 evapi.sv_signum = sv_signum; 460 evapi.sv_signum = sv_signum;
390 evapi.supported_backends = ev_supported_backends (); 461 evapi.supported_backends = ev_supported_backends ();
391 evapi.recommended_backends = ev_recommended_backends (); 462 evapi.recommended_backends = ev_recommended_backends ();
392 evapi.embeddable_backends = ev_embeddable_backends (); 463 evapi.embeddable_backends = ev_embeddable_backends ();
393 evapi.time = ev_time; 464 evapi.time_ = ev_time;
394 evapi.sleep = ev_sleep; 465 evapi.sleep_ = ev_sleep;
395 evapi.loop_new = ev_loop_new; 466 evapi.loop_new = ev_loop_new;
396 evapi.loop_destroy = ev_loop_destroy; 467 evapi.loop_destroy = ev_loop_destroy;
397 evapi.loop_fork = ev_loop_fork; 468 evapi.loop_fork = ev_loop_fork;
398 evapi.loop_count = ev_loop_count; 469 evapi.loop_count = ev_loop_count;
399 evapi.now = ev_now; 470 evapi.now = ev_now;
471 evapi.now_update = ev_now_update;
472 evapi.suspend = ev_suspend;
473 evapi.resume = ev_resume;
400 evapi.backend = ev_backend; 474 evapi.backend = ev_backend;
401 evapi.unloop = ev_unloop; 475 evapi.unloop = ev_unloop;
402 evapi.ref = ev_ref; 476 evapi.ref = ev_ref;
403 evapi.unref = ev_unref; 477 evapi.unref = ev_unref;
404 evapi.loop = ev_loop; 478 evapi.loop = ev_loop;
426 evapi.embed_start = ev_embed_start; 500 evapi.embed_start = ev_embed_start;
427 evapi.embed_stop = ev_embed_stop; 501 evapi.embed_stop = ev_embed_stop;
428 evapi.embed_sweep = ev_embed_sweep; 502 evapi.embed_sweep = ev_embed_sweep;
429 evapi.fork_start = ev_fork_start; 503 evapi.fork_start = ev_fork_start;
430 evapi.fork_stop = ev_fork_stop; 504 evapi.fork_stop = ev_fork_stop;
505 evapi.async_start = ev_async_start;
506 evapi.async_stop = ev_async_stop;
507 evapi.async_send = ev_async_send;
431 evapi.clear_pending = ev_clear_pending; 508 evapi.clear_pending = ev_clear_pending;
432 evapi.invoke = ev_invoke; 509 evapi.invoke = ev_invoke;
433 510
434 sv_setiv (sv, (IV)&evapi); 511 sv_setiv (sv, (IV)&evapi);
435 SvREADONLY_on (sv); 512 SvREADONLY_on (sv);
467 544
468unsigned int ev_recommended_backends () 545unsigned int ev_recommended_backends ()
469 546
470unsigned int ev_embeddable_backends () 547unsigned int ev_embeddable_backends ()
471 548
549void ev_sleep (NV interval)
550
472NV ev_time () 551NV ev_time ()
473 552
474NV ev_now () 553NV ev_now ()
475 C_ARGS: evapi.default_loop 554 C_ARGS: evapi.default_loop
476 555
556void ev_now_update ()
557 C_ARGS: evapi.default_loop
558
559void ev_suspend ()
560 C_ARGS: evapi.default_loop
561
562void ev_resume ()
563 C_ARGS: evapi.default_loop
564
477unsigned int ev_backend () 565unsigned int ev_backend ()
478 C_ARGS: evapi.default_loop 566 C_ARGS: evapi.default_loop
479 567
480unsigned int ev_loop_count () 568unsigned int ev_loop_count ()
481 C_ARGS: evapi.default_loop 569 C_ARGS: evapi.default_loop
487 C_ARGS: evapi.default_loop, interval 575 C_ARGS: evapi.default_loop, interval
488 576
489void ev_loop (int flags = 0) 577void ev_loop (int flags = 0)
490 C_ARGS: evapi.default_loop, flags 578 C_ARGS: evapi.default_loop, flags
491 579
492void ev_unloop (int how = 1) 580void ev_unloop (int how = EVUNLOOP_ONE)
493 C_ARGS: evapi.default_loop, how 581 C_ARGS: evapi.default_loop, how
494 582
495void ev_feed_fd_event (int fd, int revents = EV_NONE) 583void ev_feed_fd_event (int fd, int revents = EV_NONE)
496 C_ARGS: evapi.default_loop, fd, revents 584 C_ARGS: evapi.default_loop, fd, revents
497 585
602 ev_fork_set (RETVAL); 690 ev_fork_set (RETVAL);
603 if (!ix) START (fork, RETVAL); 691 if (!ix) START (fork, RETVAL);
604 OUTPUT: 692 OUTPUT:
605 RETVAL 693 RETVAL
606 694
607ev_child *child (int pid, SV *cb) 695ev_child *child (int pid, int trace, SV *cb)
608 ALIAS: 696 ALIAS:
609 child_ns = 1 697 child_ns = 1
610 CODE: 698 CODE:
611 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 699 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
612 ev_child_set (RETVAL, pid); 700 ev_child_set (RETVAL, pid, trace);
613 if (!ix) START (child, RETVAL); 701 if (!ix) START (child, RETVAL);
614 OUTPUT: 702 OUTPUT:
615 RETVAL 703 RETVAL
616 704
617ev_stat *stat (SV *path, NV interval, SV *cb) 705ev_stat *stat (SV *path, NV interval, SV *cb)
623 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 711 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
624 if (!ix) START (stat, RETVAL); 712 if (!ix) START (stat, RETVAL);
625 OUTPUT: 713 OUTPUT:
626 RETVAL 714 RETVAL
627 715
628ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef) 716ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
629 ALIAS: 717 ALIAS:
630 embed_ns = 1 718 embed_ns = 1
631 CODE: 719 CODE:
632{ 720{
633 if (!(ev_backend (loop) & ev_embeddable_backends ())) 721 if (!(ev_backend (loop) & ev_embeddable_backends ()))
634 croak ("passed loop is not embeddable via EV::embed,"); 722 croak ("passed loop is not embeddable via EV::embed,");
635 723
636 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); 724 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
637 RETVAL->fh = newSVsv (ST (0)); 725 RETVAL->fh = newSVsv (ST (0));
638 ev_embed_set (RETVAL, loop); 726 ev_embed_set (RETVAL, loop);
639
640 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
641
642 if (!ix) START (embed, RETVAL); 727 if (!ix) START (embed, RETVAL);
643} 728}
729 OUTPUT:
730 RETVAL
731
732ev_async *async (SV *cb)
733 ALIAS:
734 async_ns = 1
735 CODE:
736 RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
737 ev_async_set (RETVAL);
738 if (!ix) START (async, RETVAL);
644 OUTPUT: 739 OUTPUT:
645 RETVAL 740 RETVAL
646 741
647void once (SV *fh, int events, SV *timeout, SV *cb) 742void once (SV *fh, int events, SV *timeout, SV *cb)
648 CODE: 743 CODE:
672 C_ARGS: e_loop (w), w, revents 767 C_ARGS: e_loop (w), w, revents
673 768
674int keepalive (ev_watcher *w, int new_value = 0) 769int keepalive (ev_watcher *w, int new_value = 0)
675 CODE: 770 CODE:
676{ 771{
677 RETVAL = w->flags & WFLAG_KEEPALIVE; 772 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
678 new_value = new_value ? WFLAG_KEEPALIVE : 0; 773 new_value = new_value ? WFLAG_KEEPALIVE : 0;
679 774
680 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 775 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
681 { 776 {
777 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
682 REF (w); 778 REF (w);
683 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value;
684 UNREF (w); 779 UNREF (w);
685 } 780 }
686} 781}
687 OUTPUT: 782 OUTPUT:
688 RETVAL 783 RETVAL
689 784
690SV *cb (ev_watcher *w, SV *new_cb = 0) 785SV *cb (ev_watcher *w, SV *new_cb = 0)
691 CODE: 786 CODE:
692{ 787{
693 RETVAL = newSVsv (w->cb_sv);
694
695 if (items > 1) 788 if (items > 1)
696 sv_setsv (w->cb_sv, new_cb); 789 {
790 new_cb = e_get_cv (new_cb);
791 RETVAL = newRV_noinc (w->cb_sv);
792 w->cb_sv = SvREFCNT_inc (new_cb);
793 }
794 else
795 RETVAL = newRV_inc (w->cb_sv);
697} 796}
698 OUTPUT: 797 OUTPUT:
699 RETVAL 798 RETVAL
700 799
701SV *data (ev_watcher *w, SV *new_data = 0) 800SV *data (ev_watcher *w, SV *new_data = 0)
859 958
860void ev_timer_again (ev_timer *w) 959void ev_timer_again (ev_timer *w)
861 INIT: 960 INIT:
862 CHECK_REPEAT (w->repeat); 961 CHECK_REPEAT (w->repeat);
863 CODE: 962 CODE:
864 REF (w);
865 ev_timer_again (e_loop (w), w); 963 ev_timer_again (e_loop (w), w);
866 UNREF (w); 964 UNREF (w);
867 965
868void DESTROY (ev_timer *w) 966void DESTROY (ev_timer *w)
869 CODE: 967 CODE:
874 INIT: 972 INIT:
875 CHECK_REPEAT (repeat); 973 CHECK_REPEAT (repeat);
876 CODE: 974 CODE:
877 RESET (timer, w, (w, after, repeat)); 975 RESET (timer, w, (w, after, repeat));
878 976
879NV at (ev_timer *w)
880 CODE:
881 RETVAL = w->at;
882 OUTPUT:
883 RETVAL
884
885MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 977MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
886 978
887void ev_periodic_start (ev_periodic *w) 979void ev_periodic_start (ev_periodic *w)
888 INIT: 980 INIT:
889 CHECK_REPEAT (w->interval); 981 CHECK_REPEAT (w->interval);
894 CODE: 986 CODE:
895 STOP (periodic, w); 987 STOP (periodic, w);
896 988
897void ev_periodic_again (ev_periodic *w) 989void ev_periodic_again (ev_periodic *w)
898 CODE: 990 CODE:
899 REF (w);
900 ev_periodic_again (e_loop (w), w); 991 ev_periodic_again (e_loop (w), w);
901 UNREF (w); 992 UNREF (w);
902 993
903void DESTROY (ev_periodic *w) 994void DESTROY (ev_periodic *w)
904 CODE: 995 CODE:
916 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 1007 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
917} 1008}
918 1009
919NV at (ev_periodic *w) 1010NV at (ev_periodic *w)
920 CODE: 1011 CODE:
921 RETVAL = w->at; 1012 RETVAL = ev_periodic_at (w);
922 OUTPUT: 1013 OUTPUT:
923 RETVAL 1014 RETVAL
924 1015
925MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 1016MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
926 1017
995void DESTROY (ev_child *w) 1086void DESTROY (ev_child *w)
996 CODE: 1087 CODE:
997 STOP (child, w); 1088 STOP (child, w);
998 e_destroy (w); 1089 e_destroy (w);
999 1090
1000void set (ev_child *w, int pid) 1091void set (ev_child *w, int pid, int trace)
1001 CODE: 1092 CODE:
1002 RESET (child, w, (w, pid)); 1093 RESET (child, w, (w, pid, trace));
1003 1094
1004int pid (ev_child *w, int new_pid = 0)
1005 CODE:
1006{
1007 RETVAL = w->pid;
1008
1009 if (items > 1)
1010 RESET (child, w, (w, new_pid));
1011}
1012 OUTPUT:
1013 RETVAL
1014
1015
1016int rstatus (ev_child *w) 1095int pid (ev_child *w)
1017 ALIAS: 1096 ALIAS:
1018 rpid = 1 1097 rpid = 1
1098 rstatus = 2
1019 CODE: 1099 CODE:
1020 RETVAL = ix ? w->rpid : w->rstatus; 1100 RETVAL = ix == 0 ? w->pid
1101 : ix == 1 ? w->rpid
1102 : w->rstatus;
1021 OUTPUT: 1103 OUTPUT:
1022 RETVAL 1104 RETVAL
1023 1105
1024MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1106MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1025 1107
1141 CODE: 1223 CODE:
1142 RETVAL = newSVsv (w->fh); 1224 RETVAL = newSVsv (w->fh);
1143 OUTPUT: 1225 OUTPUT:
1144 RETVAL 1226 RETVAL
1145 1227
1228void ev_embed_sweep (ev_embed *w)
1229 C_ARGS: e_loop (w), w
1230
1231MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1232
1233void ev_async_start (ev_async *w)
1234 CODE:
1235 START (async, w);
1236
1237void ev_async_stop (ev_async *w)
1238 CODE:
1239 STOP (async, w);
1240
1241void DESTROY (ev_async *w)
1242 CODE:
1243 STOP (async, w);
1244 e_destroy (w);
1245
1246void ev_async_send (ev_async *w)
1247 C_ARGS: e_loop (w), w
1248
1249SV *ev_async_async_pending (ev_async *w)
1250 CODE:
1251 RETVAL = boolSV (ev_async_pending (w));
1252 OUTPUT:
1253 RETVAL
1254
1146MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1255MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1147 1256
1148SV *new (SV *klass, unsigned int flags = 0) 1257SV *new (SV *klass, unsigned int flags = 0)
1149 CODE: 1258 CODE:
1150{ 1259{
1163 if (loop != evapi.default_loop) /* global destruction sucks */ 1272 if (loop != evapi.default_loop) /* global destruction sucks */
1164 ev_loop_destroy (loop); 1273 ev_loop_destroy (loop);
1165 1274
1166void ev_loop_fork (struct ev_loop *loop) 1275void ev_loop_fork (struct ev_loop *loop)
1167 1276
1277void ev_loop_verify (struct ev_loop *loop)
1278
1168NV ev_now (struct ev_loop *loop) 1279NV ev_now (struct ev_loop *loop)
1280
1281void ev_now_update (struct ev_loop *loop)
1282
1283void ev_suspend (struct ev_loop *loop)
1284
1285void ev_resume (struct ev_loop *loop)
1169 1286
1170void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) 1287void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1171 1288
1172void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) 1289void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1173 1290
1296 ev_fork_set (RETVAL); 1413 ev_fork_set (RETVAL);
1297 if (!ix) START (fork, RETVAL); 1414 if (!ix) START (fork, RETVAL);
1298 OUTPUT: 1415 OUTPUT:
1299 RETVAL 1416 RETVAL
1300 1417
1301ev_child *child (struct ev_loop *loop, int pid, SV *cb) 1418ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1302 ALIAS: 1419 ALIAS:
1303 child_ns = 1 1420 child_ns = 1
1304 CODE: 1421 CODE:
1305 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1422 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1306 ev_child_set (RETVAL, pid); 1423 ev_child_set (RETVAL, pid, trace);
1307 if (!ix) START (child, RETVAL); 1424 if (!ix) START (child, RETVAL);
1308 OUTPUT: 1425 OUTPUT:
1309 RETVAL 1426 RETVAL
1310 1427
1311ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1428ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1317 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 1434 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1318 if (!ix) START (stat, RETVAL); 1435 if (!ix) START (stat, RETVAL);
1319 OUTPUT: 1436 OUTPUT:
1320 RETVAL 1437 RETVAL
1321 1438
1322ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef) 1439ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1323 ALIAS: 1440 ALIAS:
1324 embed_ns = 1 1441 embed_ns = 1
1325 CODE: 1442 CODE:
1326{ 1443{
1327 if (!(ev_backend (other) & ev_embeddable_backends ())) 1444 if (!(ev_backend (other) & ev_embeddable_backends ()))
1328 croak ("passed loop is not embeddable via EV::embed,"); 1445 croak ("passed loop is not embeddable via EV::embed,");
1329 1446
1330 RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); 1447 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1331 RETVAL->fh = newSVsv (ST (1)); 1448 RETVAL->fh = newSVsv (ST (1));
1332 ev_embed_set (RETVAL, other); 1449 ev_embed_set (RETVAL, other);
1333
1334 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1335
1336 if (!ix) START (embed, RETVAL); 1450 if (!ix) START (embed, RETVAL);
1337} 1451}
1452 OUTPUT:
1453 RETVAL
1454
1455ev_async *async (struct ev_loop *loop, SV *cb)
1456 ALIAS:
1457 async_ns = 1
1458 CODE:
1459 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1460 ev_async_set (RETVAL);
1461 if (!ix) START (async, RETVAL);
1338 OUTPUT: 1462 OUTPUT:
1339 RETVAL 1463 RETVAL
1340 1464
1341void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) 1465void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1342 CODE: 1466 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines