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