ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.166
Committed: Sat Apr 6 00:05:45 2013 UTC (11 years, 1 month ago) by root
Branch: MAIN
Changes since 1.165: +41 -51 lines
Log Message:
revert, not really so good idea

File Contents

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