ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.151
Committed: Thu Dec 30 07:28:47 2010 UTC (13 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-4_02
Changes since 1.150: +1 -0 lines
Log Message:
4.02

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