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