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