ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.172
Committed: Sat Sep 17 02:28:30 2016 UTC (7 years, 7 months ago) by root
Branch: MAIN
CVS Tags: EV-rel-4_26, EV-rel-4_25
Changes since 1.171: +3 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5 root 1.108 /* fix perl api breakage */
6 root 1.167 #ifndef WIN32
7     # undef signal
8     # undef sigaction
9     #endif
10 root 1.108
11 root 1.126 #include "schmorp.h"
12    
13 root 1.127 /* old API compatibility */
14     static int
15     sv_fileno (SV *fh)
16     {
17     return s_fileno (fh, 0);
18     }
19    
20 root 1.163 #ifndef GvCV_set
21     # define GvCV_set(gv,cv) GvCV (gv) = cv
22     #endif
23    
24 root 1.136 #define EV_STANDALONE 1
25 root 1.20 #define EV_PROTOTYPES 1
26 root 1.101 #define EV_USE_NANOSLEEP EV_USE_MONOTONIC
27 root 1.155 #define EV_USE_FLOOR 1
28 root 1.158 #define EV_API_STATIC
29 root 1.92 #define EV_H <ev.h>
30 root 1.136 #define EV_CONFIG_H error
31 root 1.11 #include "EV/EVAPI.h"
32    
33 root 1.64 #define EV_SELECT_IS_WINSOCKET 0
34     #ifdef _WIN32
35     # define EV_SELECT_USE_FD_SET 0
36     # define NFDBITS PERL_NFDBITS
37     # define fd_mask Perl_fd_mask
38     #endif
39 root 1.53 /* due to bugs in OS X we have to use libev/ explicitly here */
40     #include "libev/ev.c"
41 root 1.56
42 root 1.169 #if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK
43 root 1.55 # include <pthread.h>
44     #endif
45    
46 root 1.138 #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop))
47     #define e_flags(w) ((ev_watcher *)(w))->e_flags
48     #define e_self(w) ((ev_watcher *)(w))->self
49     #define e_fh(w) ((ev_watcher *)(w))->fh
50     #define e_data(w) ((ev_watcher *)(w))->data
51 root 1.93
52 root 1.78 #define WFLAG_KEEPALIVE 1
53 root 1.121 #define WFLAG_UNREFED 2 /* has been unref'ed */
54 root 1.78
55     #define UNREF(w) \
56 root 1.138 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
57 root 1.121 && ev_is_active (w)) \
58     { \
59     ev_unref (e_loop (w)); \
60 root 1.138 e_flags (w) |= WFLAG_UNREFED; \
61 root 1.121 }
62 root 1.78
63     #define REF(w) \
64 root 1.138 if (e_flags (w) & WFLAG_UNREFED) \
65 root 1.121 { \
66 root 1.138 e_flags (w) &= ~WFLAG_UNREFED; \
67 root 1.121 ev_ref (e_loop (w)); \
68     }
69 root 1.78
70     #define START(type,w) \
71     do { \
72 root 1.121 ev_ ## type ## _start (e_loop (w), w); \
73 root 1.78 UNREF (w); \
74     } while (0)
75    
76     #define STOP(type,w) \
77     do { \
78     REF (w); \
79 root 1.103 ev_ ## type ## _stop (e_loop (w), w); \
80 root 1.78 } while (0)
81    
82 root 1.80 #define RESET(type,w,seta) \
83 root 1.132 do { \
84     int active = ev_is_active (w); \
85     if (active) STOP (type, w); \
86     ev_ ## type ## _set seta; \
87     if (active) START (type, w); \
88     } while (0)
89 root 1.80
90 root 1.10 typedef int Signal;
91 root 1.1
92 root 1.132 /* horrible... */
93     #define CHECK_SIGNAL_CAN_START(w) \
94     do { \
95     /* dive into the internals of libev to avoid aborting in libev */ \
96     if (signals [(w)->signum - 1].loop \
97     && signals [(w)->signum - 1].loop != e_loop (w)) \
98     croak ("unable to start signal watcher, signal %d already registered in another loop", w->signum); \
99     } while (0)
100    
101     #define START_SIGNAL(w) \
102     do { \
103     CHECK_SIGNAL_CAN_START (w); \
104     START (signal, w); \
105     } while (0) \
106    
107     #define RESET_SIGNAL(w,seta) \
108     do { \
109     int active = ev_is_active (w); \
110     if (active) STOP (signal, w); \
111     ev_ ## signal ## _set seta; \
112     if (active) START_SIGNAL (w); \
113     } while (0)
114    
115 root 1.93 static SV *default_loop_sv;
116    
117 root 1.11 static struct EVAPI evapi;
118    
119 root 1.15 static HV
120 root 1.93 *stash_loop,
121 root 1.15 *stash_watcher,
122     *stash_io,
123     *stash_timer,
124     *stash_periodic,
125     *stash_signal,
126 root 1.81 *stash_child,
127     *stash_stat,
128 root 1.15 *stash_idle,
129 root 1.22 *stash_prepare,
130 root 1.23 *stash_check,
131 root 1.80 *stash_embed,
132 root 1.106 *stash_fork,
133 root 1.145 *stash_cleanup,
134 root 1.106 *stash_async;
135 root 1.1
136     /////////////////////////////////////////////////////////////////////////////
137     // Event
138    
139 root 1.91 static void e_cb (EV_P_ ev_watcher *w, int revents);
140 root 1.1
141 root 1.156 static void *
142 root 1.93 e_new (int size, SV *cb_sv, SV *loop)
143 root 1.1 {
144 root 1.126 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0;
145 root 1.78 ev_watcher *w;
146 root 1.15 SV *self = NEWSV (0, size);
147 root 1.1 SvPOK_only (self);
148 root 1.15 SvCUR_set (self, size);
149 root 1.1
150 root 1.78 w = (ev_watcher *)SvPVX (self);
151 root 1.1
152 root 1.114 ev_init (w, cv ? e_cb : 0);
153 root 1.1
154 root 1.104 w->loop = SvREFCNT_inc (SvRV (loop));
155     w->e_flags = WFLAG_KEEPALIVE;
156     w->data = 0;
157     w->fh = 0;
158 root 1.112 w->cb_sv = SvREFCNT_inc (cv);
159 root 1.104 w->self = self;
160 root 1.1
161 root 1.15 return (void *)w;
162 root 1.1 }
163    
164 root 1.56 static void
165 root 1.34 e_destroy (void *w_)
166     {
167 root 1.78 ev_watcher *w = (ev_watcher *)w_;
168 root 1.34
169 root 1.93 SvREFCNT_dec (w->loop ); w->loop = 0;
170 root 1.34 SvREFCNT_dec (w->fh ); w->fh = 0;
171     SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
172 root 1.60 SvREFCNT_dec (w->data ); w->data = 0;
173 root 1.34 }
174    
175 root 1.15 static SV *
176 root 1.78 e_bless (ev_watcher *w, HV *stash)
177 root 1.1 {
178     SV *rv;
179    
180 root 1.15 if (SvOBJECT (w->self))
181     rv = newRV_inc (w->self);
182 root 1.1 else
183     {
184 root 1.15 rv = newRV_noinc (w->self);
185     sv_bless (rv, stash);
186     SvREADONLY_on (w->self);
187 root 1.1 }
188    
189     return rv;
190     }
191    
192 root 1.116 static SV *sv_self_cache, *sv_events_cache;
193 root 1.75
194 root 1.1 static void
195 root 1.91 e_cb (EV_P_ ev_watcher *w, int revents)
196 root 1.1 {
197     dSP;
198 root 1.14 I32 mark = SP - PL_stack_base;
199 root 1.75 SV *sv_self, *sv_events;
200 root 1.1
201 root 1.121 /* libev might have stopped the watcher */
202     if (expect_false (w->e_flags & WFLAG_UNREFED)
203     && !ev_is_active (w))
204     REF (w);
205    
206 root 1.166 if (expect_true (sv_self_cache))
207     {
208     sv_self = sv_self_cache; sv_self_cache = 0;
209     SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
210     }
211     else
212     {
213     sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */
214     SvREADONLY_on (sv_self);
215     }
216 root 1.164
217 root 1.166 if (expect_true (sv_events_cache))
218     {
219     sv_events = sv_events_cache; sv_events_cache = 0;
220     SvIV_set (sv_events, revents);
221     SvIOK_only (sv_events);
222     }
223     else
224 root 1.116 {
225 root 1.166 sv_events = newSViv (revents);
226     SvREADONLY_on (sv_events);
227     }
228    
229     PUSHMARK (SP);
230     EXTEND (SP, 2);
231     PUSHs (sv_self);
232     PUSHs (sv_events);
233 root 1.164
234 root 1.166 PUTBACK;
235     call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
236 root 1.14
237 root 1.166 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
238     SvREFCNT_dec (sv_self);
239 root 1.14 else
240 root 1.116 {
241 root 1.166 SvREFCNT_dec (SvRV (sv_self));
242     SvRV_set (sv_self, &PL_sv_undef);
243     sv_self_cache = sv_self;
244 root 1.116 }
245 root 1.75
246 root 1.166 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
247     SvREFCNT_dec (sv_events);
248     else
249     sv_events_cache = sv_events;
250    
251 root 1.119 if (expect_false (SvTRUE (ERRSV)))
252 root 1.75 {
253 root 1.84 SPAGAIN;
254 root 1.75 PUSHMARK (SP);
255     PUTBACK;
256     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
257     }
258    
259     SP = PL_stack_base + mark;
260     PUTBACK;
261     }
262    
263     static void
264     e_once_cb (int revents, void *arg)
265     {
266     dSP;
267     I32 mark = SP - PL_stack_base;
268     SV *sv_events;
269    
270     if (sv_events_cache)
271     {
272     sv_events = sv_events_cache; sv_events_cache = 0;
273     SvIV_set (sv_events, revents);
274     }
275     else
276     sv_events = newSViv (revents);
277    
278     PUSHMARK (SP);
279     XPUSHs (sv_events);
280    
281     PUTBACK;
282     call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
283    
284     SvREFCNT_dec ((SV *)arg);
285 root 1.14
286     if (sv_events_cache)
287     SvREFCNT_dec (sv_events);
288     else
289     sv_events_cache = sv_events;
290 root 1.1
291 root 1.8 if (SvTRUE (ERRSV))
292     {
293 root 1.86 SPAGAIN;
294 root 1.8 PUSHMARK (SP);
295     PUTBACK;
296     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
297     }
298 root 1.68
299     SP = PL_stack_base + mark;
300     PUTBACK;
301 root 1.1 }
302    
303 root 1.59 static ev_tstamp
304 root 1.78 e_periodic_cb (ev_periodic *w, ev_tstamp now)
305 root 1.59 {
306     ev_tstamp retval;
307     int count;
308     dSP;
309    
310     ENTER;
311     SAVETMPS;
312    
313     PUSHMARK (SP);
314     EXTEND (SP, 2);
315 root 1.138 PUSHs (newRV_inc (e_self (w))); /* e_self (w) MUST be blessed by now */
316 root 1.59 PUSHs (newSVnv (now));
317    
318     PUTBACK;
319     count = call_sv (w->fh, G_SCALAR | G_EVAL);
320     SPAGAIN;
321    
322     if (SvTRUE (ERRSV))
323     {
324     PUSHMARK (SP);
325     PUTBACK;
326     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
327     SPAGAIN;
328     }
329    
330     if (count > 0)
331     {
332     retval = SvNV (TOPs);
333    
334     if (retval < now)
335     retval = now;
336     }
337     else
338     retval = now;
339    
340     FREETMPS;
341     LEAVE;
342    
343     return retval;
344     }
345    
346 root 1.18 #define CHECK_REPEAT(repeat) if (repeat < 0.) \
347     croak (# repeat " value must be >= 0");
348    
349 root 1.31 #define CHECK_FD(fh,fd) if ((fd) < 0) \
350     croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
351    
352 root 1.80 #define CHECK_SIG(sv,num) if ((num) < 0) \
353     croak ("illegal signal number or name: %s", SvPV_nolen (sv));
354    
355 root 1.148 static void
356     default_fork (void)
357 root 1.147 {
358     ev_loop_fork (EV_DEFAULT_UC);
359     }
360    
361 root 1.1 /////////////////////////////////////////////////////////////////////////////
362     // XS interface functions
363    
364 root 1.15 MODULE = EV PACKAGE = EV PREFIX = ev_
365 root 1.1
366 root 1.21 PROTOTYPES: ENABLE
367    
368 root 1.1 BOOT:
369     {
370     HV *stash = gv_stashpv ("EV", 1);
371    
372     static const struct {
373     const char *name;
374     IV iv;
375     } *civ, const_iv[] = {
376     # define const_iv(pfx, name) { # name, (IV) pfx ## name },
377 root 1.41 const_iv (EV_, MINPRI)
378     const_iv (EV_, MAXPRI)
379    
380 root 1.20 const_iv (EV_, UNDEF)
381 root 1.1 const_iv (EV_, NONE)
382     const_iv (EV_, READ)
383     const_iv (EV_, WRITE)
384 root 1.123 const_iv (EV_, IO)
385 root 1.147 const_iv (EV_, TIMER)
386 root 1.123 const_iv (EV_, PERIODIC)
387 root 1.1 const_iv (EV_, SIGNAL)
388 root 1.123 const_iv (EV_, CHILD)
389     const_iv (EV_, STAT)
390 root 1.15 const_iv (EV_, IDLE)
391 root 1.123 const_iv (EV_, PREPARE)
392 root 1.163 /*const_iv (EV_, CHECK) needs special tretament */
393 root 1.123 const_iv (EV_, EMBED)
394     const_iv (EV_, FORK)
395 root 1.145 const_iv (EV_, CLEANUP)
396 root 1.123 const_iv (EV_, ASYNC)
397     const_iv (EV_, CUSTOM)
398 root 1.20 const_iv (EV_, ERROR)
399 root 1.15
400 root 1.142 const_iv (EV, RUN_NOWAIT)
401     const_iv (EV, RUN_ONCE)
402 root 1.15
403 root 1.142 const_iv (EV, BREAK_CANCEL)
404     const_iv (EV, BREAK_ONE)
405     const_iv (EV, BREAK_ALL)
406 root 1.73 const_iv (EV, BACKEND_SELECT)
407     const_iv (EV, BACKEND_POLL)
408     const_iv (EV, BACKEND_EPOLL)
409     const_iv (EV, BACKEND_KQUEUE)
410     const_iv (EV, BACKEND_DEVPOLL)
411     const_iv (EV, BACKEND_PORT)
412 root 1.134 const_iv (EV, BACKEND_ALL)
413 root 1.153 const_iv (EV, BACKEND_MASK)
414 root 1.66 const_iv (EV, FLAG_AUTO)
415 root 1.134 const_iv (EV, FLAG_FORKCHECK)
416 root 1.135 const_iv (EV, FLAG_SIGNALFD)
417 root 1.153 const_iv (EV, FLAG_NOSIGMASK)
418 root 1.66 const_iv (EV, FLAG_NOENV)
419 root 1.134 const_iv (EV, FLAG_NOINOTIFY)
420 root 1.123
421     const_iv (EV_, VERSION_MAJOR)
422     const_iv (EV_, VERSION_MINOR)
423 root 1.142 #if EV_COMPAT3
424 root 1.147 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
425     const_iv (EV_, TIMEOUT)
426 root 1.142 const_iv (EV, LOOP_NONBLOCK)
427     const_iv (EV, LOOP_ONESHOT)
428     const_iv (EV, UNLOOP_CANCEL)
429     const_iv (EV, UNLOOP_ONE)
430     const_iv (EV, UNLOOP_ALL)
431     #endif
432 root 1.1 };
433    
434 root 1.157 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
435     newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
436 root 1.1
437 root 1.163 /* since this clashes with perl CHECK blocks, */
438     /* but we are interested in constants, */
439     /* and not blocks, we treat CHECK specially. */
440     {
441     /* the local $^W = 0 takes care of the warning */
442     CV *cv = newCONSTSUB (stash, "CHECK", newSViv (EV_CHECK));
443     /* now we need to re-set the gv, in case it was hijacked */
444     GvCV_set (gv_fetchpv ("EV::CHECK", GV_ADD, SVt_PVCV), cv);
445     }
446    
447 root 1.93 stash_loop = gv_stashpv ("EV::Loop" , 1);
448 root 1.15 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
449 root 1.78 stash_io = gv_stashpv ("EV::IO" , 1);
450 root 1.15 stash_timer = gv_stashpv ("EV::Timer" , 1);
451     stash_periodic = gv_stashpv ("EV::Periodic", 1);
452     stash_signal = gv_stashpv ("EV::Signal" , 1);
453     stash_idle = gv_stashpv ("EV::Idle" , 1);
454 root 1.22 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
455 root 1.15 stash_check = gv_stashpv ("EV::Check" , 1);
456 root 1.23 stash_child = gv_stashpv ("EV::Child" , 1);
457 root 1.80 stash_embed = gv_stashpv ("EV::Embed" , 1);
458     stash_stat = gv_stashpv ("EV::Stat" , 1);
459 root 1.91 stash_fork = gv_stashpv ("EV::Fork" , 1);
460 root 1.145 stash_cleanup = gv_stashpv ("EV::Cleanup" , 1);
461 root 1.106 stash_async = gv_stashpv ("EV::Async" , 1);
462 root 1.11
463     {
464     SV *sv = perl_get_sv ("EV::API", TRUE);
465     perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
466    
467 root 1.15 /* the poor man's shared library emulator */
468 root 1.91 evapi.ver = EV_API_VERSION;
469     evapi.rev = EV_API_REVISION;
470 root 1.127 evapi.sv_fileno = sv_fileno;
471 root 1.126 evapi.sv_signum = s_signum;
472 root 1.91 evapi.supported_backends = ev_supported_backends ();
473     evapi.recommended_backends = ev_recommended_backends ();
474     evapi.embeddable_backends = ev_embeddable_backends ();
475 root 1.109 evapi.time_ = ev_time;
476     evapi.sleep_ = ev_sleep;
477 root 1.91 evapi.loop_new = ev_loop_new;
478     evapi.loop_destroy = ev_loop_destroy;
479     evapi.loop_fork = ev_loop_fork;
480 root 1.137 evapi.iteration = ev_iteration;
481     evapi.depth = ev_depth;
482 root 1.126 evapi.set_userdata = ev_set_userdata;
483     evapi.userdata = ev_userdata;
484 root 1.91 evapi.now = ev_now;
485 root 1.115 evapi.now_update = ev_now_update;
486 root 1.122 evapi.suspend = ev_suspend;
487     evapi.resume = ev_resume;
488 root 1.91 evapi.backend = ev_backend;
489 root 1.142 evapi.break_ = ev_break;
490 root 1.126 evapi.invoke_pending = ev_invoke_pending;
491 root 1.128 evapi.pending_count = ev_pending_count;
492 root 1.137 evapi.verify = ev_verify;
493 root 1.126 evapi.set_loop_release_cb = ev_set_loop_release_cb;
494     evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
495 root 1.91 evapi.ref = ev_ref;
496     evapi.unref = ev_unref;
497 root 1.142 evapi.run = ev_run;
498 root 1.91 evapi.once = ev_once;
499     evapi.io_start = ev_io_start;
500     evapi.io_stop = ev_io_stop;
501     evapi.timer_start = ev_timer_start;
502     evapi.timer_stop = ev_timer_stop;
503     evapi.timer_again = ev_timer_again;
504 root 1.130 evapi.timer_remaining = ev_timer_remaining;
505 root 1.91 evapi.periodic_start = ev_periodic_start;
506     evapi.periodic_stop = ev_periodic_stop;
507     evapi.signal_start = ev_signal_start;
508     evapi.signal_stop = ev_signal_stop;
509     evapi.idle_start = ev_idle_start;
510     evapi.idle_stop = ev_idle_stop;
511     evapi.prepare_start = ev_prepare_start;
512     evapi.prepare_stop = ev_prepare_stop;
513     evapi.check_start = ev_check_start;
514     evapi.check_stop = ev_check_stop;
515 root 1.139 #if EV_CHILD_ENABLE
516 root 1.91 evapi.child_start = ev_child_start;
517     evapi.child_stop = ev_child_stop;
518 root 1.139 #endif
519 root 1.91 evapi.stat_start = ev_stat_start;
520     evapi.stat_stop = ev_stat_stop;
521     evapi.stat_stat = ev_stat_stat;
522     evapi.embed_start = ev_embed_start;
523     evapi.embed_stop = ev_embed_stop;
524     evapi.embed_sweep = ev_embed_sweep;
525     evapi.fork_start = ev_fork_start;
526     evapi.fork_stop = ev_fork_stop;
527 root 1.145 evapi.cleanup_start = ev_cleanup_start;
528     evapi.cleanup_stop = ev_cleanup_stop;
529 root 1.105 evapi.async_start = ev_async_start;
530     evapi.async_stop = ev_async_stop;
531     evapi.async_send = ev_async_send;
532 root 1.91 evapi.clear_pending = ev_clear_pending;
533     evapi.invoke = ev_invoke;
534 root 1.11
535     sv_setiv (sv, (IV)&evapi);
536     SvREADONLY_on (sv);
537     }
538 root 1.168 #if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK
539 root 1.172 /* unfortunately, musl neither implements the linux standard base,
540     /* nor makes itself detectable via macros. yeah, right... */
541     #if __linux && (__GLIBC__ || __UCLIBC__)
542 root 1.162 int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
543     __register_atfork (0, 0, default_fork, 0);
544     #else
545 root 1.147 pthread_atfork (0, 0, default_fork);
546 root 1.56 #endif
547 root 1.162 #endif
548 root 1.1 }
549    
550 root 1.97 SV *ev_default_loop (unsigned int flags = 0)
551 root 1.91 CODE:
552     {
553 root 1.93 if (!default_loop_sv)
554     {
555     evapi.default_loop = ev_default_loop (flags);
556    
557     if (!evapi.default_loop)
558     XSRETURN_UNDEF;
559    
560     default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
561     }
562 root 1.1
563 root 1.93 RETVAL = newSVsv (default_loop_sv);
564 root 1.91 }
565     OUTPUT:
566     RETVAL
567 root 1.1
568 root 1.102 void ev_default_destroy ()
569     CODE:
570 root 1.144 ev_loop_destroy (EV_DEFAULT_UC);
571 root 1.102 SvREFCNT_dec (default_loop_sv);
572     default_loop_sv = 0;
573    
574     unsigned int ev_supported_backends ()
575    
576     unsigned int ev_recommended_backends ()
577    
578     unsigned int ev_embeddable_backends ()
579    
580 root 1.117 void ev_sleep (NV interval)
581    
582 root 1.15 NV ev_time ()
583 root 1.1
584 root 1.154 void ev_feed_signal (SV *signal)
585     CODE:
586     {
587 root 1.170 Signal signum = s_signum (signal);
588 root 1.154 CHECK_SIG (signal, signum);
589    
590     ev_feed_signal (signum);
591     }
592    
593 root 1.91 NV ev_now ()
594     C_ARGS: evapi.default_loop
595    
596 root 1.115 void ev_now_update ()
597     C_ARGS: evapi.default_loop
598    
599 root 1.122 void ev_suspend ()
600     C_ARGS: evapi.default_loop
601    
602     void ev_resume ()
603     C_ARGS: evapi.default_loop
604    
605 root 1.91 unsigned int ev_backend ()
606     C_ARGS: evapi.default_loop
607 root 1.1
608 root 1.137 void ev_verify ()
609 root 1.142 ALIAS:
610     loop_verify = 1
611 root 1.125 C_ARGS: evapi.default_loop
612    
613 root 1.137 unsigned int ev_iteration ()
614 root 1.142 ALIAS:
615     loop_count = 1
616 root 1.91 C_ARGS: evapi.default_loop
617 root 1.86
618 root 1.137 unsigned int ev_depth ()
619 root 1.142 ALIAS:
620     loop_depth = 1
621 root 1.125 C_ARGS: evapi.default_loop
622    
623 root 1.101 void ev_set_io_collect_interval (NV interval)
624     C_ARGS: evapi.default_loop, interval
625    
626     void ev_set_timeout_collect_interval (NV interval)
627     C_ARGS: evapi.default_loop, interval
628    
629 root 1.162 int ev_run (int flags = 0)
630 root 1.142 ALIAS:
631     loop = 1
632 root 1.91 C_ARGS: evapi.default_loop, flags
633 root 1.1
634 root 1.142 void ev_break (int how = EVBREAK_ONE)
635     ALIAS:
636     unloop = 1
637 root 1.91 C_ARGS: evapi.default_loop, how
638 root 1.1
639 root 1.89 void ev_feed_fd_event (int fd, int revents = EV_NONE)
640 root 1.91 C_ARGS: evapi.default_loop, fd, revents
641 root 1.89
642     void ev_feed_signal_event (SV *signal)
643     CODE:
644     {
645 root 1.162 Signal signum = s_signum (signal);
646 root 1.89 CHECK_SIG (signal, signum);
647    
648 root 1.91 ev_feed_signal_event (evapi.default_loop, signum);
649 root 1.89 }
650    
651 root 1.129 unsigned int ev_pending_count ()
652     C_ARGS: evapi.default_loop
653    
654     void ev_invoke_pending ()
655     C_ARGS: evapi.default_loop
656    
657 root 1.78 ev_io *io (SV *fh, int events, SV *cb)
658 root 1.15 ALIAS:
659     io_ns = 1
660 root 1.133 _ae_io = 2
661 root 1.1 CODE:
662 root 1.31 {
663 root 1.126 int fd = s_fileno (fh, events & EV_WRITE);
664 root 1.31 CHECK_FD (fh, fd);
665    
666 root 1.133 if (ix == 2)
667     {
668 root 1.166 ix = 0;
669 root 1.133 events = events ? EV_WRITE : EV_READ;
670     }
671    
672 root 1.166 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
673     e_fh (RETVAL) = newSVsv (fh);
674 root 1.31 ev_io_set (RETVAL, fd, events);
675 root 1.166 if (!ix) START (io, RETVAL);
676 root 1.31 }
677 root 1.1 OUTPUT:
678     RETVAL
679    
680 root 1.78 ev_timer *timer (NV after, NV repeat, SV *cb)
681 root 1.1 ALIAS:
682 root 1.15 timer_ns = 1
683 root 1.18 INIT:
684     CHECK_REPEAT (repeat);
685 root 1.1 CODE:
686 root 1.93 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
687 root 1.29 ev_timer_set (RETVAL, after, repeat);
688 root 1.78 if (!ix) START (timer, RETVAL);
689 root 1.1 OUTPUT:
690     RETVAL
691    
692 root 1.59 SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
693 root 1.9 ALIAS:
694 root 1.15 periodic_ns = 1
695 root 1.18 INIT:
696     CHECK_REPEAT (interval);
697 root 1.9 CODE:
698 root 1.59 {
699 root 1.170 ev_periodic *w;
700 root 1.93 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
701 root 1.138 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
702     ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
703 root 1.78 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
704     if (!ix) START (periodic, w);
705 root 1.59 }
706 root 1.9 OUTPUT:
707     RETVAL
708    
709 root 1.80 ev_signal *signal (SV *signal, SV *cb)
710 root 1.1 ALIAS:
711 root 1.15 signal_ns = 1
712 root 1.1 CODE:
713 root 1.80 {
714 root 1.170 Signal signum = s_signum (signal);
715 root 1.80 CHECK_SIG (signal, signum);
716    
717 root 1.93 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
718 root 1.29 ev_signal_set (RETVAL, signum);
719 root 1.132 if (!ix) START_SIGNAL (RETVAL);
720 root 1.80 }
721 root 1.1 OUTPUT:
722     RETVAL
723    
724 root 1.78 ev_idle *idle (SV *cb)
725 root 1.1 ALIAS:
726 root 1.15 idle_ns = 1
727 root 1.1 CODE:
728 root 1.93 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
729 root 1.29 ev_idle_set (RETVAL);
730 root 1.78 if (!ix) START (idle, RETVAL);
731 root 1.1 OUTPUT:
732     RETVAL
733    
734 root 1.78 ev_prepare *prepare (SV *cb)
735 root 1.22 ALIAS:
736     prepare_ns = 1
737     CODE:
738 root 1.93 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
739 root 1.29 ev_prepare_set (RETVAL);
740 root 1.78 if (!ix) START (prepare, RETVAL);
741 root 1.22 OUTPUT:
742     RETVAL
743    
744 root 1.78 ev_check *check (SV *cb)
745 root 1.1 ALIAS:
746 root 1.15 check_ns = 1
747 root 1.1 CODE:
748 root 1.93 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
749 root 1.29 ev_check_set (RETVAL);
750 root 1.78 if (!ix) START (check, RETVAL);
751 root 1.1 OUTPUT:
752     RETVAL
753    
754 root 1.91 ev_fork *fork (SV *cb)
755     ALIAS:
756     fork_ns = 1
757     CODE:
758 root 1.93 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
759 root 1.91 ev_fork_set (RETVAL);
760     if (!ix) START (fork, RETVAL);
761     OUTPUT:
762     RETVAL
763    
764 root 1.160 #if CLEANUP_ENABLED
765    
766 root 1.145 ev_cleanup *cleanup (SV *cb)
767     ALIAS:
768     cleanup_ns = 1
769     CODE:
770     RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
771 root 1.160 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
772 root 1.145 ev_cleanup_set (RETVAL);
773     if (!ix) START (cleanup, RETVAL);
774     OUTPUT:
775     RETVAL
776 root 1.139
777 root 1.160 #endif
778    
779 root 1.104 ev_child *child (int pid, int trace, SV *cb)
780 root 1.23 ALIAS:
781 root 1.69 child_ns = 1
782 root 1.23 CODE:
783 root 1.140 #if EV_CHILD_ENABLE
784 root 1.93 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
785 root 1.104 ev_child_set (RETVAL, pid, trace);
786 root 1.78 if (!ix) START (child, RETVAL);
787 root 1.140 #else
788     croak ("EV::child watchers not supported on this platform");
789     #endif
790 root 1.23 OUTPUT:
791     RETVAL
792    
793 root 1.139
794 root 1.80 ev_stat *stat (SV *path, NV interval, SV *cb)
795     ALIAS:
796     stat_ns = 1
797     CODE:
798 root 1.93 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
799 root 1.138 e_fh (RETVAL) = newSVsv (path);
800     ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
801 root 1.80 if (!ix) START (stat, RETVAL);
802     OUTPUT:
803     RETVAL
804    
805 root 1.150 #ifndef EV_NO_LOOPS
806    
807 root 1.114 ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
808 root 1.93 ALIAS:
809     embed_ns = 1
810     CODE:
811 root 1.95 {
812     if (!(ev_backend (loop) & ev_embeddable_backends ()))
813     croak ("passed loop is not embeddable via EV::embed,");
814    
815 root 1.93 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
816 root 1.138 e_fh (RETVAL) = newSVsv (ST (0));
817 root 1.93 ev_embed_set (RETVAL, loop);
818     if (!ix) START (embed, RETVAL);
819 root 1.95 }
820 root 1.93 OUTPUT:
821     RETVAL
822    
823 root 1.150 #endif
824    
825 root 1.106 ev_async *async (SV *cb)
826     ALIAS:
827     async_ns = 1
828     CODE:
829     RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
830     ev_async_set (RETVAL);
831     if (!ix) START (async, RETVAL);
832     OUTPUT:
833     RETVAL
834    
835 root 1.76 void once (SV *fh, int events, SV *timeout, SV *cb)
836 root 1.75 CODE:
837 root 1.76 ev_once (
838 root 1.91 evapi.default_loop,
839 root 1.126 s_fileno (fh, events & EV_WRITE), events,
840 root 1.76 SvOK (timeout) ? SvNV (timeout) : -1.,
841     e_once_cb,
842     newSVsv (cb)
843     );
844 root 1.15
845 root 1.1 PROTOTYPES: DISABLE
846    
847 root 1.15 MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
848 root 1.1
849 root 1.78 int ev_is_active (ev_watcher *w)
850 root 1.1
851 root 1.78 int ev_is_pending (ev_watcher *w)
852    
853 root 1.89 void ev_invoke (ev_watcher *w, int revents = EV_NONE)
854 root 1.93 C_ARGS: e_loop (w), w, revents
855 root 1.89
856     int ev_clear_pending (ev_watcher *w)
857 root 1.93 C_ARGS: e_loop (w), w
858 root 1.89
859     void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
860 root 1.93 C_ARGS: e_loop (w), w, revents
861 root 1.89
862 root 1.78 int keepalive (ev_watcher *w, int new_value = 0)
863     CODE:
864     {
865 root 1.104 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
866 root 1.78 new_value = new_value ? WFLAG_KEEPALIVE : 0;
867    
868 root 1.104 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
869 root 1.78 {
870 root 1.121 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
871 root 1.78 REF (w);
872     UNREF (w);
873     }
874     }
875     OUTPUT:
876     RETVAL
877    
878     SV *cb (ev_watcher *w, SV *new_cb = 0)
879 root 1.1 CODE:
880 root 1.15 {
881     if (items > 1)
882 root 1.112 {
883 root 1.126 new_cb = s_get_cv_croak (new_cb);
884 root 1.112 RETVAL = newRV_noinc (w->cb_sv);
885     w->cb_sv = SvREFCNT_inc (new_cb);
886     }
887     else
888     RETVAL = newRV_inc (w->cb_sv);
889 root 1.15 }
890 root 1.1 OUTPUT:
891     RETVAL
892    
893 root 1.78 SV *data (ev_watcher *w, SV *new_data = 0)
894 root 1.60 CODE:
895     {
896     RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
897 root 1.79
898     if (items > 1)
899     {
900     SvREFCNT_dec (w->data);
901     w->data = newSVsv (new_data);
902     }
903 root 1.60 }
904     OUTPUT:
905     RETVAL
906    
907 root 1.99 SV *loop (ev_watcher *w)
908     CODE:
909     RETVAL = newRV_inc (w->loop);
910     OUTPUT:
911     RETVAL
912    
913 root 1.78 int priority (ev_watcher *w, int new_priority = 0)
914 root 1.41 CODE:
915     {
916     RETVAL = w->priority;
917    
918     if (items > 1)
919     {
920     int active = ev_is_active (w);
921    
922     if (active)
923     {
924     /* grrr. */
925     PUSHMARK (SP);
926     XPUSHs (ST (0));
927 root 1.87 PUTBACK;
928 root 1.41 call_method ("stop", G_DISCARD | G_VOID);
929     }
930    
931     ev_set_priority (w, new_priority);
932    
933     if (active)
934     {
935     PUSHMARK (SP);
936     XPUSHs (ST (0));
937 root 1.87 PUTBACK;
938 root 1.41 call_method ("start", G_DISCARD | G_VOID);
939     }
940     }
941     }
942     OUTPUT:
943     RETVAL
944    
945 root 1.78 MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_
946 root 1.1
947 root 1.78 void ev_io_start (ev_io *w)
948     CODE:
949     START (io, w);
950 root 1.1
951 root 1.78 void ev_io_stop (ev_io *w)
952     CODE:
953     STOP (io, w);
954 root 1.15
955 root 1.78 void DESTROY (ev_io *w)
956 root 1.26 CODE:
957 root 1.78 STOP (io, w);
958 root 1.34 e_destroy (w);
959 root 1.26
960 root 1.78 void set (ev_io *w, SV *fh, int events)
961 root 1.1 CODE:
962     {
963 root 1.126 int fd = s_fileno (fh, events & EV_WRITE);
964 root 1.31 CHECK_FD (fh, fd);
965    
966 root 1.138 sv_setsv (e_fh (w), fh);
967 root 1.80 RESET (io, w, (w, fd, events));
968 root 1.15 }
969 root 1.1
970 root 1.78 SV *fh (ev_io *w, SV *new_fh = 0)
971 root 1.1 CODE:
972 root 1.15 {
973     if (items > 1)
974     {
975 root 1.126 int fd = s_fileno (new_fh, w->events & EV_WRITE);
976 root 1.80 CHECK_FD (new_fh, fd);
977 root 1.1
978 root 1.138 RETVAL = e_fh (w);
979     e_fh (w) = newSVsv (new_fh);
980 root 1.1
981 root 1.80 RESET (io, w, (w, fd, w->events));
982 root 1.15 }
983 root 1.80 else
984 root 1.138 RETVAL = newSVsv (e_fh (w));
985 root 1.15 }
986 root 1.1 OUTPUT:
987     RETVAL
988    
989 root 1.78 int events (ev_io *w, int new_events = EV_UNDEF)
990 root 1.1 CODE:
991 root 1.15 {
992     RETVAL = w->events;
993    
994     if (items > 1)
995 root 1.80 RESET (io, w, (w, w->fd, new_events));
996 root 1.15 }
997 root 1.1 OUTPUT:
998     RETVAL
999    
1000 root 1.29 MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
1001 root 1.15
1002 root 1.78 void ev_signal_start (ev_signal *w)
1003     CODE:
1004 root 1.132 START_SIGNAL (w);
1005 root 1.15
1006 root 1.78 void ev_signal_stop (ev_signal *w)
1007     CODE:
1008     STOP (signal, w);
1009 root 1.15
1010 root 1.78 void DESTROY (ev_signal *w)
1011 root 1.26 CODE:
1012 root 1.78 STOP (signal, w);
1013 root 1.34 e_destroy (w);
1014 root 1.26
1015 root 1.78 void set (ev_signal *w, SV *signal)
1016 root 1.1 CODE:
1017 root 1.15 {
1018 root 1.126 Signal signum = s_signum (signal);
1019 root 1.80 CHECK_SIG (signal, signum);
1020 root 1.39
1021 root 1.132 RESET_SIGNAL (w, (w, signum));
1022 root 1.15 }
1023    
1024 root 1.78 int signal (ev_signal *w, SV *new_signal = 0)
1025 root 1.39 CODE:
1026     {
1027     RETVAL = w->signum;
1028    
1029     if (items > 1)
1030     {
1031 root 1.126 Signal signum = s_signum (new_signal);
1032 root 1.80 CHECK_SIG (new_signal, signum);
1033 root 1.39
1034 root 1.132 RESET_SIGNAL (w, (w, signum));
1035 root 1.39 }
1036     }
1037     OUTPUT:
1038     RETVAL
1039    
1040 root 1.29 MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
1041 root 1.15
1042 root 1.78 void ev_timer_start (ev_timer *w)
1043 root 1.18 INIT:
1044     CHECK_REPEAT (w->repeat);
1045 root 1.78 CODE:
1046     START (timer, w);
1047 root 1.15
1048 root 1.78 void ev_timer_stop (ev_timer *w)
1049     CODE:
1050     STOP (timer, w);
1051 root 1.1
1052 root 1.171 void ev_timer_again (ev_timer *w, NV repeat = NO_INIT)
1053     CODE:
1054     if (items > 1)
1055     w->repeat = repeat;
1056 root 1.18 CHECK_REPEAT (w->repeat);
1057 root 1.93 ev_timer_again (e_loop (w), w);
1058 root 1.78 UNREF (w);
1059 root 1.17
1060 root 1.130 NV ev_timer_remaining (ev_timer *w)
1061     C_ARGS: e_loop (w), w
1062    
1063 root 1.78 void DESTROY (ev_timer *w)
1064 root 1.26 CODE:
1065 root 1.78 STOP (timer, w);
1066 root 1.34 e_destroy (w);
1067 root 1.26
1068 root 1.78 void set (ev_timer *w, NV after, NV repeat = 0.)
1069 root 1.18 INIT:
1070     CHECK_REPEAT (repeat);
1071 root 1.1 CODE:
1072 root 1.80 RESET (timer, w, (w, after, repeat));
1073 root 1.1
1074 root 1.29 MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
1075 root 1.15
1076 root 1.78 void ev_periodic_start (ev_periodic *w)
1077 root 1.18 INIT:
1078     CHECK_REPEAT (w->interval);
1079 root 1.78 CODE:
1080     START (periodic, w);
1081 root 1.1
1082 root 1.78 void ev_periodic_stop (ev_periodic *w)
1083     CODE:
1084     STOP (periodic, w);
1085 root 1.1
1086 root 1.78 void ev_periodic_again (ev_periodic *w)
1087     CODE:
1088 root 1.93 ev_periodic_again (e_loop (w), w);
1089 root 1.78 UNREF (w);
1090 root 1.59
1091 root 1.78 void DESTROY (ev_periodic *w)
1092 root 1.26 CODE:
1093 root 1.78 STOP (periodic, w);
1094 root 1.34 e_destroy (w);
1095 root 1.26
1096 root 1.78 void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
1097 root 1.18 INIT:
1098     CHECK_REPEAT (interval);
1099 root 1.10 CODE:
1100     {
1101 root 1.138 SvREFCNT_dec (e_fh (w));
1102     e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1103 root 1.39
1104 root 1.138 RESET (periodic, w, (w, at, interval, e_fh (w) ? e_periodic_cb : 0));
1105 root 1.15 }
1106 root 1.10
1107 root 1.90 NV at (ev_periodic *w)
1108     CODE:
1109 root 1.111 RETVAL = ev_periodic_at (w);
1110 root 1.90 OUTPUT:
1111     RETVAL
1112    
1113 root 1.29 MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
1114 root 1.10
1115 root 1.78 void ev_idle_start (ev_idle *w)
1116     CODE:
1117     START (idle, w);
1118 root 1.10
1119 root 1.78 void ev_idle_stop (ev_idle *w)
1120     CODE:
1121     STOP (idle, w);
1122 root 1.10
1123 root 1.78 void DESTROY (ev_idle *w)
1124 root 1.26 CODE:
1125 root 1.78 STOP (idle, w);
1126 root 1.34 e_destroy (w);
1127 root 1.26
1128 root 1.100 MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
1129 root 1.22
1130 root 1.78 void ev_prepare_start (ev_prepare *w)
1131     CODE:
1132     START (prepare, w);
1133 root 1.22
1134 root 1.78 void ev_prepare_stop (ev_prepare *w)
1135     CODE:
1136     STOP (prepare, w);
1137 root 1.22
1138 root 1.78 void DESTROY (ev_prepare *w)
1139 root 1.26 CODE:
1140 root 1.78 STOP (prepare, w);
1141 root 1.34 e_destroy (w);
1142 root 1.26
1143 root 1.29 MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
1144 root 1.1
1145 root 1.78 void ev_check_start (ev_check *w)
1146     CODE:
1147     START (check, w);
1148 root 1.1
1149 root 1.78 void ev_check_stop (ev_check *w)
1150     CODE:
1151     STOP (check, w);
1152 root 1.1
1153 root 1.78 void DESTROY (ev_check *w)
1154 root 1.26 CODE:
1155 root 1.78 STOP (check, w);
1156 root 1.34 e_destroy (w);
1157 root 1.26
1158 root 1.91 MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
1159    
1160     void ev_fork_start (ev_fork *w)
1161     CODE:
1162     START (fork, w);
1163    
1164     void ev_fork_stop (ev_fork *w)
1165     CODE:
1166     STOP (fork, w);
1167    
1168     void DESTROY (ev_fork *w)
1169     CODE:
1170     STOP (fork, w);
1171     e_destroy (w);
1172    
1173 root 1.160 #if CLEANUP_ENABLED
1174    
1175 root 1.145 MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1176    
1177     void ev_cleanup_start (ev_cleanup *w)
1178     CODE:
1179     START (cleanup, w);
1180    
1181     void ev_cleanup_stop (ev_cleanup *w)
1182     CODE:
1183     STOP (cleanup, w);
1184    
1185     void DESTROY (ev_cleanup *w)
1186     CODE:
1187     STOP (cleanup, w);
1188 root 1.160 SvREFCNT_inc (w->loop); /* has been dec'ed on creation */
1189 root 1.145 e_destroy (w);
1190    
1191 root 1.160 int keepalive (ev_watcher *w, SV *new_value = 0)
1192 root 1.146 CODE:
1193 root 1.160 RETVAL = 1;
1194 root 1.146 OUTPUT:
1195     RETVAL
1196    
1197 root 1.160 #endif
1198    
1199 root 1.29 MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1200 root 1.23
1201 root 1.139 #if EV_CHILD_ENABLE
1202    
1203 root 1.78 void ev_child_start (ev_child *w)
1204     CODE:
1205     START (child, w);
1206 root 1.23
1207 root 1.78 void ev_child_stop (ev_child *w)
1208     CODE:
1209     STOP (child, w);
1210 root 1.23
1211 root 1.78 void DESTROY (ev_child *w)
1212 root 1.26 CODE:
1213 root 1.78 STOP (child, w);
1214 root 1.34 e_destroy (w);
1215 root 1.26
1216 root 1.104 void set (ev_child *w, int pid, int trace)
1217 root 1.23 CODE:
1218 root 1.104 RESET (child, w, (w, pid, trace));
1219 root 1.23
1220 root 1.104 int pid (ev_child *w)
1221 root 1.45 ALIAS:
1222 root 1.104 rpid = 1
1223     rstatus = 2
1224 root 1.24 CODE:
1225 root 1.104 RETVAL = ix == 0 ? w->pid
1226     : ix == 1 ? w->rpid
1227     : w->rstatus;
1228 root 1.24 OUTPUT:
1229     RETVAL
1230    
1231 root 1.139 #endif
1232    
1233 root 1.80 MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1234    
1235     void ev_stat_start (ev_stat *w)
1236     CODE:
1237     START (stat, w);
1238    
1239     void ev_stat_stop (ev_stat *w)
1240     CODE:
1241     STOP (stat, w);
1242    
1243     void DESTROY (ev_stat *w)
1244     CODE:
1245     STOP (stat, w);
1246     e_destroy (w);
1247    
1248     void set (ev_stat *w, SV *path, NV interval)
1249     CODE:
1250     {
1251 root 1.138 sv_setsv (e_fh (w), path);
1252     RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval));
1253 root 1.80 }
1254    
1255     SV *path (ev_stat *w, SV *new_path = 0)
1256     CODE:
1257     {
1258 root 1.138 RETVAL = SvREFCNT_inc (e_fh (w));
1259 root 1.80
1260     if (items > 1)
1261     {
1262 root 1.138 SvREFCNT_dec (e_fh (w));
1263     e_fh (w) = newSVsv (new_path);
1264     RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval));
1265 root 1.80 }
1266     }
1267     OUTPUT:
1268     RETVAL
1269    
1270     NV interval (ev_stat *w, NV new_interval = 0.)
1271     CODE:
1272     {
1273     RETVAL = w->interval;
1274    
1275     if (items > 1)
1276 root 1.138 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), new_interval));
1277 root 1.80 }
1278     OUTPUT:
1279     RETVAL
1280    
1281 root 1.82 void prev (ev_stat *w)
1282     ALIAS:
1283     stat = 1
1284     attr = 2
1285     PPCODE:
1286     {
1287     ev_statdata *s = ix ? &w->attr : &w->prev;
1288    
1289     if (ix == 1)
1290 root 1.93 ev_stat_stat (e_loop (w), w);
1291 root 1.82 else if (!s->st_nlink)
1292     errno = ENOENT;
1293    
1294     PL_statcache.st_dev = s->st_nlink;
1295     PL_statcache.st_ino = s->st_ino;
1296     PL_statcache.st_mode = s->st_mode;
1297     PL_statcache.st_nlink = s->st_nlink;
1298     PL_statcache.st_uid = s->st_uid;
1299     PL_statcache.st_gid = s->st_gid;
1300     PL_statcache.st_rdev = s->st_rdev;
1301     PL_statcache.st_size = s->st_size;
1302     PL_statcache.st_atime = s->st_atime;
1303     PL_statcache.st_mtime = s->st_mtime;
1304     PL_statcache.st_ctime = s->st_ctime;
1305    
1306     if (GIMME_V == G_SCALAR)
1307     XPUSHs (boolSV (s->st_nlink));
1308     else if (GIMME_V == G_ARRAY && s->st_nlink)
1309     {
1310     EXTEND (SP, 13);
1311     PUSHs (sv_2mortal (newSViv (s->st_dev)));
1312     PUSHs (sv_2mortal (newSViv (s->st_ino)));
1313     PUSHs (sv_2mortal (newSVuv (s->st_mode)));
1314     PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
1315     PUSHs (sv_2mortal (newSViv (s->st_uid)));
1316     PUSHs (sv_2mortal (newSViv (s->st_gid)));
1317     PUSHs (sv_2mortal (newSViv (s->st_rdev)));
1318     PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
1319     PUSHs (sv_2mortal (newSVnv (s->st_atime)));
1320     PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
1321     PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1322     PUSHs (sv_2mortal (newSVuv (4096)));
1323     PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1324     }
1325     }
1326    
1327 root 1.93 MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1328 root 1.5
1329 root 1.93 void ev_embed_start (ev_embed *w)
1330     CODE:
1331     START (embed, w);
1332 root 1.5
1333 root 1.93 void ev_embed_stop (ev_embed *w)
1334     CODE:
1335     STOP (embed, w);
1336 root 1.5
1337 root 1.93 void DESTROY (ev_embed *w)
1338     CODE:
1339     STOP (embed, w);
1340     e_destroy (w);
1341 root 1.5
1342 root 1.93 void set (ev_embed *w, struct ev_loop *loop)
1343     CODE:
1344     {
1345 root 1.138 sv_setsv (e_fh (w), ST (1));
1346 root 1.93 RESET (embed, w, (w, loop));
1347 root 1.5 }
1348    
1349 root 1.96 SV *other (ev_embed *w)
1350     CODE:
1351 root 1.138 RETVAL = newSVsv (e_fh (w));
1352 root 1.96 OUTPUT:
1353     RETVAL
1354    
1355 root 1.107 void ev_embed_sweep (ev_embed *w)
1356     C_ARGS: e_loop (w), w
1357    
1358 root 1.106 MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1359    
1360     void ev_async_start (ev_async *w)
1361     CODE:
1362     START (async, w);
1363    
1364     void ev_async_stop (ev_async *w)
1365     CODE:
1366     STOP (async, w);
1367    
1368     void DESTROY (ev_async *w)
1369     CODE:
1370     STOP (async, w);
1371     e_destroy (w);
1372    
1373 root 1.107 void ev_async_send (ev_async *w)
1374     C_ARGS: e_loop (w), w
1375    
1376 root 1.110 SV *ev_async_async_pending (ev_async *w)
1377     CODE:
1378     RETVAL = boolSV (ev_async_pending (w));
1379     OUTPUT:
1380     RETVAL
1381    
1382 root 1.150 #ifndef EV_NO_LOOPS
1383 root 1.149
1384 root 1.98 MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1385 root 1.5
1386 root 1.97 SV *new (SV *klass, unsigned int flags = 0)
1387 root 1.93 CODE:
1388     {
1389     struct ev_loop *loop = ev_loop_new (flags);
1390 root 1.5
1391 root 1.93 if (!loop)
1392     XSRETURN_UNDEF;
1393 root 1.5
1394 root 1.95 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1395 root 1.93 }
1396     OUTPUT:
1397     RETVAL
1398 root 1.5
1399 root 1.93 void DESTROY (struct ev_loop *loop)
1400     CODE:
1401 root 1.160 /* 1. the default loop shouldn't be freed by destroying it's perl loop object */
1402 root 1.143 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1403     if (loop != evapi.default_loop)
1404 root 1.93 ev_loop_destroy (loop);
1405 root 1.5
1406 root 1.98 void ev_loop_fork (struct ev_loop *loop)
1407    
1408     NV ev_now (struct ev_loop *loop)
1409    
1410 root 1.115 void ev_now_update (struct ev_loop *loop)
1411    
1412 root 1.122 void ev_suspend (struct ev_loop *loop)
1413    
1414     void ev_resume (struct ev_loop *loop)
1415    
1416 root 1.101 void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1417    
1418     void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1419    
1420 root 1.98 unsigned int ev_backend (struct ev_loop *loop)
1421    
1422 root 1.142 void ev_verify (struct ev_loop *loop)
1423     ALIAS:
1424     loop_verify = 1
1425    
1426 root 1.137 unsigned int ev_iteration (struct ev_loop *loop)
1427 root 1.142 ALIAS:
1428     loop_count = 1
1429 root 1.98
1430 root 1.137 unsigned int ev_depth (struct ev_loop *loop)
1431 root 1.142 ALIAS:
1432     loop_depth = 1
1433 root 1.125
1434 root 1.162 int ev_run (struct ev_loop *loop, int flags = 0)
1435 root 1.142 ALIAS:
1436     loop = 1
1437 root 1.98
1438 root 1.142 void ev_break (struct ev_loop *loop, int how = 1)
1439     ALIAS:
1440     unloop = 1
1441 root 1.98
1442     void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1443    
1444 root 1.129 unsigned int ev_pending_count (struct ev_loop *loop)
1445    
1446     void ev_invoke_pending (struct ev_loop *loop)
1447    
1448 root 1.98 #if 0
1449    
1450     void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1451     CODE:
1452     {
1453 root 1.160 Signal signum = s_signum (signal);
1454 root 1.98 CHECK_SIG (signal, signum);
1455    
1456     ev_feed_signal_event (loop, signum);
1457     }
1458    
1459     #endif
1460    
1461 root 1.94 ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1462     ALIAS:
1463     io_ns = 1
1464     CODE:
1465     {
1466 root 1.126 int fd = s_fileno (fh, events & EV_WRITE);
1467 root 1.94 CHECK_FD (fh, fd);
1468    
1469     RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1470 root 1.138 e_fh (RETVAL) = newSVsv (fh);
1471 root 1.94 ev_io_set (RETVAL, fd, events);
1472     if (!ix) START (io, RETVAL);
1473     }
1474     OUTPUT:
1475     RETVAL
1476    
1477 root 1.98 ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1478     ALIAS:
1479     timer_ns = 1
1480     INIT:
1481     CHECK_REPEAT (repeat);
1482     CODE:
1483     RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1484     ev_timer_set (RETVAL, after, repeat);
1485     if (!ix) START (timer, RETVAL);
1486     OUTPUT:
1487     RETVAL
1488    
1489     SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1490     ALIAS:
1491     periodic_ns = 1
1492     INIT:
1493     CHECK_REPEAT (interval);
1494     CODE:
1495     {
1496 root 1.160 ev_periodic *w;
1497 root 1.98 w = e_new (sizeof (ev_periodic), cb, ST (0));
1498 root 1.138 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1499     ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
1500 root 1.98 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1501     if (!ix) START (periodic, w);
1502     }
1503     OUTPUT:
1504     RETVAL
1505    
1506     ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1507     ALIAS:
1508     signal_ns = 1
1509     CODE:
1510     {
1511 root 1.160 Signal signum = s_signum (signal);
1512 root 1.98 CHECK_SIG (signal, signum);
1513    
1514     RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1515     ev_signal_set (RETVAL, signum);
1516 root 1.132 if (!ix) START_SIGNAL (RETVAL);
1517 root 1.98 }
1518     OUTPUT:
1519     RETVAL
1520    
1521     ev_idle *idle (struct ev_loop *loop, SV *cb)
1522     ALIAS:
1523     idle_ns = 1
1524     CODE:
1525     RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1526     ev_idle_set (RETVAL);
1527     if (!ix) START (idle, RETVAL);
1528     OUTPUT:
1529     RETVAL
1530    
1531     ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1532     ALIAS:
1533     prepare_ns = 1
1534     CODE:
1535     RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1536     ev_prepare_set (RETVAL);
1537     if (!ix) START (prepare, RETVAL);
1538     OUTPUT:
1539     RETVAL
1540    
1541     ev_check *check (struct ev_loop *loop, SV *cb)
1542     ALIAS:
1543     check_ns = 1
1544     CODE:
1545     RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1546     ev_check_set (RETVAL);
1547     if (!ix) START (check, RETVAL);
1548     OUTPUT:
1549     RETVAL
1550    
1551     ev_fork *fork (struct ev_loop *loop, SV *cb)
1552     ALIAS:
1553     fork_ns = 1
1554     CODE:
1555     RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1556     ev_fork_set (RETVAL);
1557     if (!ix) START (fork, RETVAL);
1558     OUTPUT:
1559     RETVAL
1560    
1561 root 1.160 #if CLEANUP_ENABLED
1562    
1563 root 1.145 ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1564     ALIAS:
1565     cleanup_ns = 1
1566     CODE:
1567     RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1568 root 1.160 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
1569 root 1.145 ev_cleanup_set (RETVAL);
1570     if (!ix) START (cleanup, RETVAL);
1571     OUTPUT:
1572     RETVAL
1573 root 1.139
1574 root 1.160 #endif
1575    
1576 root 1.104 ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1577 root 1.98 ALIAS:
1578     child_ns = 1
1579     CODE:
1580 root 1.140 #if EV_CHILD_ENABLE
1581 root 1.98 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1582 root 1.104 ev_child_set (RETVAL, pid, trace);
1583 root 1.98 if (!ix) START (child, RETVAL);
1584 root 1.140 #else
1585     croak ("EV::child watchers not supported on this platform");
1586     #endif
1587 root 1.98 OUTPUT:
1588     RETVAL
1589    
1590     ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1591     ALIAS:
1592     stat_ns = 1
1593     CODE:
1594     RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1595 root 1.138 e_fh (RETVAL) = newSVsv (path);
1596     ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
1597 root 1.98 if (!ix) START (stat, RETVAL);
1598     OUTPUT:
1599     RETVAL
1600    
1601 root 1.114 ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1602 root 1.98 ALIAS:
1603     embed_ns = 1
1604     CODE:
1605     {
1606     if (!(ev_backend (other) & ev_embeddable_backends ()))
1607     croak ("passed loop is not embeddable via EV::embed,");
1608    
1609     RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1610 root 1.138 e_fh (RETVAL) = newSVsv (ST (1));
1611 root 1.98 ev_embed_set (RETVAL, other);
1612     if (!ix) START (embed, RETVAL);
1613     }
1614     OUTPUT:
1615     RETVAL
1616    
1617 root 1.106 ev_async *async (struct ev_loop *loop, SV *cb)
1618     ALIAS:
1619     async_ns = 1
1620     CODE:
1621     RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1622     ev_async_set (RETVAL);
1623     if (!ix) START (async, RETVAL);
1624     OUTPUT:
1625     RETVAL
1626    
1627 root 1.98 void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1628     CODE:
1629     ev_once (
1630     loop,
1631 root 1.126 s_fileno (fh, events & EV_WRITE), events,
1632 root 1.98 SvOK (timeout) ? SvNV (timeout) : -1.,
1633     e_once_cb,
1634     newSVsv (cb)
1635     );
1636    
1637 root 1.149 #endif
1638