ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.154
Committed: Tue Jan 11 02:31:24 2011 UTC (13 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-4_03
Changes since 1.153: +9 -0 lines
Log Message:
*** empty log message ***

File Contents

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