ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.169
Committed: Sat Mar 8 15:51:23 2014 UTC (10 years, 2 months ago) by root
Branch: MAIN
CVS Tags: EV-rel-4_20, EV_rel-4_17, EV_rel-4_16, EV-rel-4_18
Changes since 1.168: +1 -1 lines
Log Message:
4.16

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.162 #if __linux
540     int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
541     __register_atfork (0, 0, default_fork, 0);
542     #else
543 root 1.147 pthread_atfork (0, 0, default_fork);
544 root 1.56 #endif
545 root 1.162 #endif
546 root 1.1 }
547    
548 root 1.97 SV *ev_default_loop (unsigned int flags = 0)
549 root 1.91 CODE:
550     {
551 root 1.93 if (!default_loop_sv)
552     {
553     evapi.default_loop = ev_default_loop (flags);
554    
555     if (!evapi.default_loop)
556     XSRETURN_UNDEF;
557    
558     default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
559     }
560 root 1.1
561 root 1.93 RETVAL = newSVsv (default_loop_sv);
562 root 1.91 }
563     OUTPUT:
564     RETVAL
565 root 1.1
566 root 1.102 void ev_default_destroy ()
567     CODE:
568 root 1.144 ev_loop_destroy (EV_DEFAULT_UC);
569 root 1.102 SvREFCNT_dec (default_loop_sv);
570     default_loop_sv = 0;
571    
572     unsigned int ev_supported_backends ()
573    
574     unsigned int ev_recommended_backends ()
575    
576     unsigned int ev_embeddable_backends ()
577    
578 root 1.117 void ev_sleep (NV interval)
579    
580 root 1.15 NV ev_time ()
581 root 1.1
582 root 1.154 void ev_feed_signal (SV *signal)
583     CODE:
584     {
585     Signal signum = s_signum (signal);
586     CHECK_SIG (signal, signum);
587    
588     ev_feed_signal (signum);
589     }
590    
591 root 1.91 NV ev_now ()
592     C_ARGS: evapi.default_loop
593    
594 root 1.115 void ev_now_update ()
595     C_ARGS: evapi.default_loop
596    
597 root 1.122 void ev_suspend ()
598     C_ARGS: evapi.default_loop
599    
600     void ev_resume ()
601     C_ARGS: evapi.default_loop
602    
603 root 1.91 unsigned int ev_backend ()
604     C_ARGS: evapi.default_loop
605 root 1.1
606 root 1.137 void ev_verify ()
607 root 1.142 ALIAS:
608     loop_verify = 1
609 root 1.125 C_ARGS: evapi.default_loop
610    
611 root 1.137 unsigned int ev_iteration ()
612 root 1.142 ALIAS:
613     loop_count = 1
614 root 1.91 C_ARGS: evapi.default_loop
615 root 1.86
616 root 1.137 unsigned int ev_depth ()
617 root 1.142 ALIAS:
618     loop_depth = 1
619 root 1.125 C_ARGS: evapi.default_loop
620    
621 root 1.101 void ev_set_io_collect_interval (NV interval)
622     C_ARGS: evapi.default_loop, interval
623    
624     void ev_set_timeout_collect_interval (NV interval)
625     C_ARGS: evapi.default_loop, interval
626    
627 root 1.162 int ev_run (int flags = 0)
628 root 1.142 ALIAS:
629     loop = 1
630 root 1.91 C_ARGS: evapi.default_loop, flags
631 root 1.1
632 root 1.142 void ev_break (int how = EVBREAK_ONE)
633     ALIAS:
634     unloop = 1
635 root 1.91 C_ARGS: evapi.default_loop, how
636 root 1.1
637 root 1.89 void ev_feed_fd_event (int fd, int revents = EV_NONE)
638 root 1.91 C_ARGS: evapi.default_loop, fd, revents
639 root 1.89
640     void ev_feed_signal_event (SV *signal)
641     CODE:
642     {
643 root 1.162 Signal signum = s_signum (signal);
644 root 1.89 CHECK_SIG (signal, signum);
645    
646 root 1.91 ev_feed_signal_event (evapi.default_loop, signum);
647 root 1.89 }
648    
649 root 1.129 unsigned int ev_pending_count ()
650     C_ARGS: evapi.default_loop
651    
652     void ev_invoke_pending ()
653     C_ARGS: evapi.default_loop
654    
655 root 1.78 ev_io *io (SV *fh, int events, SV *cb)
656 root 1.15 ALIAS:
657     io_ns = 1
658 root 1.133 _ae_io = 2
659 root 1.1 CODE:
660 root 1.31 {
661 root 1.126 int fd = s_fileno (fh, events & EV_WRITE);
662 root 1.31 CHECK_FD (fh, fd);
663    
664 root 1.133 if (ix == 2)
665     {
666 root 1.166 ix = 0;
667 root 1.133 events = events ? EV_WRITE : EV_READ;
668     }
669    
670 root 1.166 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
671     e_fh (RETVAL) = newSVsv (fh);
672 root 1.31 ev_io_set (RETVAL, fd, events);
673 root 1.166 if (!ix) START (io, RETVAL);
674 root 1.31 }
675 root 1.1 OUTPUT:
676     RETVAL
677    
678 root 1.78 ev_timer *timer (NV after, NV repeat, SV *cb)
679 root 1.1 ALIAS:
680 root 1.15 timer_ns = 1
681 root 1.18 INIT:
682     CHECK_REPEAT (repeat);
683 root 1.1 CODE:
684 root 1.93 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
685 root 1.29 ev_timer_set (RETVAL, after, repeat);
686 root 1.78 if (!ix) START (timer, RETVAL);
687 root 1.1 OUTPUT:
688     RETVAL
689    
690 root 1.59 SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
691 root 1.9 ALIAS:
692 root 1.15 periodic_ns = 1
693 root 1.18 INIT:
694     CHECK_REPEAT (interval);
695 root 1.9 CODE:
696 root 1.59 {
697 root 1.78 ev_periodic *w;
698 root 1.93 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
699 root 1.138 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
700     ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
701 root 1.78 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
702     if (!ix) START (periodic, w);
703 root 1.59 }
704 root 1.9 OUTPUT:
705     RETVAL
706    
707 root 1.80 ev_signal *signal (SV *signal, SV *cb)
708 root 1.1 ALIAS:
709 root 1.15 signal_ns = 1
710 root 1.1 CODE:
711 root 1.80 {
712 root 1.126 Signal signum = s_signum (signal);
713 root 1.80 CHECK_SIG (signal, signum);
714    
715 root 1.93 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
716 root 1.29 ev_signal_set (RETVAL, signum);
717 root 1.132 if (!ix) START_SIGNAL (RETVAL);
718 root 1.80 }
719 root 1.1 OUTPUT:
720     RETVAL
721    
722 root 1.78 ev_idle *idle (SV *cb)
723 root 1.1 ALIAS:
724 root 1.15 idle_ns = 1
725 root 1.1 CODE:
726 root 1.93 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
727 root 1.29 ev_idle_set (RETVAL);
728 root 1.78 if (!ix) START (idle, RETVAL);
729 root 1.1 OUTPUT:
730     RETVAL
731    
732 root 1.78 ev_prepare *prepare (SV *cb)
733 root 1.22 ALIAS:
734     prepare_ns = 1
735     CODE:
736 root 1.93 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
737 root 1.29 ev_prepare_set (RETVAL);
738 root 1.78 if (!ix) START (prepare, RETVAL);
739 root 1.22 OUTPUT:
740     RETVAL
741    
742 root 1.78 ev_check *check (SV *cb)
743 root 1.1 ALIAS:
744 root 1.15 check_ns = 1
745 root 1.1 CODE:
746 root 1.93 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
747 root 1.29 ev_check_set (RETVAL);
748 root 1.78 if (!ix) START (check, RETVAL);
749 root 1.1 OUTPUT:
750     RETVAL
751    
752 root 1.91 ev_fork *fork (SV *cb)
753     ALIAS:
754     fork_ns = 1
755     CODE:
756 root 1.93 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
757 root 1.91 ev_fork_set (RETVAL);
758     if (!ix) START (fork, RETVAL);
759     OUTPUT:
760     RETVAL
761    
762 root 1.160 #if CLEANUP_ENABLED
763    
764 root 1.145 ev_cleanup *cleanup (SV *cb)
765     ALIAS:
766     cleanup_ns = 1
767     CODE:
768     RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
769 root 1.160 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
770 root 1.145 ev_cleanup_set (RETVAL);
771     if (!ix) START (cleanup, RETVAL);
772     OUTPUT:
773     RETVAL
774 root 1.139
775 root 1.160 #endif
776    
777 root 1.104 ev_child *child (int pid, int trace, SV *cb)
778 root 1.23 ALIAS:
779 root 1.69 child_ns = 1
780 root 1.23 CODE:
781 root 1.140 #if EV_CHILD_ENABLE
782 root 1.93 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
783 root 1.104 ev_child_set (RETVAL, pid, trace);
784 root 1.78 if (!ix) START (child, RETVAL);
785 root 1.140 #else
786     croak ("EV::child watchers not supported on this platform");
787     #endif
788 root 1.23 OUTPUT:
789     RETVAL
790    
791 root 1.139
792 root 1.80 ev_stat *stat (SV *path, NV interval, SV *cb)
793     ALIAS:
794     stat_ns = 1
795     CODE:
796 root 1.93 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
797 root 1.138 e_fh (RETVAL) = newSVsv (path);
798     ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
799 root 1.80 if (!ix) START (stat, RETVAL);
800     OUTPUT:
801     RETVAL
802    
803 root 1.150 #ifndef EV_NO_LOOPS
804    
805 root 1.114 ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
806 root 1.93 ALIAS:
807     embed_ns = 1
808     CODE:
809 root 1.95 {
810     if (!(ev_backend (loop) & ev_embeddable_backends ()))
811     croak ("passed loop is not embeddable via EV::embed,");
812    
813 root 1.93 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
814 root 1.138 e_fh (RETVAL) = newSVsv (ST (0));
815 root 1.93 ev_embed_set (RETVAL, loop);
816     if (!ix) START (embed, RETVAL);
817 root 1.95 }
818 root 1.93 OUTPUT:
819     RETVAL
820    
821 root 1.150 #endif
822    
823 root 1.106 ev_async *async (SV *cb)
824     ALIAS:
825     async_ns = 1
826     CODE:
827     RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
828     ev_async_set (RETVAL);
829     if (!ix) START (async, RETVAL);
830     OUTPUT:
831     RETVAL
832    
833 root 1.76 void once (SV *fh, int events, SV *timeout, SV *cb)
834 root 1.75 CODE:
835 root 1.76 ev_once (
836 root 1.91 evapi.default_loop,
837 root 1.126 s_fileno (fh, events & EV_WRITE), events,
838 root 1.76 SvOK (timeout) ? SvNV (timeout) : -1.,
839     e_once_cb,
840     newSVsv (cb)
841     );
842 root 1.15
843 root 1.1 PROTOTYPES: DISABLE
844    
845 root 1.15 MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
846 root 1.1
847 root 1.78 int ev_is_active (ev_watcher *w)
848 root 1.1
849 root 1.78 int ev_is_pending (ev_watcher *w)
850    
851 root 1.89 void ev_invoke (ev_watcher *w, int revents = EV_NONE)
852 root 1.93 C_ARGS: e_loop (w), w, revents
853 root 1.89
854     int ev_clear_pending (ev_watcher *w)
855 root 1.93 C_ARGS: e_loop (w), w
856 root 1.89
857     void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
858 root 1.93 C_ARGS: e_loop (w), w, revents
859 root 1.89
860 root 1.78 int keepalive (ev_watcher *w, int new_value = 0)
861     CODE:
862     {
863 root 1.104 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
864 root 1.78 new_value = new_value ? WFLAG_KEEPALIVE : 0;
865    
866 root 1.104 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
867 root 1.78 {
868 root 1.121 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
869 root 1.78 REF (w);
870     UNREF (w);
871     }
872     }
873     OUTPUT:
874     RETVAL
875    
876     SV *cb (ev_watcher *w, SV *new_cb = 0)
877 root 1.1 CODE:
878 root 1.15 {
879     if (items > 1)
880 root 1.112 {
881 root 1.126 new_cb = s_get_cv_croak (new_cb);
882 root 1.112 RETVAL = newRV_noinc (w->cb_sv);
883     w->cb_sv = SvREFCNT_inc (new_cb);
884     }
885     else
886     RETVAL = newRV_inc (w->cb_sv);
887 root 1.15 }
888 root 1.1 OUTPUT:
889     RETVAL
890    
891 root 1.78 SV *data (ev_watcher *w, SV *new_data = 0)
892 root 1.60 CODE:
893     {
894     RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
895 root 1.79
896     if (items > 1)
897     {
898     SvREFCNT_dec (w->data);
899     w->data = newSVsv (new_data);
900     }
901 root 1.60 }
902     OUTPUT:
903     RETVAL
904    
905 root 1.99 SV *loop (ev_watcher *w)
906     CODE:
907     RETVAL = newRV_inc (w->loop);
908     OUTPUT:
909     RETVAL
910    
911 root 1.78 int priority (ev_watcher *w, int new_priority = 0)
912 root 1.41 CODE:
913     {
914     RETVAL = w->priority;
915    
916     if (items > 1)
917     {
918     int active = ev_is_active (w);
919    
920     if (active)
921     {
922     /* grrr. */
923     PUSHMARK (SP);
924     XPUSHs (ST (0));
925 root 1.87 PUTBACK;
926 root 1.41 call_method ("stop", G_DISCARD | G_VOID);
927     }
928    
929     ev_set_priority (w, new_priority);
930    
931     if (active)
932     {
933     PUSHMARK (SP);
934     XPUSHs (ST (0));
935 root 1.87 PUTBACK;
936 root 1.41 call_method ("start", G_DISCARD | G_VOID);
937     }
938     }
939     }
940     OUTPUT:
941     RETVAL
942    
943 root 1.78 MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_
944 root 1.1
945 root 1.78 void ev_io_start (ev_io *w)
946     CODE:
947     START (io, w);
948 root 1.1
949 root 1.78 void ev_io_stop (ev_io *w)
950     CODE:
951     STOP (io, w);
952 root 1.15
953 root 1.78 void DESTROY (ev_io *w)
954 root 1.26 CODE:
955 root 1.78 STOP (io, w);
956 root 1.34 e_destroy (w);
957 root 1.26
958 root 1.78 void set (ev_io *w, SV *fh, int events)
959 root 1.1 CODE:
960     {
961 root 1.126 int fd = s_fileno (fh, events & EV_WRITE);
962 root 1.31 CHECK_FD (fh, fd);
963    
964 root 1.138 sv_setsv (e_fh (w), fh);
965 root 1.80 RESET (io, w, (w, fd, events));
966 root 1.15 }
967 root 1.1
968 root 1.78 SV *fh (ev_io *w, SV *new_fh = 0)
969 root 1.1 CODE:
970 root 1.15 {
971     if (items > 1)
972     {
973 root 1.126 int fd = s_fileno (new_fh, w->events & EV_WRITE);
974 root 1.80 CHECK_FD (new_fh, fd);
975 root 1.1
976 root 1.138 RETVAL = e_fh (w);
977     e_fh (w) = newSVsv (new_fh);
978 root 1.1
979 root 1.80 RESET (io, w, (w, fd, w->events));
980 root 1.15 }
981 root 1.80 else
982 root 1.138 RETVAL = newSVsv (e_fh (w));
983 root 1.15 }
984 root 1.1 OUTPUT:
985     RETVAL
986    
987 root 1.78 int events (ev_io *w, int new_events = EV_UNDEF)
988 root 1.1 CODE:
989 root 1.15 {
990     RETVAL = w->events;
991    
992     if (items > 1)
993 root 1.80 RESET (io, w, (w, w->fd, new_events));
994 root 1.15 }
995 root 1.1 OUTPUT:
996     RETVAL
997    
998 root 1.29 MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
999 root 1.15
1000 root 1.78 void ev_signal_start (ev_signal *w)
1001     CODE:
1002 root 1.132 START_SIGNAL (w);
1003 root 1.15
1004 root 1.78 void ev_signal_stop (ev_signal *w)
1005     CODE:
1006     STOP (signal, w);
1007 root 1.15
1008 root 1.78 void DESTROY (ev_signal *w)
1009 root 1.26 CODE:
1010 root 1.78 STOP (signal, w);
1011 root 1.34 e_destroy (w);
1012 root 1.26
1013 root 1.78 void set (ev_signal *w, SV *signal)
1014 root 1.1 CODE:
1015 root 1.15 {
1016 root 1.126 Signal signum = s_signum (signal);
1017 root 1.80 CHECK_SIG (signal, signum);
1018 root 1.39
1019 root 1.132 RESET_SIGNAL (w, (w, signum));
1020 root 1.15 }
1021    
1022 root 1.78 int signal (ev_signal *w, SV *new_signal = 0)
1023 root 1.39 CODE:
1024     {
1025     RETVAL = w->signum;
1026    
1027     if (items > 1)
1028     {
1029 root 1.126 Signal signum = s_signum (new_signal);
1030 root 1.80 CHECK_SIG (new_signal, signum);
1031 root 1.39
1032 root 1.132 RESET_SIGNAL (w, (w, signum));
1033 root 1.39 }
1034     }
1035     OUTPUT:
1036     RETVAL
1037    
1038 root 1.29 MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
1039 root 1.15
1040 root 1.78 void ev_timer_start (ev_timer *w)
1041 root 1.18 INIT:
1042     CHECK_REPEAT (w->repeat);
1043 root 1.78 CODE:
1044     START (timer, w);
1045 root 1.15
1046 root 1.78 void ev_timer_stop (ev_timer *w)
1047     CODE:
1048     STOP (timer, w);
1049 root 1.1
1050 root 1.78 void ev_timer_again (ev_timer *w)
1051 root 1.18 INIT:
1052     CHECK_REPEAT (w->repeat);
1053 root 1.78 CODE:
1054 root 1.93 ev_timer_again (e_loop (w), w);
1055 root 1.78 UNREF (w);
1056 root 1.17
1057 root 1.130 NV ev_timer_remaining (ev_timer *w)
1058     C_ARGS: e_loop (w), w
1059    
1060 root 1.78 void DESTROY (ev_timer *w)
1061 root 1.26 CODE:
1062 root 1.78 STOP (timer, w);
1063 root 1.34 e_destroy (w);
1064 root 1.26
1065 root 1.78 void set (ev_timer *w, NV after, NV repeat = 0.)
1066 root 1.18 INIT:
1067     CHECK_REPEAT (repeat);
1068 root 1.1 CODE:
1069 root 1.80 RESET (timer, w, (w, after, repeat));
1070 root 1.1
1071 root 1.29 MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
1072 root 1.15
1073 root 1.78 void ev_periodic_start (ev_periodic *w)
1074 root 1.18 INIT:
1075     CHECK_REPEAT (w->interval);
1076 root 1.78 CODE:
1077     START (periodic, w);
1078 root 1.1
1079 root 1.78 void ev_periodic_stop (ev_periodic *w)
1080     CODE:
1081     STOP (periodic, w);
1082 root 1.1
1083 root 1.78 void ev_periodic_again (ev_periodic *w)
1084     CODE:
1085 root 1.93 ev_periodic_again (e_loop (w), w);
1086 root 1.78 UNREF (w);
1087 root 1.59
1088 root 1.78 void DESTROY (ev_periodic *w)
1089 root 1.26 CODE:
1090 root 1.78 STOP (periodic, w);
1091 root 1.34 e_destroy (w);
1092 root 1.26
1093 root 1.78 void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
1094 root 1.18 INIT:
1095     CHECK_REPEAT (interval);
1096 root 1.10 CODE:
1097     {
1098 root 1.138 SvREFCNT_dec (e_fh (w));
1099     e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1100 root 1.39
1101 root 1.138 RESET (periodic, w, (w, at, interval, e_fh (w) ? e_periodic_cb : 0));
1102 root 1.15 }
1103 root 1.10
1104 root 1.90 NV at (ev_periodic *w)
1105     CODE:
1106 root 1.111 RETVAL = ev_periodic_at (w);
1107 root 1.90 OUTPUT:
1108     RETVAL
1109    
1110 root 1.29 MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
1111 root 1.10
1112 root 1.78 void ev_idle_start (ev_idle *w)
1113     CODE:
1114     START (idle, w);
1115 root 1.10
1116 root 1.78 void ev_idle_stop (ev_idle *w)
1117     CODE:
1118     STOP (idle, w);
1119 root 1.10
1120 root 1.78 void DESTROY (ev_idle *w)
1121 root 1.26 CODE:
1122 root 1.78 STOP (idle, w);
1123 root 1.34 e_destroy (w);
1124 root 1.26
1125 root 1.100 MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
1126 root 1.22
1127 root 1.78 void ev_prepare_start (ev_prepare *w)
1128     CODE:
1129     START (prepare, w);
1130 root 1.22
1131 root 1.78 void ev_prepare_stop (ev_prepare *w)
1132     CODE:
1133     STOP (prepare, w);
1134 root 1.22
1135 root 1.78 void DESTROY (ev_prepare *w)
1136 root 1.26 CODE:
1137 root 1.78 STOP (prepare, w);
1138 root 1.34 e_destroy (w);
1139 root 1.26
1140 root 1.29 MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
1141 root 1.1
1142 root 1.78 void ev_check_start (ev_check *w)
1143     CODE:
1144     START (check, w);
1145 root 1.1
1146 root 1.78 void ev_check_stop (ev_check *w)
1147     CODE:
1148     STOP (check, w);
1149 root 1.1
1150 root 1.78 void DESTROY (ev_check *w)
1151 root 1.26 CODE:
1152 root 1.78 STOP (check, w);
1153 root 1.34 e_destroy (w);
1154 root 1.26
1155 root 1.91 MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
1156    
1157     void ev_fork_start (ev_fork *w)
1158     CODE:
1159     START (fork, w);
1160    
1161     void ev_fork_stop (ev_fork *w)
1162     CODE:
1163     STOP (fork, w);
1164    
1165     void DESTROY (ev_fork *w)
1166     CODE:
1167     STOP (fork, w);
1168     e_destroy (w);
1169    
1170 root 1.160 #if CLEANUP_ENABLED
1171    
1172 root 1.145 MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1173    
1174     void ev_cleanup_start (ev_cleanup *w)
1175     CODE:
1176     START (cleanup, w);
1177    
1178     void ev_cleanup_stop (ev_cleanup *w)
1179     CODE:
1180     STOP (cleanup, w);
1181    
1182     void DESTROY (ev_cleanup *w)
1183     CODE:
1184     STOP (cleanup, w);
1185 root 1.160 SvREFCNT_inc (w->loop); /* has been dec'ed on creation */
1186 root 1.145 e_destroy (w);
1187    
1188 root 1.160 int keepalive (ev_watcher *w, SV *new_value = 0)
1189 root 1.146 CODE:
1190 root 1.160 RETVAL = 1;
1191 root 1.146 OUTPUT:
1192     RETVAL
1193    
1194 root 1.160 #endif
1195    
1196 root 1.29 MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1197 root 1.23
1198 root 1.139 #if EV_CHILD_ENABLE
1199    
1200 root 1.78 void ev_child_start (ev_child *w)
1201     CODE:
1202     START (child, w);
1203 root 1.23
1204 root 1.78 void ev_child_stop (ev_child *w)
1205     CODE:
1206     STOP (child, w);
1207 root 1.23
1208 root 1.78 void DESTROY (ev_child *w)
1209 root 1.26 CODE:
1210 root 1.78 STOP (child, w);
1211 root 1.34 e_destroy (w);
1212 root 1.26
1213 root 1.104 void set (ev_child *w, int pid, int trace)
1214 root 1.23 CODE:
1215 root 1.104 RESET (child, w, (w, pid, trace));
1216 root 1.23
1217 root 1.104 int pid (ev_child *w)
1218 root 1.45 ALIAS:
1219 root 1.104 rpid = 1
1220     rstatus = 2
1221 root 1.24 CODE:
1222 root 1.104 RETVAL = ix == 0 ? w->pid
1223     : ix == 1 ? w->rpid
1224     : w->rstatus;
1225 root 1.24 OUTPUT:
1226     RETVAL
1227    
1228 root 1.139 #endif
1229    
1230 root 1.80 MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1231    
1232     void ev_stat_start (ev_stat *w)
1233     CODE:
1234     START (stat, w);
1235    
1236     void ev_stat_stop (ev_stat *w)
1237     CODE:
1238     STOP (stat, w);
1239    
1240     void DESTROY (ev_stat *w)
1241     CODE:
1242     STOP (stat, w);
1243     e_destroy (w);
1244    
1245     void set (ev_stat *w, SV *path, NV interval)
1246     CODE:
1247     {
1248 root 1.138 sv_setsv (e_fh (w), path);
1249     RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval));
1250 root 1.80 }
1251    
1252     SV *path (ev_stat *w, SV *new_path = 0)
1253     CODE:
1254     {
1255 root 1.138 RETVAL = SvREFCNT_inc (e_fh (w));
1256 root 1.80
1257     if (items > 1)
1258     {
1259 root 1.138 SvREFCNT_dec (e_fh (w));
1260     e_fh (w) = newSVsv (new_path);
1261     RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval));
1262 root 1.80 }
1263     }
1264     OUTPUT:
1265     RETVAL
1266    
1267     NV interval (ev_stat *w, NV new_interval = 0.)
1268     CODE:
1269     {
1270     RETVAL = w->interval;
1271    
1272     if (items > 1)
1273 root 1.138 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), new_interval));
1274 root 1.80 }
1275     OUTPUT:
1276     RETVAL
1277    
1278 root 1.82 void prev (ev_stat *w)
1279     ALIAS:
1280     stat = 1
1281     attr = 2
1282     PPCODE:
1283     {
1284     ev_statdata *s = ix ? &w->attr : &w->prev;
1285    
1286     if (ix == 1)
1287 root 1.93 ev_stat_stat (e_loop (w), w);
1288 root 1.82 else if (!s->st_nlink)
1289     errno = ENOENT;
1290    
1291     PL_statcache.st_dev = s->st_nlink;
1292     PL_statcache.st_ino = s->st_ino;
1293     PL_statcache.st_mode = s->st_mode;
1294     PL_statcache.st_nlink = s->st_nlink;
1295     PL_statcache.st_uid = s->st_uid;
1296     PL_statcache.st_gid = s->st_gid;
1297     PL_statcache.st_rdev = s->st_rdev;
1298     PL_statcache.st_size = s->st_size;
1299     PL_statcache.st_atime = s->st_atime;
1300     PL_statcache.st_mtime = s->st_mtime;
1301     PL_statcache.st_ctime = s->st_ctime;
1302    
1303     if (GIMME_V == G_SCALAR)
1304     XPUSHs (boolSV (s->st_nlink));
1305     else if (GIMME_V == G_ARRAY && s->st_nlink)
1306     {
1307     EXTEND (SP, 13);
1308     PUSHs (sv_2mortal (newSViv (s->st_dev)));
1309     PUSHs (sv_2mortal (newSViv (s->st_ino)));
1310     PUSHs (sv_2mortal (newSVuv (s->st_mode)));
1311     PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
1312     PUSHs (sv_2mortal (newSViv (s->st_uid)));
1313     PUSHs (sv_2mortal (newSViv (s->st_gid)));
1314     PUSHs (sv_2mortal (newSViv (s->st_rdev)));
1315     PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
1316     PUSHs (sv_2mortal (newSVnv (s->st_atime)));
1317     PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
1318     PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1319     PUSHs (sv_2mortal (newSVuv (4096)));
1320     PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1321     }
1322     }
1323    
1324 root 1.93 MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
1325 root 1.5
1326 root 1.93 void ev_embed_start (ev_embed *w)
1327     CODE:
1328     START (embed, w);
1329 root 1.5
1330 root 1.93 void ev_embed_stop (ev_embed *w)
1331     CODE:
1332     STOP (embed, w);
1333 root 1.5
1334 root 1.93 void DESTROY (ev_embed *w)
1335     CODE:
1336     STOP (embed, w);
1337     e_destroy (w);
1338 root 1.5
1339 root 1.93 void set (ev_embed *w, struct ev_loop *loop)
1340     CODE:
1341     {
1342 root 1.138 sv_setsv (e_fh (w), ST (1));
1343 root 1.93 RESET (embed, w, (w, loop));
1344 root 1.5 }
1345    
1346 root 1.96 SV *other (ev_embed *w)
1347     CODE:
1348 root 1.138 RETVAL = newSVsv (e_fh (w));
1349 root 1.96 OUTPUT:
1350     RETVAL
1351    
1352 root 1.107 void ev_embed_sweep (ev_embed *w)
1353     C_ARGS: e_loop (w), w
1354    
1355 root 1.106 MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1356    
1357     void ev_async_start (ev_async *w)
1358     CODE:
1359     START (async, w);
1360    
1361     void ev_async_stop (ev_async *w)
1362     CODE:
1363     STOP (async, w);
1364    
1365     void DESTROY (ev_async *w)
1366     CODE:
1367     STOP (async, w);
1368     e_destroy (w);
1369    
1370 root 1.107 void ev_async_send (ev_async *w)
1371     C_ARGS: e_loop (w), w
1372    
1373 root 1.110 SV *ev_async_async_pending (ev_async *w)
1374     CODE:
1375     RETVAL = boolSV (ev_async_pending (w));
1376     OUTPUT:
1377     RETVAL
1378    
1379 root 1.150 #ifndef EV_NO_LOOPS
1380 root 1.149
1381 root 1.98 MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1382 root 1.5
1383 root 1.97 SV *new (SV *klass, unsigned int flags = 0)
1384 root 1.93 CODE:
1385     {
1386     struct ev_loop *loop = ev_loop_new (flags);
1387 root 1.5
1388 root 1.93 if (!loop)
1389     XSRETURN_UNDEF;
1390 root 1.5
1391 root 1.95 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1392 root 1.93 }
1393     OUTPUT:
1394     RETVAL
1395 root 1.5
1396 root 1.93 void DESTROY (struct ev_loop *loop)
1397     CODE:
1398 root 1.160 /* 1. the default loop shouldn't be freed by destroying it's perl loop object */
1399 root 1.143 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1400     if (loop != evapi.default_loop)
1401 root 1.93 ev_loop_destroy (loop);
1402 root 1.5
1403 root 1.98 void ev_loop_fork (struct ev_loop *loop)
1404    
1405     NV ev_now (struct ev_loop *loop)
1406    
1407 root 1.115 void ev_now_update (struct ev_loop *loop)
1408    
1409 root 1.122 void ev_suspend (struct ev_loop *loop)
1410    
1411     void ev_resume (struct ev_loop *loop)
1412    
1413 root 1.101 void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1414    
1415     void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1416    
1417 root 1.98 unsigned int ev_backend (struct ev_loop *loop)
1418    
1419 root 1.142 void ev_verify (struct ev_loop *loop)
1420     ALIAS:
1421     loop_verify = 1
1422    
1423 root 1.137 unsigned int ev_iteration (struct ev_loop *loop)
1424 root 1.142 ALIAS:
1425     loop_count = 1
1426 root 1.98
1427 root 1.137 unsigned int ev_depth (struct ev_loop *loop)
1428 root 1.142 ALIAS:
1429     loop_depth = 1
1430 root 1.125
1431 root 1.162 int ev_run (struct ev_loop *loop, int flags = 0)
1432 root 1.142 ALIAS:
1433     loop = 1
1434 root 1.98
1435 root 1.142 void ev_break (struct ev_loop *loop, int how = 1)
1436     ALIAS:
1437     unloop = 1
1438 root 1.98
1439     void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1440    
1441 root 1.129 unsigned int ev_pending_count (struct ev_loop *loop)
1442    
1443     void ev_invoke_pending (struct ev_loop *loop)
1444    
1445 root 1.98 #if 0
1446    
1447     void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1448     CODE:
1449     {
1450 root 1.160 Signal signum = s_signum (signal);
1451 root 1.98 CHECK_SIG (signal, signum);
1452    
1453     ev_feed_signal_event (loop, signum);
1454     }
1455    
1456     #endif
1457    
1458 root 1.94 ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1459     ALIAS:
1460     io_ns = 1
1461     CODE:
1462     {
1463 root 1.126 int fd = s_fileno (fh, events & EV_WRITE);
1464 root 1.94 CHECK_FD (fh, fd);
1465    
1466     RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1467 root 1.138 e_fh (RETVAL) = newSVsv (fh);
1468 root 1.94 ev_io_set (RETVAL, fd, events);
1469     if (!ix) START (io, RETVAL);
1470     }
1471     OUTPUT:
1472     RETVAL
1473    
1474 root 1.98 ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1475     ALIAS:
1476     timer_ns = 1
1477     INIT:
1478     CHECK_REPEAT (repeat);
1479     CODE:
1480     RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1481     ev_timer_set (RETVAL, after, repeat);
1482     if (!ix) START (timer, RETVAL);
1483     OUTPUT:
1484     RETVAL
1485    
1486     SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1487     ALIAS:
1488     periodic_ns = 1
1489     INIT:
1490     CHECK_REPEAT (interval);
1491     CODE:
1492     {
1493 root 1.160 ev_periodic *w;
1494 root 1.98 w = e_new (sizeof (ev_periodic), cb, ST (0));
1495 root 1.138 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1496     ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
1497 root 1.98 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1498     if (!ix) START (periodic, w);
1499     }
1500     OUTPUT:
1501     RETVAL
1502    
1503     ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1504     ALIAS:
1505     signal_ns = 1
1506     CODE:
1507     {
1508 root 1.160 Signal signum = s_signum (signal);
1509 root 1.98 CHECK_SIG (signal, signum);
1510    
1511     RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1512     ev_signal_set (RETVAL, signum);
1513 root 1.132 if (!ix) START_SIGNAL (RETVAL);
1514 root 1.98 }
1515     OUTPUT:
1516     RETVAL
1517    
1518     ev_idle *idle (struct ev_loop *loop, SV *cb)
1519     ALIAS:
1520     idle_ns = 1
1521     CODE:
1522     RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1523     ev_idle_set (RETVAL);
1524     if (!ix) START (idle, RETVAL);
1525     OUTPUT:
1526     RETVAL
1527    
1528     ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1529     ALIAS:
1530     prepare_ns = 1
1531     CODE:
1532     RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1533     ev_prepare_set (RETVAL);
1534     if (!ix) START (prepare, RETVAL);
1535     OUTPUT:
1536     RETVAL
1537    
1538     ev_check *check (struct ev_loop *loop, SV *cb)
1539     ALIAS:
1540     check_ns = 1
1541     CODE:
1542     RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1543     ev_check_set (RETVAL);
1544     if (!ix) START (check, RETVAL);
1545     OUTPUT:
1546     RETVAL
1547    
1548     ev_fork *fork (struct ev_loop *loop, SV *cb)
1549     ALIAS:
1550     fork_ns = 1
1551     CODE:
1552     RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1553     ev_fork_set (RETVAL);
1554     if (!ix) START (fork, RETVAL);
1555     OUTPUT:
1556     RETVAL
1557    
1558 root 1.160 #if CLEANUP_ENABLED
1559    
1560 root 1.145 ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1561     ALIAS:
1562     cleanup_ns = 1
1563     CODE:
1564     RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1565 root 1.160 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
1566 root 1.145 ev_cleanup_set (RETVAL);
1567     if (!ix) START (cleanup, RETVAL);
1568     OUTPUT:
1569     RETVAL
1570 root 1.139
1571 root 1.160 #endif
1572    
1573 root 1.104 ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1574 root 1.98 ALIAS:
1575     child_ns = 1
1576     CODE:
1577 root 1.140 #if EV_CHILD_ENABLE
1578 root 1.98 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1579 root 1.104 ev_child_set (RETVAL, pid, trace);
1580 root 1.98 if (!ix) START (child, RETVAL);
1581 root 1.140 #else
1582     croak ("EV::child watchers not supported on this platform");
1583     #endif
1584 root 1.98 OUTPUT:
1585     RETVAL
1586    
1587     ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1588     ALIAS:
1589     stat_ns = 1
1590     CODE:
1591     RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1592 root 1.138 e_fh (RETVAL) = newSVsv (path);
1593     ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
1594 root 1.98 if (!ix) START (stat, RETVAL);
1595     OUTPUT:
1596     RETVAL
1597    
1598 root 1.114 ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1599 root 1.98 ALIAS:
1600     embed_ns = 1
1601     CODE:
1602     {
1603     if (!(ev_backend (other) & ev_embeddable_backends ()))
1604     croak ("passed loop is not embeddable via EV::embed,");
1605    
1606     RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1607 root 1.138 e_fh (RETVAL) = newSVsv (ST (1));
1608 root 1.98 ev_embed_set (RETVAL, other);
1609     if (!ix) START (embed, RETVAL);
1610     }
1611     OUTPUT:
1612     RETVAL
1613    
1614 root 1.106 ev_async *async (struct ev_loop *loop, SV *cb)
1615     ALIAS:
1616     async_ns = 1
1617     CODE:
1618     RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1619     ev_async_set (RETVAL);
1620     if (!ix) START (async, RETVAL);
1621     OUTPUT:
1622     RETVAL
1623    
1624 root 1.98 void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1625     CODE:
1626     ev_once (
1627     loop,
1628 root 1.126 s_fileno (fh, events & EV_WRITE), events,
1629 root 1.98 SvOK (timeout) ? SvNV (timeout) : -1.,
1630     e_once_cb,
1631     newSVsv (cb)
1632     );
1633    
1634 root 1.149 #endif
1635