ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.90
Committed: Mon Dec 17 07:24:12 2007 UTC (16 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-1_86
Changes since 1.89: +12 -0 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.20 /*#include <netinet/in.h>*/
6 root 1.1
7 root 1.20 #define EV_PROTOTYPES 1
8 root 1.11 #include "EV/EVAPI.h"
9    
10 root 1.56 /* fix perl api breakage */
11     #undef signal
12     #undef sigaction
13    
14 root 1.64 #define EV_SELECT_IS_WINSOCKET 0
15     #ifdef _WIN32
16     # define EV_SELECT_USE_FD_SET 0
17     # define NFDBITS PERL_NFDBITS
18     # define fd_mask Perl_fd_mask
19     #endif
20 root 1.53 /* due to bugs in OS X we have to use libev/ explicitly here */
21     #include "libev/ev.c"
22 root 1.51 #include "event.c"
23 root 1.56
24 root 1.64 #ifndef _WIN32
25 root 1.55 # include <pthread.h>
26     #endif
27    
28 root 1.78 #define WFLAG_KEEPALIVE 1
29    
30     #define UNREF(w) \
31     if (!((w)->flags & WFLAG_KEEPALIVE) \
32     && !ev_is_active (w)) \
33     ev_unref ();
34    
35     #define REF(w) \
36     if (!((w)->flags & WFLAG_KEEPALIVE) \
37     && ev_is_active (w)) \
38     ev_ref ();
39    
40     #define START(type,w) \
41     do { \
42     UNREF (w); \
43     ev_ ## type ## _start (w); \
44     } while (0)
45    
46     #define STOP(type,w) \
47     do { \
48     REF (w); \
49     ev_ ## type ## _stop (w); \
50     } while (0)
51    
52 root 1.80 #define RESET(type,w,seta) \
53     do { \
54     int active = ev_is_active (w); \
55     if (active) STOP (type, w); \
56     ev_ ## type ## _set seta; \
57     if (active) START (type, w); \
58     } while (0)
59    
60 root 1.10 typedef int Signal;
61 root 1.1
62 root 1.11 static struct EVAPI evapi;
63    
64 root 1.15 static HV
65     *stash_watcher,
66     *stash_io,
67     *stash_timer,
68     *stash_periodic,
69     *stash_signal,
70 root 1.81 *stash_child,
71     *stash_stat,
72 root 1.15 *stash_idle,
73 root 1.22 *stash_prepare,
74 root 1.23 *stash_check,
75 root 1.80 *stash_embed,
76 root 1.81 *stash_fork;
77 root 1.1
78 root 1.43 #ifndef SIG_SIZE
79     /* kudos to Slaven Rezic for the idea */
80     static char sig_size [] = { SIG_NUM };
81     # define SIG_SIZE (sizeof (sig_size) + 1)
82     #endif
83    
84 root 1.80 static Signal
85 root 1.10 sv_signum (SV *sig)
86     {
87 root 1.80 Signal signum;
88 root 1.10
89 root 1.31 SvGETMAGIC (sig);
90 root 1.10
91     for (signum = 1; signum < SIG_SIZE; ++signum)
92     if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
93     return signum;
94    
95 root 1.80 signum = SvIV (sig);
96    
97     if (signum > 0 && signum < SIG_SIZE)
98     return signum;
99 root 1.31
100 root 1.10 return -1;
101     }
102    
103 root 1.1 /////////////////////////////////////////////////////////////////////////////
104     // Event
105    
106 root 1.78 static void e_cb (ev_watcher *w, int revents);
107 root 1.1
108 root 1.15 static int
109     sv_fileno (SV *fh)
110 root 1.1 {
111 root 1.3 SvGETMAGIC (fh);
112 root 1.1
113 root 1.3 if (SvROK (fh))
114     fh = SvRV (fh);
115 root 1.1
116 root 1.3 if (SvTYPE (fh) == SVt_PVGV)
117     return PerlIO_fileno (IoIFP (sv_2io (fh)));
118 root 1.1
119 root 1.75 if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL))
120 root 1.3 return SvIV (fh);
121 root 1.1
122     return -1;
123     }
124    
125 root 1.15 static void *
126     e_new (int size, SV *cb_sv)
127 root 1.1 {
128 root 1.78 ev_watcher *w;
129 root 1.15 SV *self = NEWSV (0, size);
130 root 1.1 SvPOK_only (self);
131 root 1.15 SvCUR_set (self, size);
132 root 1.1
133 root 1.78 w = (ev_watcher *)SvPVX (self);
134 root 1.1
135 root 1.63 ev_init (w, e_cb);
136 root 1.1
137 root 1.78 w->flags = WFLAG_KEEPALIVE;
138 root 1.61 w->data = 0;
139 root 1.15 w->fh = 0;
140     w->cb_sv = newSVsv (cb_sv);
141     w->self = self;
142 root 1.1
143 root 1.15 return (void *)w;
144 root 1.1 }
145    
146 root 1.56 static void
147 root 1.34 e_destroy (void *w_)
148     {
149 root 1.78 ev_watcher *w = (ev_watcher *)w_;
150 root 1.34
151     SvREFCNT_dec (w->fh ); w->fh = 0;
152     SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
153 root 1.60 SvREFCNT_dec (w->data ); w->data = 0;
154 root 1.34 }
155    
156 root 1.15 static SV *
157 root 1.78 e_bless (ev_watcher *w, HV *stash)
158 root 1.1 {
159     SV *rv;
160    
161 root 1.15 if (SvOBJECT (w->self))
162     rv = newRV_inc (w->self);
163 root 1.1 else
164     {
165 root 1.15 rv = newRV_noinc (w->self);
166     sv_bless (rv, stash);
167     SvREADONLY_on (w->self);
168 root 1.1 }
169    
170     return rv;
171     }
172    
173 root 1.75 static SV *sv_events_cache;
174    
175 root 1.1 static void
176 root 1.78 e_cb (ev_watcher *w, int revents)
177 root 1.1 {
178     dSP;
179 root 1.14 I32 mark = SP - PL_stack_base;
180 root 1.75 SV *sv_self, *sv_events;
181 root 1.1
182 root 1.15 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
183 root 1.14
184     if (sv_events_cache)
185     {
186     sv_events = sv_events_cache; sv_events_cache = 0;
187 root 1.15 SvIV_set (sv_events, revents);
188 root 1.14 }
189     else
190 root 1.15 sv_events = newSViv (revents);
191 root 1.14
192 root 1.1 PUSHMARK (SP);
193     EXTEND (SP, 2);
194 root 1.14 PUSHs (sv_self);
195     PUSHs (sv_events);
196 root 1.24
197 root 1.1 PUTBACK;
198 root 1.15 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
199 root 1.14
200     SvREFCNT_dec (sv_self);
201 root 1.75
202     if (sv_events_cache)
203     SvREFCNT_dec (sv_events);
204     else
205     sv_events_cache = sv_events;
206    
207     if (SvTRUE (ERRSV))
208     {
209 root 1.84 SPAGAIN;
210 root 1.75 PUSHMARK (SP);
211     PUTBACK;
212     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
213     }
214    
215     SP = PL_stack_base + mark;
216     PUTBACK;
217     }
218    
219     static void
220     e_once_cb (int revents, void *arg)
221     {
222     dSP;
223     I32 mark = SP - PL_stack_base;
224     SV *sv_events;
225    
226     if (sv_events_cache)
227     {
228     sv_events = sv_events_cache; sv_events_cache = 0;
229     SvIV_set (sv_events, revents);
230     }
231     else
232     sv_events = newSViv (revents);
233    
234     PUSHMARK (SP);
235     XPUSHs (sv_events);
236    
237     PUTBACK;
238     call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
239    
240     SvREFCNT_dec ((SV *)arg);
241 root 1.14
242     if (sv_events_cache)
243     SvREFCNT_dec (sv_events);
244     else
245     sv_events_cache = sv_events;
246 root 1.1
247 root 1.8 if (SvTRUE (ERRSV))
248     {
249 root 1.86 SPAGAIN;
250 root 1.8 PUSHMARK (SP);
251     PUTBACK;
252     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
253     }
254 root 1.68
255     SP = PL_stack_base + mark;
256     PUTBACK;
257 root 1.1 }
258    
259 root 1.59 static ev_tstamp
260 root 1.78 e_periodic_cb (ev_periodic *w, ev_tstamp now)
261 root 1.59 {
262     ev_tstamp retval;
263     int count;
264     dSP;
265    
266     ENTER;
267     SAVETMPS;
268    
269     PUSHMARK (SP);
270     EXTEND (SP, 2);
271     PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */
272     PUSHs (newSVnv (now));
273    
274     PUTBACK;
275     count = call_sv (w->fh, G_SCALAR | G_EVAL);
276     SPAGAIN;
277    
278     if (SvTRUE (ERRSV))
279     {
280     PUSHMARK (SP);
281     PUTBACK;
282     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
283     SPAGAIN;
284     }
285    
286     if (count > 0)
287     {
288     retval = SvNV (TOPs);
289    
290     if (retval < now)
291     retval = now;
292     }
293     else
294     retval = now;
295    
296     FREETMPS;
297     LEAVE;
298    
299     return retval;
300     }
301    
302 root 1.18 #define CHECK_REPEAT(repeat) if (repeat < 0.) \
303     croak (# repeat " value must be >= 0");
304    
305 root 1.31 #define CHECK_FD(fh,fd) if ((fd) < 0) \
306     croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
307    
308 root 1.80 #define CHECK_SIG(sv,num) if ((num) < 0) \
309     croak ("illegal signal number or name: %s", SvPV_nolen (sv));
310    
311 root 1.1 /////////////////////////////////////////////////////////////////////////////
312     // XS interface functions
313    
314 root 1.15 MODULE = EV PACKAGE = EV PREFIX = ev_
315 root 1.1
316 root 1.21 PROTOTYPES: ENABLE
317    
318 root 1.1 BOOT:
319     {
320     HV *stash = gv_stashpv ("EV", 1);
321    
322     static const struct {
323     const char *name;
324     IV iv;
325     } *civ, const_iv[] = {
326     # define const_iv(pfx, name) { # name, (IV) pfx ## name },
327 root 1.41 const_iv (EV_, MINPRI)
328     const_iv (EV_, MAXPRI)
329    
330 root 1.20 const_iv (EV_, UNDEF)
331 root 1.1 const_iv (EV_, NONE)
332     const_iv (EV_, TIMEOUT)
333     const_iv (EV_, READ)
334     const_iv (EV_, WRITE)
335     const_iv (EV_, SIGNAL)
336 root 1.15 const_iv (EV_, IDLE)
337     const_iv (EV_, CHECK)
338 root 1.20 const_iv (EV_, ERROR)
339 root 1.15
340     const_iv (EV, LOOP_ONESHOT)
341 root 1.1 const_iv (EV, LOOP_NONBLOCK)
342 root 1.67 const_iv (EV, UNLOOP_ONE)
343     const_iv (EV, UNLOOP_ALL)
344 root 1.15
345 root 1.73 const_iv (EV, BACKEND_SELECT)
346     const_iv (EV, BACKEND_POLL)
347     const_iv (EV, BACKEND_EPOLL)
348     const_iv (EV, BACKEND_KQUEUE)
349     const_iv (EV, BACKEND_DEVPOLL)
350     const_iv (EV, BACKEND_PORT)
351 root 1.66 const_iv (EV, FLAG_AUTO)
352     const_iv (EV, FLAG_NOENV)
353 root 1.83 const_iv (EV, FLAG_FORKCHECK)
354 root 1.1 };
355    
356     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
357     newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
358    
359 root 1.15 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
360 root 1.78 stash_io = gv_stashpv ("EV::IO" , 1);
361 root 1.15 stash_timer = gv_stashpv ("EV::Timer" , 1);
362     stash_periodic = gv_stashpv ("EV::Periodic", 1);
363     stash_signal = gv_stashpv ("EV::Signal" , 1);
364     stash_idle = gv_stashpv ("EV::Idle" , 1);
365 root 1.22 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
366 root 1.15 stash_check = gv_stashpv ("EV::Check" , 1);
367 root 1.23 stash_child = gv_stashpv ("EV::Child" , 1);
368 root 1.80 stash_embed = gv_stashpv ("EV::Embed" , 1);
369     stash_stat = gv_stashpv ("EV::Stat" , 1);
370 root 1.11
371     {
372     SV *sv = perl_get_sv ("EV::API", TRUE);
373     perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
374    
375 root 1.15 /* the poor man's shared library emulator */
376     evapi.ver = EV_API_VERSION;
377     evapi.rev = EV_API_REVISION;
378     evapi.sv_fileno = sv_fileno;
379     evapi.sv_signum = sv_signum;
380 root 1.47 evapi.now = ev_now;
381 root 1.73 evapi.backend = ev_backend;
382 root 1.47 evapi.unloop = ev_unloop;
383 root 1.80 evapi.ref = ev_ref;
384     evapi.unref = ev_unref;
385 root 1.15 evapi.time = ev_time;
386     evapi.loop = ev_loop;
387 root 1.20 evapi.once = ev_once;
388 root 1.29 evapi.io_start = ev_io_start;
389     evapi.io_stop = ev_io_stop;
390     evapi.timer_start = ev_timer_start;
391     evapi.timer_stop = ev_timer_stop;
392     evapi.timer_again = ev_timer_again;
393     evapi.periodic_start = ev_periodic_start;
394     evapi.periodic_stop = ev_periodic_stop;
395     evapi.signal_start = ev_signal_start;
396     evapi.signal_stop = ev_signal_stop;
397     evapi.idle_start = ev_idle_start;
398     evapi.idle_stop = ev_idle_stop;
399     evapi.prepare_start = ev_prepare_start;
400     evapi.prepare_stop = ev_prepare_stop;
401     evapi.check_start = ev_check_start;
402     evapi.check_stop = ev_check_stop;
403     evapi.child_start = ev_child_start;
404     evapi.child_stop = ev_child_stop;
405 root 1.80 evapi.stat_start = ev_stat_start;
406     evapi.stat_stop = ev_stat_stop;
407     evapi.stat_stat = ev_stat_stat;
408 root 1.88 evapi.clear_pending = ev_clear_pending;
409 root 1.89 evapi.invoke = ev_invoke;
410 root 1.11
411     sv_setiv (sv, (IV)&evapi);
412     SvREADONLY_on (sv);
413     }
414 root 1.64 #ifndef _WIN32
415 root 1.56 pthread_atfork (0, 0, ev_default_fork);
416     #endif
417 root 1.1 }
418    
419 root 1.15 NV ev_now ()
420 root 1.1
421 root 1.74 unsigned int ev_backend ()
422 root 1.1
423 root 1.15 NV ev_time ()
424 root 1.1
425 root 1.74 unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
426 root 1.1
427 root 1.86 unsigned int ev_loop_count ()
428    
429 root 1.15 void ev_loop (int flags = 0)
430 root 1.1
431 root 1.47 void ev_unloop (int how = 1)
432 root 1.1
433 root 1.89 void ev_feed_fd_event (int fd, int revents = EV_NONE)
434    
435     void ev_feed_signal_event (SV *signal)
436     CODE:
437     {
438     Signal signum = sv_signum (signal);
439     CHECK_SIG (signal, signum);
440    
441     ev_feed_signal_event (EV_DEFAULT_ signum);
442     }
443    
444 root 1.78 ev_io *io (SV *fh, int events, SV *cb)
445 root 1.15 ALIAS:
446     io_ns = 1
447 root 1.1 CODE:
448 root 1.31 {
449     int fd = sv_fileno (fh);
450     CHECK_FD (fh, fd);
451    
452 root 1.78 RETVAL = e_new (sizeof (ev_io), cb);
453 root 1.15 RETVAL->fh = newSVsv (fh);
454 root 1.31 ev_io_set (RETVAL, fd, events);
455 root 1.78 if (!ix) START (io, RETVAL);
456 root 1.31 }
457 root 1.1 OUTPUT:
458     RETVAL
459    
460 root 1.78 ev_timer *timer (NV after, NV repeat, SV *cb)
461 root 1.1 ALIAS:
462 root 1.15 timer_ns = 1
463 root 1.18 INIT:
464     CHECK_REPEAT (repeat);
465 root 1.1 CODE:
466 root 1.78 RETVAL = e_new (sizeof (ev_timer), cb);
467 root 1.29 ev_timer_set (RETVAL, after, repeat);
468 root 1.78 if (!ix) START (timer, RETVAL);
469 root 1.1 OUTPUT:
470     RETVAL
471    
472 root 1.59 SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
473 root 1.9 ALIAS:
474 root 1.15 periodic_ns = 1
475 root 1.18 INIT:
476     CHECK_REPEAT (interval);
477 root 1.9 CODE:
478 root 1.59 {
479 root 1.78 ev_periodic *w;
480     w = e_new (sizeof (ev_periodic), cb);
481 root 1.60 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
482 root 1.59 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
483 root 1.78 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
484     if (!ix) START (periodic, w);
485 root 1.59 }
486 root 1.9 OUTPUT:
487     RETVAL
488    
489 root 1.80 ev_signal *signal (SV *signal, SV *cb)
490 root 1.1 ALIAS:
491 root 1.15 signal_ns = 1
492 root 1.1 CODE:
493 root 1.80 {
494     Signal signum = sv_signum (signal);
495     CHECK_SIG (signal, signum);
496    
497 root 1.78 RETVAL = e_new (sizeof (ev_signal), cb);
498 root 1.29 ev_signal_set (RETVAL, signum);
499 root 1.78 if (!ix) START (signal, RETVAL);
500 root 1.80 }
501 root 1.1 OUTPUT:
502     RETVAL
503    
504 root 1.78 ev_idle *idle (SV *cb)
505 root 1.1 ALIAS:
506 root 1.15 idle_ns = 1
507 root 1.1 CODE:
508 root 1.78 RETVAL = e_new (sizeof (ev_idle), cb);
509 root 1.29 ev_idle_set (RETVAL);
510 root 1.78 if (!ix) START (idle, RETVAL);
511 root 1.1 OUTPUT:
512     RETVAL
513    
514 root 1.78 ev_prepare *prepare (SV *cb)
515 root 1.22 ALIAS:
516     prepare_ns = 1
517     CODE:
518 root 1.78 RETVAL = e_new (sizeof (ev_prepare), cb);
519 root 1.29 ev_prepare_set (RETVAL);
520 root 1.78 if (!ix) START (prepare, RETVAL);
521 root 1.22 OUTPUT:
522     RETVAL
523    
524 root 1.78 ev_check *check (SV *cb)
525 root 1.1 ALIAS:
526 root 1.15 check_ns = 1
527 root 1.1 CODE:
528 root 1.78 RETVAL = e_new (sizeof (ev_check), cb);
529 root 1.29 ev_check_set (RETVAL);
530 root 1.78 if (!ix) START (check, RETVAL);
531 root 1.1 OUTPUT:
532     RETVAL
533    
534 root 1.78 ev_child *child (int pid, SV *cb)
535 root 1.23 ALIAS:
536 root 1.69 child_ns = 1
537 root 1.23 CODE:
538 root 1.78 RETVAL = e_new (sizeof (ev_child), cb);
539 root 1.29 ev_child_set (RETVAL, pid);
540 root 1.78 if (!ix) START (child, RETVAL);
541 root 1.23 OUTPUT:
542     RETVAL
543    
544 root 1.80 ev_stat *stat (SV *path, NV interval, SV *cb)
545     ALIAS:
546     stat_ns = 1
547     CODE:
548     RETVAL = e_new (sizeof (ev_stat), cb);
549     RETVAL->fh = newSVsv (path);
550     ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
551     if (!ix) START (stat, RETVAL);
552     OUTPUT:
553     RETVAL
554    
555 root 1.76 void once (SV *fh, int events, SV *timeout, SV *cb)
556 root 1.75 CODE:
557 root 1.76 ev_once (
558     sv_fileno (fh), events,
559     SvOK (timeout) ? SvNV (timeout) : -1.,
560     e_once_cb,
561     newSVsv (cb)
562     );
563 root 1.15
564 root 1.1 PROTOTYPES: DISABLE
565    
566 root 1.15 MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
567 root 1.1
568 root 1.78 int ev_is_active (ev_watcher *w)
569 root 1.1
570 root 1.78 int ev_is_pending (ev_watcher *w)
571    
572 root 1.89 void ev_invoke (ev_watcher *w, int revents = EV_NONE)
573    
574     int ev_clear_pending (ev_watcher *w)
575    
576     void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
577    
578 root 1.78 int keepalive (ev_watcher *w, int new_value = 0)
579     CODE:
580     {
581     RETVAL = w->flags & WFLAG_KEEPALIVE;
582     new_value = new_value ? WFLAG_KEEPALIVE : 0;
583    
584     if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE))
585     {
586     REF (w);
587     w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value;
588     UNREF (w);
589     }
590     }
591     OUTPUT:
592     RETVAL
593    
594     SV *cb (ev_watcher *w, SV *new_cb = 0)
595 root 1.1 CODE:
596 root 1.15 {
597     RETVAL = newSVsv (w->cb_sv);
598    
599     if (items > 1)
600     sv_setsv (w->cb_sv, new_cb);
601     }
602 root 1.1 OUTPUT:
603     RETVAL
604    
605 root 1.78 SV *data (ev_watcher *w, SV *new_data = 0)
606 root 1.60 CODE:
607     {
608     RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
609 root 1.79
610     if (items > 1)
611     {
612     SvREFCNT_dec (w->data);
613     w->data = newSVsv (new_data);
614     }
615 root 1.60 }
616     OUTPUT:
617     RETVAL
618    
619 root 1.78 int priority (ev_watcher *w, int new_priority = 0)
620 root 1.41 CODE:
621     {
622     RETVAL = w->priority;
623    
624     if (items > 1)
625     {
626     int active = ev_is_active (w);
627    
628     if (active)
629     {
630     /* grrr. */
631     PUSHMARK (SP);
632     XPUSHs (ST (0));
633 root 1.87 PUTBACK;
634 root 1.41 call_method ("stop", G_DISCARD | G_VOID);
635     }
636    
637     ev_set_priority (w, new_priority);
638    
639     if (active)
640     {
641     PUSHMARK (SP);
642     XPUSHs (ST (0));
643 root 1.87 PUTBACK;
644 root 1.41 call_method ("start", G_DISCARD | G_VOID);
645     }
646     }
647     }
648     OUTPUT:
649     RETVAL
650    
651 root 1.78 MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_
652 root 1.1
653 root 1.78 void ev_io_start (ev_io *w)
654     CODE:
655     START (io, w);
656 root 1.1
657 root 1.78 void ev_io_stop (ev_io *w)
658     CODE:
659     STOP (io, w);
660 root 1.15
661 root 1.78 void DESTROY (ev_io *w)
662 root 1.26 CODE:
663 root 1.78 STOP (io, w);
664 root 1.34 e_destroy (w);
665 root 1.26
666 root 1.78 void set (ev_io *w, SV *fh, int events)
667 root 1.1 CODE:
668     {
669 root 1.31 int fd = sv_fileno (fh);
670     CHECK_FD (fh, fd);
671    
672 root 1.15 sv_setsv (w->fh, fh);
673 root 1.80 RESET (io, w, (w, fd, events));
674 root 1.15 }
675 root 1.1
676 root 1.78 SV *fh (ev_io *w, SV *new_fh = 0)
677 root 1.1 CODE:
678 root 1.15 {
679     if (items > 1)
680     {
681 root 1.80 int fd = sv_fileno (new_fh);
682     CHECK_FD (new_fh, fd);
683 root 1.1
684 root 1.80 RETVAL = w->fh;
685     w->fh = newSVsv (new_fh);
686 root 1.1
687 root 1.80 RESET (io, w, (w, fd, w->events));
688 root 1.15 }
689 root 1.80 else
690     RETVAL = newSVsv (w->fh);
691 root 1.15 }
692 root 1.1 OUTPUT:
693     RETVAL
694    
695 root 1.78 int events (ev_io *w, int new_events = EV_UNDEF)
696 root 1.1 CODE:
697 root 1.15 {
698     RETVAL = w->events;
699    
700     if (items > 1)
701 root 1.80 RESET (io, w, (w, w->fd, new_events));
702 root 1.15 }
703 root 1.1 OUTPUT:
704     RETVAL
705    
706 root 1.29 MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
707 root 1.15
708 root 1.78 void ev_signal_start (ev_signal *w)
709     CODE:
710     START (signal, w);
711 root 1.15
712 root 1.78 void ev_signal_stop (ev_signal *w)
713     CODE:
714     STOP (signal, w);
715 root 1.15
716 root 1.78 void DESTROY (ev_signal *w)
717 root 1.26 CODE:
718 root 1.78 STOP (signal, w);
719 root 1.34 e_destroy (w);
720 root 1.26
721 root 1.78 void set (ev_signal *w, SV *signal)
722 root 1.1 CODE:
723 root 1.15 {
724 root 1.80 Signal signum = sv_signum (signal);
725     CHECK_SIG (signal, signum);
726 root 1.39
727 root 1.80 RESET (signal, w, (w, signum));
728 root 1.15 }
729    
730 root 1.78 int signal (ev_signal *w, SV *new_signal = 0)
731 root 1.39 CODE:
732     {
733     RETVAL = w->signum;
734    
735     if (items > 1)
736     {
737 root 1.80 Signal signum = sv_signum (new_signal);
738     CHECK_SIG (new_signal, signum);
739 root 1.39
740 root 1.80 RESET (signal, w, (w, signum));
741 root 1.39 }
742     }
743     OUTPUT:
744     RETVAL
745    
746 root 1.29 MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
747 root 1.15
748 root 1.78 void ev_timer_start (ev_timer *w)
749 root 1.18 INIT:
750     CHECK_REPEAT (w->repeat);
751 root 1.78 CODE:
752     START (timer, w);
753 root 1.15
754 root 1.78 void ev_timer_stop (ev_timer *w)
755     CODE:
756     STOP (timer, w);
757 root 1.1
758 root 1.78 void ev_timer_again (ev_timer *w)
759 root 1.18 INIT:
760     CHECK_REPEAT (w->repeat);
761 root 1.78 CODE:
762     REF (w);
763     ev_timer_again (w);
764     UNREF (w);
765 root 1.17
766 root 1.78 void DESTROY (ev_timer *w)
767 root 1.26 CODE:
768 root 1.78 STOP (timer, w);
769 root 1.34 e_destroy (w);
770 root 1.26
771 root 1.78 void set (ev_timer *w, NV after, NV repeat = 0.)
772 root 1.18 INIT:
773     CHECK_REPEAT (repeat);
774 root 1.1 CODE:
775 root 1.80 RESET (timer, w, (w, after, repeat));
776 root 1.1
777 root 1.90 NV at (ev_timer *w)
778     CODE:
779     RETVAL = w->at;
780     OUTPUT:
781     RETVAL
782    
783 root 1.29 MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
784 root 1.15
785 root 1.78 void ev_periodic_start (ev_periodic *w)
786 root 1.18 INIT:
787     CHECK_REPEAT (w->interval);
788 root 1.78 CODE:
789     START (periodic, w);
790 root 1.1
791 root 1.78 void ev_periodic_stop (ev_periodic *w)
792     CODE:
793     STOP (periodic, w);
794 root 1.1
795 root 1.78 void ev_periodic_again (ev_periodic *w)
796     CODE:
797     REF (w);
798     ev_periodic_again (w);
799     UNREF (w);
800 root 1.59
801 root 1.78 void DESTROY (ev_periodic *w)
802 root 1.26 CODE:
803 root 1.78 STOP (periodic, w);
804 root 1.34 e_destroy (w);
805 root 1.26
806 root 1.78 void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
807 root 1.18 INIT:
808     CHECK_REPEAT (interval);
809 root 1.10 CODE:
810     {
811 root 1.59 SvREFCNT_dec (w->fh);
812     w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
813 root 1.39
814 root 1.80 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
815 root 1.15 }
816 root 1.10
817 root 1.90 NV at (ev_periodic *w)
818     CODE:
819     RETVAL = w->at;
820     OUTPUT:
821     RETVAL
822    
823 root 1.29 MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
824 root 1.10
825 root 1.78 void ev_idle_start (ev_idle *w)
826     CODE:
827     START (idle, w);
828 root 1.10
829 root 1.78 void ev_idle_stop (ev_idle *w)
830     CODE:
831     STOP (idle, w);
832 root 1.10
833 root 1.78 void DESTROY (ev_idle *w)
834 root 1.26 CODE:
835 root 1.78 STOP (idle, w);
836 root 1.34 e_destroy (w);
837 root 1.26
838 root 1.29 MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
839 root 1.22
840 root 1.78 void ev_prepare_start (ev_prepare *w)
841     CODE:
842     START (prepare, w);
843 root 1.22
844 root 1.78 void ev_prepare_stop (ev_prepare *w)
845     CODE:
846     STOP (prepare, w);
847 root 1.22
848 root 1.78 void DESTROY (ev_prepare *w)
849 root 1.26 CODE:
850 root 1.78 STOP (prepare, w);
851 root 1.34 e_destroy (w);
852 root 1.26
853 root 1.29 MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
854 root 1.1
855 root 1.78 void ev_check_start (ev_check *w)
856     CODE:
857     START (check, w);
858 root 1.1
859 root 1.78 void ev_check_stop (ev_check *w)
860     CODE:
861     STOP (check, w);
862 root 1.1
863 root 1.78 void DESTROY (ev_check *w)
864 root 1.26 CODE:
865 root 1.78 STOP (check, w);
866 root 1.34 e_destroy (w);
867 root 1.26
868 root 1.29 MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
869 root 1.23
870 root 1.78 void ev_child_start (ev_child *w)
871     CODE:
872     START (child, w);
873 root 1.23
874 root 1.78 void ev_child_stop (ev_child *w)
875     CODE:
876     STOP (child, w);
877 root 1.23
878 root 1.78 void DESTROY (ev_child *w)
879 root 1.26 CODE:
880 root 1.78 STOP (child, w);
881 root 1.34 e_destroy (w);
882 root 1.26
883 root 1.78 void set (ev_child *w, int pid)
884 root 1.23 CODE:
885 root 1.80 RESET (child, w, (w, pid));
886 root 1.23
887 root 1.78 int pid (ev_child *w, int new_pid = 0)
888 root 1.39 CODE:
889     {
890 root 1.40 RETVAL = w->pid;
891 root 1.39
892     if (items > 1)
893 root 1.80 RESET (child, w, (w, new_pid));
894 root 1.39 }
895     OUTPUT:
896     RETVAL
897    
898    
899 root 1.78 int rstatus (ev_child *w)
900 root 1.45 ALIAS:
901     rpid = 1
902 root 1.24 CODE:
903 root 1.45 RETVAL = ix ? w->rpid : w->rstatus;
904 root 1.24 OUTPUT:
905     RETVAL
906    
907 root 1.80 MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
908    
909     void ev_stat_start (ev_stat *w)
910     CODE:
911     START (stat, w);
912    
913     void ev_stat_stop (ev_stat *w)
914     CODE:
915     STOP (stat, w);
916    
917     void DESTROY (ev_stat *w)
918     CODE:
919     STOP (stat, w);
920     e_destroy (w);
921    
922     void set (ev_stat *w, SV *path, NV interval)
923     CODE:
924     {
925     sv_setsv (w->fh, path);
926     RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval));
927     }
928    
929     SV *path (ev_stat *w, SV *new_path = 0)
930     CODE:
931     {
932     RETVAL = SvREFCNT_inc (w->fh);
933    
934     if (items > 1)
935     {
936     SvREFCNT_dec (w->fh);
937     w->fh = newSVsv (new_path);
938     RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval));
939     }
940     }
941     OUTPUT:
942     RETVAL
943    
944     NV interval (ev_stat *w, NV new_interval = 0.)
945     CODE:
946     {
947     RETVAL = w->interval;
948    
949     if (items > 1)
950     RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval));
951     }
952     OUTPUT:
953     RETVAL
954    
955 root 1.82 void prev (ev_stat *w)
956     ALIAS:
957     stat = 1
958     attr = 2
959     PPCODE:
960     {
961     ev_statdata *s = ix ? &w->attr : &w->prev;
962    
963     if (ix == 1)
964     ev_stat_stat (w);
965     else if (!s->st_nlink)
966     errno = ENOENT;
967    
968     PL_statcache.st_dev = s->st_nlink;
969     PL_statcache.st_ino = s->st_ino;
970     PL_statcache.st_mode = s->st_mode;
971     PL_statcache.st_nlink = s->st_nlink;
972     PL_statcache.st_uid = s->st_uid;
973     PL_statcache.st_gid = s->st_gid;
974     PL_statcache.st_rdev = s->st_rdev;
975     PL_statcache.st_size = s->st_size;
976     PL_statcache.st_atime = s->st_atime;
977     PL_statcache.st_mtime = s->st_mtime;
978     PL_statcache.st_ctime = s->st_ctime;
979    
980     if (GIMME_V == G_SCALAR)
981     XPUSHs (boolSV (s->st_nlink));
982     else if (GIMME_V == G_ARRAY && s->st_nlink)
983     {
984     EXTEND (SP, 13);
985     PUSHs (sv_2mortal (newSViv (s->st_dev)));
986     PUSHs (sv_2mortal (newSViv (s->st_ino)));
987     PUSHs (sv_2mortal (newSVuv (s->st_mode)));
988     PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
989     PUSHs (sv_2mortal (newSViv (s->st_uid)));
990     PUSHs (sv_2mortal (newSViv (s->st_gid)));
991     PUSHs (sv_2mortal (newSViv (s->st_rdev)));
992     PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
993     PUSHs (sv_2mortal (newSVnv (s->st_atime)));
994     PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
995     PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
996     PUSHs (sv_2mortal (newSVuv (4096)));
997     PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
998     }
999     }
1000    
1001 root 1.36 #if 0
1002 root 1.5
1003     MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1004    
1005     BOOT:
1006     {
1007     HV *stash = gv_stashpv ("EV::HTTP", 1);
1008    
1009     static const struct {
1010     const char *name;
1011     IV iv;
1012     } *civ, const_iv[] = {
1013     # define const_iv(pfx, name) { # name, (IV) pfx ## name },
1014     const_iv (HTTP_, OK)
1015     const_iv (HTTP_, NOCONTENT)
1016     const_iv (HTTP_, MOVEPERM)
1017     const_iv (HTTP_, MOVETEMP)
1018     const_iv (HTTP_, NOTMODIFIED)
1019     const_iv (HTTP_, BADREQUEST)
1020     const_iv (HTTP_, NOTFOUND)
1021     const_iv (HTTP_, SERVUNAVAIL)
1022     const_iv (EVHTTP_, REQ_OWN_CONNECTION)
1023     const_iv (EVHTTP_, PROXY_REQUEST)
1024     const_iv (EVHTTP_, REQ_GET)
1025     const_iv (EVHTTP_, REQ_POST)
1026     const_iv (EVHTTP_, REQ_HEAD)
1027     const_iv (EVHTTP_, REQUEST)
1028     const_iv (EVHTTP_, RESPONSE)
1029     };
1030    
1031     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1032     newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1033     }
1034    
1035     MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
1036    
1037     #HttpRequest new (SV *klass, SV *cb)
1038    
1039     #void DESTROY (struct evhttp_request *req);
1040    
1041 root 1.15 #endif
1042    
1043 root 1.5
1044    
1045    
1046    
1047    
1048    
1049