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