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