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