ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.86
Committed: Mon Dec 3 13:41:24 2007 UTC (16 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-1_6
Changes since 1.85: +3 -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.11
409     sv_setiv (sv, (IV)&evapi);
410     SvREADONLY_on (sv);
411     }
412 root 1.64 #ifndef _WIN32
413 root 1.56 pthread_atfork (0, 0, ev_default_fork);
414     #endif
415 root 1.1 }
416    
417 root 1.15 NV ev_now ()
418 root 1.1
419 root 1.74 unsigned int ev_backend ()
420 root 1.1
421 root 1.15 NV ev_time ()
422 root 1.1
423 root 1.74 unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
424 root 1.1
425 root 1.86 unsigned int ev_loop_count ()
426    
427 root 1.15 void ev_loop (int flags = 0)
428 root 1.1
429 root 1.47 void ev_unloop (int how = 1)
430 root 1.1
431 root 1.78 ev_io *io (SV *fh, int events, SV *cb)
432 root 1.15 ALIAS:
433     io_ns = 1
434 root 1.1 CODE:
435 root 1.31 {
436     int fd = sv_fileno (fh);
437     CHECK_FD (fh, fd);
438    
439 root 1.78 RETVAL = e_new (sizeof (ev_io), cb);
440 root 1.15 RETVAL->fh = newSVsv (fh);
441 root 1.31 ev_io_set (RETVAL, fd, events);
442 root 1.78 if (!ix) START (io, RETVAL);
443 root 1.31 }
444 root 1.1 OUTPUT:
445     RETVAL
446    
447 root 1.78 ev_timer *timer (NV after, NV repeat, SV *cb)
448 root 1.1 ALIAS:
449 root 1.15 timer_ns = 1
450 root 1.18 INIT:
451     CHECK_REPEAT (repeat);
452 root 1.1 CODE:
453 root 1.78 RETVAL = e_new (sizeof (ev_timer), cb);
454 root 1.29 ev_timer_set (RETVAL, after, repeat);
455 root 1.78 if (!ix) START (timer, RETVAL);
456 root 1.1 OUTPUT:
457     RETVAL
458    
459 root 1.59 SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
460 root 1.9 ALIAS:
461 root 1.15 periodic_ns = 1
462 root 1.18 INIT:
463     CHECK_REPEAT (interval);
464 root 1.9 CODE:
465 root 1.59 {
466 root 1.78 ev_periodic *w;
467     w = e_new (sizeof (ev_periodic), cb);
468 root 1.60 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
469 root 1.59 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
470 root 1.78 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
471     if (!ix) START (periodic, w);
472 root 1.59 }
473 root 1.9 OUTPUT:
474     RETVAL
475    
476 root 1.80 ev_signal *signal (SV *signal, SV *cb)
477 root 1.1 ALIAS:
478 root 1.15 signal_ns = 1
479 root 1.1 CODE:
480 root 1.80 {
481     Signal signum = sv_signum (signal);
482     CHECK_SIG (signal, signum);
483    
484 root 1.78 RETVAL = e_new (sizeof (ev_signal), cb);
485 root 1.29 ev_signal_set (RETVAL, signum);
486 root 1.78 if (!ix) START (signal, RETVAL);
487 root 1.80 }
488 root 1.1 OUTPUT:
489     RETVAL
490    
491 root 1.78 ev_idle *idle (SV *cb)
492 root 1.1 ALIAS:
493 root 1.15 idle_ns = 1
494 root 1.1 CODE:
495 root 1.78 RETVAL = e_new (sizeof (ev_idle), cb);
496 root 1.29 ev_idle_set (RETVAL);
497 root 1.78 if (!ix) START (idle, RETVAL);
498 root 1.1 OUTPUT:
499     RETVAL
500    
501 root 1.78 ev_prepare *prepare (SV *cb)
502 root 1.22 ALIAS:
503     prepare_ns = 1
504     CODE:
505 root 1.78 RETVAL = e_new (sizeof (ev_prepare), cb);
506 root 1.29 ev_prepare_set (RETVAL);
507 root 1.78 if (!ix) START (prepare, RETVAL);
508 root 1.22 OUTPUT:
509     RETVAL
510    
511 root 1.78 ev_check *check (SV *cb)
512 root 1.1 ALIAS:
513 root 1.15 check_ns = 1
514 root 1.1 CODE:
515 root 1.78 RETVAL = e_new (sizeof (ev_check), cb);
516 root 1.29 ev_check_set (RETVAL);
517 root 1.78 if (!ix) START (check, RETVAL);
518 root 1.1 OUTPUT:
519     RETVAL
520    
521 root 1.78 ev_child *child (int pid, SV *cb)
522 root 1.23 ALIAS:
523 root 1.69 child_ns = 1
524 root 1.23 CODE:
525 root 1.78 RETVAL = e_new (sizeof (ev_child), cb);
526 root 1.29 ev_child_set (RETVAL, pid);
527 root 1.78 if (!ix) START (child, RETVAL);
528 root 1.23 OUTPUT:
529     RETVAL
530    
531 root 1.80 ev_stat *stat (SV *path, NV interval, SV *cb)
532     ALIAS:
533     stat_ns = 1
534     CODE:
535     RETVAL = e_new (sizeof (ev_stat), cb);
536     RETVAL->fh = newSVsv (path);
537     ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
538     if (!ix) START (stat, RETVAL);
539     OUTPUT:
540     RETVAL
541    
542 root 1.76 void once (SV *fh, int events, SV *timeout, SV *cb)
543 root 1.75 CODE:
544 root 1.76 ev_once (
545     sv_fileno (fh), events,
546     SvOK (timeout) ? SvNV (timeout) : -1.,
547     e_once_cb,
548     newSVsv (cb)
549     );
550 root 1.15
551 root 1.1 PROTOTYPES: DISABLE
552    
553 root 1.15 MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
554 root 1.1
555 root 1.78 int ev_is_active (ev_watcher *w)
556 root 1.1
557 root 1.78 int ev_is_pending (ev_watcher *w)
558    
559     int keepalive (ev_watcher *w, int new_value = 0)
560     CODE:
561     {
562     RETVAL = w->flags & WFLAG_KEEPALIVE;
563     new_value = new_value ? WFLAG_KEEPALIVE : 0;
564    
565     if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE))
566     {
567     REF (w);
568     w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value;
569     UNREF (w);
570     }
571     }
572     OUTPUT:
573     RETVAL
574    
575     SV *cb (ev_watcher *w, SV *new_cb = 0)
576 root 1.1 CODE:
577 root 1.15 {
578     RETVAL = newSVsv (w->cb_sv);
579    
580     if (items > 1)
581     sv_setsv (w->cb_sv, new_cb);
582     }
583 root 1.1 OUTPUT:
584     RETVAL
585    
586 root 1.78 SV *data (ev_watcher *w, SV *new_data = 0)
587 root 1.60 CODE:
588     {
589     RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
590 root 1.79
591     if (items > 1)
592     {
593     SvREFCNT_dec (w->data);
594     w->data = newSVsv (new_data);
595     }
596 root 1.60 }
597     OUTPUT:
598     RETVAL
599    
600 root 1.78 void trigger (ev_watcher *w, int revents = EV_NONE)
601 root 1.28 CODE:
602     w->cb (w, revents);
603    
604 root 1.78 int priority (ev_watcher *w, int new_priority = 0)
605 root 1.41 CODE:
606     {
607     RETVAL = w->priority;
608    
609     if (items > 1)
610     {
611     int active = ev_is_active (w);
612    
613     if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
614     croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
615    
616     if (active)
617     {
618     /* grrr. */
619     PUSHMARK (SP);
620     XPUSHs (ST (0));
621     call_method ("stop", G_DISCARD | G_VOID);
622     }
623    
624     ev_set_priority (w, new_priority);
625    
626     if (active)
627     {
628     PUSHMARK (SP);
629     XPUSHs (ST (0));
630     call_method ("start", G_DISCARD | G_VOID);
631     }
632     }
633     }
634     OUTPUT:
635     RETVAL
636    
637 root 1.78 MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_
638 root 1.1
639 root 1.78 void ev_io_start (ev_io *w)
640     CODE:
641     START (io, w);
642 root 1.1
643 root 1.78 void ev_io_stop (ev_io *w)
644     CODE:
645     STOP (io, w);
646 root 1.15
647 root 1.78 void DESTROY (ev_io *w)
648 root 1.26 CODE:
649 root 1.78 STOP (io, w);
650 root 1.34 e_destroy (w);
651 root 1.26
652 root 1.78 void set (ev_io *w, SV *fh, int events)
653 root 1.1 CODE:
654     {
655 root 1.31 int fd = sv_fileno (fh);
656     CHECK_FD (fh, fd);
657    
658 root 1.15 sv_setsv (w->fh, fh);
659 root 1.80 RESET (io, w, (w, fd, events));
660 root 1.15 }
661 root 1.1
662 root 1.78 SV *fh (ev_io *w, SV *new_fh = 0)
663 root 1.1 CODE:
664 root 1.15 {
665     if (items > 1)
666     {
667 root 1.80 int fd = sv_fileno (new_fh);
668     CHECK_FD (new_fh, fd);
669 root 1.1
670 root 1.80 RETVAL = w->fh;
671     w->fh = newSVsv (new_fh);
672 root 1.1
673 root 1.80 RESET (io, w, (w, fd, w->events));
674 root 1.15 }
675 root 1.80 else
676     RETVAL = newSVsv (w->fh);
677 root 1.15 }
678 root 1.1 OUTPUT:
679     RETVAL
680    
681 root 1.78 int events (ev_io *w, int new_events = EV_UNDEF)
682 root 1.1 CODE:
683 root 1.15 {
684     RETVAL = w->events;
685    
686     if (items > 1)
687 root 1.80 RESET (io, w, (w, w->fd, new_events));
688 root 1.15 }
689 root 1.1 OUTPUT:
690     RETVAL
691    
692 root 1.29 MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
693 root 1.15
694 root 1.78 void ev_signal_start (ev_signal *w)
695     CODE:
696     START (signal, w);
697 root 1.15
698 root 1.78 void ev_signal_stop (ev_signal *w)
699     CODE:
700     STOP (signal, w);
701 root 1.15
702 root 1.78 void DESTROY (ev_signal *w)
703 root 1.26 CODE:
704 root 1.78 STOP (signal, w);
705 root 1.34 e_destroy (w);
706 root 1.26
707 root 1.78 void set (ev_signal *w, SV *signal)
708 root 1.1 CODE:
709 root 1.15 {
710 root 1.80 Signal signum = sv_signum (signal);
711     CHECK_SIG (signal, signum);
712 root 1.39
713 root 1.80 RESET (signal, w, (w, signum));
714 root 1.15 }
715    
716 root 1.78 int signal (ev_signal *w, SV *new_signal = 0)
717 root 1.39 CODE:
718     {
719     RETVAL = w->signum;
720    
721     if (items > 1)
722     {
723 root 1.80 Signal signum = sv_signum (new_signal);
724     CHECK_SIG (new_signal, signum);
725 root 1.39
726 root 1.80 RESET (signal, w, (w, signum));
727 root 1.39 }
728     }
729     OUTPUT:
730     RETVAL
731    
732 root 1.29 MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
733 root 1.15
734 root 1.78 void ev_timer_start (ev_timer *w)
735 root 1.18 INIT:
736     CHECK_REPEAT (w->repeat);
737 root 1.78 CODE:
738     START (timer, w);
739 root 1.15
740 root 1.78 void ev_timer_stop (ev_timer *w)
741     CODE:
742     STOP (timer, w);
743 root 1.1
744 root 1.78 void ev_timer_again (ev_timer *w)
745 root 1.18 INIT:
746     CHECK_REPEAT (w->repeat);
747 root 1.78 CODE:
748     REF (w);
749     ev_timer_again (w);
750     UNREF (w);
751 root 1.17
752 root 1.78 void DESTROY (ev_timer *w)
753 root 1.26 CODE:
754 root 1.78 STOP (timer, w);
755 root 1.34 e_destroy (w);
756 root 1.26
757 root 1.78 void set (ev_timer *w, NV after, NV repeat = 0.)
758 root 1.18 INIT:
759     CHECK_REPEAT (repeat);
760 root 1.1 CODE:
761 root 1.80 RESET (timer, w, (w, after, repeat));
762 root 1.1
763 root 1.29 MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
764 root 1.15
765 root 1.78 void ev_periodic_start (ev_periodic *w)
766 root 1.18 INIT:
767     CHECK_REPEAT (w->interval);
768 root 1.78 CODE:
769     START (periodic, w);
770 root 1.1
771 root 1.78 void ev_periodic_stop (ev_periodic *w)
772     CODE:
773     STOP (periodic, w);
774 root 1.1
775 root 1.78 void ev_periodic_again (ev_periodic *w)
776     CODE:
777     REF (w);
778     ev_periodic_again (w);
779     UNREF (w);
780 root 1.59
781 root 1.78 void DESTROY (ev_periodic *w)
782 root 1.26 CODE:
783 root 1.78 STOP (periodic, w);
784 root 1.34 e_destroy (w);
785 root 1.26
786 root 1.78 void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
787 root 1.18 INIT:
788     CHECK_REPEAT (interval);
789 root 1.10 CODE:
790     {
791 root 1.59 SvREFCNT_dec (w->fh);
792     w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
793 root 1.39
794 root 1.80 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
795 root 1.15 }
796 root 1.10
797 root 1.29 MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
798 root 1.10
799 root 1.78 void ev_idle_start (ev_idle *w)
800     CODE:
801     START (idle, w);
802 root 1.10
803 root 1.78 void ev_idle_stop (ev_idle *w)
804     CODE:
805     STOP (idle, w);
806 root 1.10
807 root 1.78 void DESTROY (ev_idle *w)
808 root 1.26 CODE:
809 root 1.78 STOP (idle, w);
810 root 1.34 e_destroy (w);
811 root 1.26
812 root 1.29 MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
813 root 1.22
814 root 1.78 void ev_prepare_start (ev_prepare *w)
815     CODE:
816     START (prepare, w);
817 root 1.22
818 root 1.78 void ev_prepare_stop (ev_prepare *w)
819     CODE:
820     STOP (prepare, w);
821 root 1.22
822 root 1.78 void DESTROY (ev_prepare *w)
823 root 1.26 CODE:
824 root 1.78 STOP (prepare, w);
825 root 1.34 e_destroy (w);
826 root 1.26
827 root 1.29 MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
828 root 1.1
829 root 1.78 void ev_check_start (ev_check *w)
830     CODE:
831     START (check, w);
832 root 1.1
833 root 1.78 void ev_check_stop (ev_check *w)
834     CODE:
835     STOP (check, w);
836 root 1.1
837 root 1.78 void DESTROY (ev_check *w)
838 root 1.26 CODE:
839 root 1.78 STOP (check, w);
840 root 1.34 e_destroy (w);
841 root 1.26
842 root 1.29 MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
843 root 1.23
844 root 1.78 void ev_child_start (ev_child *w)
845     CODE:
846     START (child, w);
847 root 1.23
848 root 1.78 void ev_child_stop (ev_child *w)
849     CODE:
850     STOP (child, w);
851 root 1.23
852 root 1.78 void DESTROY (ev_child *w)
853 root 1.26 CODE:
854 root 1.78 STOP (child, w);
855 root 1.34 e_destroy (w);
856 root 1.26
857 root 1.78 void set (ev_child *w, int pid)
858 root 1.23 CODE:
859 root 1.80 RESET (child, w, (w, pid));
860 root 1.23
861 root 1.78 int pid (ev_child *w, int new_pid = 0)
862 root 1.39 CODE:
863     {
864 root 1.40 RETVAL = w->pid;
865 root 1.39
866     if (items > 1)
867 root 1.80 RESET (child, w, (w, new_pid));
868 root 1.39 }
869     OUTPUT:
870     RETVAL
871    
872    
873 root 1.78 int rstatus (ev_child *w)
874 root 1.45 ALIAS:
875     rpid = 1
876 root 1.24 CODE:
877 root 1.45 RETVAL = ix ? w->rpid : w->rstatus;
878 root 1.24 OUTPUT:
879     RETVAL
880    
881 root 1.80 MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
882    
883     void ev_stat_start (ev_stat *w)
884     CODE:
885     START (stat, w);
886    
887     void ev_stat_stop (ev_stat *w)
888     CODE:
889     STOP (stat, w);
890    
891     void DESTROY (ev_stat *w)
892     CODE:
893     STOP (stat, w);
894     e_destroy (w);
895    
896     void set (ev_stat *w, SV *path, NV interval)
897     CODE:
898     {
899     sv_setsv (w->fh, path);
900     RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval));
901     }
902    
903     SV *path (ev_stat *w, SV *new_path = 0)
904     CODE:
905     {
906     RETVAL = SvREFCNT_inc (w->fh);
907    
908     if (items > 1)
909     {
910     SvREFCNT_dec (w->fh);
911     w->fh = newSVsv (new_path);
912     RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval));
913     }
914     }
915     OUTPUT:
916     RETVAL
917    
918     NV interval (ev_stat *w, NV new_interval = 0.)
919     CODE:
920     {
921     RETVAL = w->interval;
922    
923     if (items > 1)
924     RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval));
925     }
926     OUTPUT:
927     RETVAL
928    
929 root 1.82 void prev (ev_stat *w)
930     ALIAS:
931     stat = 1
932     attr = 2
933     PPCODE:
934     {
935     ev_statdata *s = ix ? &w->attr : &w->prev;
936    
937     if (ix == 1)
938     ev_stat_stat (w);
939     else if (!s->st_nlink)
940     errno = ENOENT;
941    
942     PL_statcache.st_dev = s->st_nlink;
943     PL_statcache.st_ino = s->st_ino;
944     PL_statcache.st_mode = s->st_mode;
945     PL_statcache.st_nlink = s->st_nlink;
946     PL_statcache.st_uid = s->st_uid;
947     PL_statcache.st_gid = s->st_gid;
948     PL_statcache.st_rdev = s->st_rdev;
949     PL_statcache.st_size = s->st_size;
950     PL_statcache.st_atime = s->st_atime;
951     PL_statcache.st_mtime = s->st_mtime;
952     PL_statcache.st_ctime = s->st_ctime;
953    
954     if (GIMME_V == G_SCALAR)
955     XPUSHs (boolSV (s->st_nlink));
956     else if (GIMME_V == G_ARRAY && s->st_nlink)
957     {
958     EXTEND (SP, 13);
959     PUSHs (sv_2mortal (newSViv (s->st_dev)));
960     PUSHs (sv_2mortal (newSViv (s->st_ino)));
961     PUSHs (sv_2mortal (newSVuv (s->st_mode)));
962     PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
963     PUSHs (sv_2mortal (newSViv (s->st_uid)));
964     PUSHs (sv_2mortal (newSViv (s->st_gid)));
965     PUSHs (sv_2mortal (newSViv (s->st_rdev)));
966     PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
967     PUSHs (sv_2mortal (newSVnv (s->st_atime)));
968     PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
969     PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
970     PUSHs (sv_2mortal (newSVuv (4096)));
971     PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
972     }
973     }
974    
975 root 1.36 #if 0
976 root 1.5
977     MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
978    
979     BOOT:
980     {
981     HV *stash = gv_stashpv ("EV::HTTP", 1);
982    
983     static const struct {
984     const char *name;
985     IV iv;
986     } *civ, const_iv[] = {
987     # define const_iv(pfx, name) { # name, (IV) pfx ## name },
988     const_iv (HTTP_, OK)
989     const_iv (HTTP_, NOCONTENT)
990     const_iv (HTTP_, MOVEPERM)
991     const_iv (HTTP_, MOVETEMP)
992     const_iv (HTTP_, NOTMODIFIED)
993     const_iv (HTTP_, BADREQUEST)
994     const_iv (HTTP_, NOTFOUND)
995     const_iv (HTTP_, SERVUNAVAIL)
996     const_iv (EVHTTP_, REQ_OWN_CONNECTION)
997     const_iv (EVHTTP_, PROXY_REQUEST)
998     const_iv (EVHTTP_, REQ_GET)
999     const_iv (EVHTTP_, REQ_POST)
1000     const_iv (EVHTTP_, REQ_HEAD)
1001     const_iv (EVHTTP_, REQUEST)
1002     const_iv (EVHTTP_, RESPONSE)
1003     };
1004    
1005     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1006     newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1007     }
1008    
1009     MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
1010    
1011     #HttpRequest new (SV *klass, SV *cb)
1012    
1013     #void DESTROY (struct evhttp_request *req);
1014    
1015 root 1.15 #endif
1016    
1017 root 1.5
1018    
1019    
1020    
1021    
1022    
1023