ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.133
Committed: Sun Aug 9 13:30:41 2009 UTC (14 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-3_8
Changes since 1.132: +7 -0 lines
Log Message:
3.8

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