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