ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
Revision: 1.36
Committed: Thu Nov 1 15:46:43 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
Changes since 1.35: +8 -4 lines
Log Message:
include evdns and re-enable build

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.15 #define TIMEOUT_NONE HUGE_VAL
8 root 1.1
9 root 1.20 #define EV_PROTOTYPES 1
10 root 1.11 #include "EV/EVAPI.h"
11    
12 root 1.16 #include "libev/ev.c"
13 root 1.36 #include "libev/event.h"
14     #include "libev/event.c"
15    
16     #define DNS_USE_GETTIMEOFDAY_FOR_ID 1
17     #define HAVE_STRUCT_IN6_ADDR 1
18     #define HAVE_STRTOK_R 1
19     #include "libev/evdns.c"
20 root 1.16
21 root 1.10 typedef int Signal;
22 root 1.1
23 root 1.11 static struct EVAPI evapi;
24    
25 root 1.15 static HV
26     *stash_watcher,
27     *stash_io,
28     *stash_timer,
29     *stash_periodic,
30     *stash_signal,
31     *stash_idle,
32 root 1.22 *stash_prepare,
33 root 1.23 *stash_check,
34     *stash_child;
35 root 1.1
36 root 1.10 static int
37     sv_signum (SV *sig)
38     {
39     int signum;
40    
41 root 1.31 SvGETMAGIC (sig);
42 root 1.10
43     for (signum = 1; signum < SIG_SIZE; ++signum)
44     if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
45     return signum;
46    
47 root 1.31 if (SvIV (sig) > 0)
48     return SvIV (sig);
49    
50 root 1.10 return -1;
51     }
52    
53 root 1.1 /////////////////////////////////////////////////////////////////////////////
54     // Event
55    
56 root 1.15 static void e_cb (struct ev_watcher *w, int revents);
57 root 1.1
58 root 1.15 static int
59     sv_fileno (SV *fh)
60 root 1.1 {
61 root 1.3 SvGETMAGIC (fh);
62 root 1.1
63 root 1.3 if (SvROK (fh))
64     fh = SvRV (fh);
65 root 1.1
66 root 1.3 if (SvTYPE (fh) == SVt_PVGV)
67     return PerlIO_fileno (IoIFP (sv_2io (fh)));
68 root 1.1
69 root 1.31 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff))
70 root 1.3 return SvIV (fh);
71 root 1.1
72     return -1;
73     }
74    
75 root 1.15 static void *
76     e_new (int size, SV *cb_sv)
77 root 1.1 {
78 root 1.15 struct ev_watcher *w;
79     SV *self = NEWSV (0, size);
80 root 1.1 SvPOK_only (self);
81 root 1.15 SvCUR_set (self, size);
82 root 1.1
83 root 1.15 w = (struct ev_watcher *)SvPVX (self);
84 root 1.1
85 root 1.29 ev_watcher_init (w, e_cb);
86 root 1.1
87 root 1.15 w->fh = 0;
88     w->cb_sv = newSVsv (cb_sv);
89     w->self = self;
90 root 1.1
91 root 1.15 return (void *)w;
92 root 1.1 }
93    
94 root 1.34 static void *
95     e_destroy (void *w_)
96     {
97     struct ev_watcher *w = w_;
98    
99     SvREFCNT_dec (w->fh ); w->fh = 0;
100     SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
101     }
102    
103 root 1.15 static SV *
104     e_bless (struct ev_watcher *w, HV *stash)
105 root 1.1 {
106     SV *rv;
107    
108 root 1.15 if (SvOBJECT (w->self))
109     rv = newRV_inc (w->self);
110 root 1.1 else
111     {
112 root 1.15 rv = newRV_noinc (w->self);
113     sv_bless (rv, stash);
114     SvREADONLY_on (w->self);
115 root 1.1 }
116    
117     return rv;
118     }
119    
120     static void
121 root 1.15 e_cb (struct ev_watcher *w, int revents)
122 root 1.1 {
123     dSP;
124 root 1.14 I32 mark = SP - PL_stack_base;
125 root 1.24 SV *sv_self, *sv_events, *sv_status = 0;
126 root 1.14 static SV *sv_events_cache;
127 root 1.1
128 root 1.15 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
129 root 1.14
130     if (sv_events_cache)
131     {
132     sv_events = sv_events_cache; sv_events_cache = 0;
133 root 1.15 SvIV_set (sv_events, revents);
134 root 1.14 }
135     else
136 root 1.15 sv_events = newSViv (revents);
137 root 1.14
138 root 1.1 PUSHMARK (SP);
139     EXTEND (SP, 2);
140 root 1.14 PUSHs (sv_self);
141     PUSHs (sv_events);
142 root 1.24
143     if (revents & EV_CHILD)
144     XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status));
145    
146 root 1.1 PUTBACK;
147 root 1.15 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
148 root 1.14 SP = PL_stack_base + mark; PUTBACK;
149    
150     SvREFCNT_dec (sv_self);
151 root 1.24 SvREFCNT_dec (sv_status);
152 root 1.14
153     if (sv_events_cache)
154     SvREFCNT_dec (sv_events);
155     else
156     sv_events_cache = sv_events;
157 root 1.1
158 root 1.8 if (SvTRUE (ERRSV))
159     {
160     PUSHMARK (SP);
161     PUTBACK;
162     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
163 root 1.14 SP = PL_stack_base + mark; PUTBACK;
164 root 1.8 }
165 root 1.1 }
166    
167     /////////////////////////////////////////////////////////////////////////////
168     // DNS
169    
170     static void
171     dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
172     {
173     dSP;
174     SV *cb = (SV *)arg;
175    
176     ENTER;
177     SAVETMPS;
178     PUSHMARK (SP);
179     EXTEND (SP, count + 3);
180     PUSHs (sv_2mortal (newSViv (result)));
181    
182     if (result == DNS_ERR_NONE && ttl >= 0)
183     {
184     int i;
185    
186     PUSHs (sv_2mortal (newSViv (type)));
187     PUSHs (sv_2mortal (newSViv (ttl)));
188    
189     for (i = 0; i < count; ++i)
190     switch (type)
191     {
192     case DNS_IPv6_AAAA:
193     PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16)));
194     break;
195     case DNS_IPv4_A:
196     PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4)));
197     break;
198     case DNS_PTR:
199     PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0)));
200     break;
201     }
202     }
203    
204     PUTBACK;
205     call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
206    
207     FREETMPS;
208 root 1.8
209     if (SvTRUE (ERRSV))
210     {
211     PUSHMARK (SP);
212     PUTBACK;
213     call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
214     }
215    
216 root 1.1 LEAVE;
217     }
218    
219 root 1.18 #define CHECK_REPEAT(repeat) if (repeat < 0.) \
220     croak (# repeat " value must be >= 0");
221    
222 root 1.31 #define CHECK_FD(fh,fd) if ((fd) < 0) \
223     croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
224    
225 root 1.1 /////////////////////////////////////////////////////////////////////////////
226     // XS interface functions
227    
228 root 1.15 MODULE = EV PACKAGE = EV PREFIX = ev_
229 root 1.1
230 root 1.21 PROTOTYPES: ENABLE
231    
232 root 1.1 BOOT:
233     {
234 root 1.10 int i;
235 root 1.1 HV *stash = gv_stashpv ("EV", 1);
236    
237     static const struct {
238     const char *name;
239     IV iv;
240     } *civ, const_iv[] = {
241     # define const_iv(pfx, name) { # name, (IV) pfx ## name },
242 root 1.20 const_iv (EV_, UNDEF)
243 root 1.1 const_iv (EV_, NONE)
244     const_iv (EV_, TIMEOUT)
245     const_iv (EV_, READ)
246     const_iv (EV_, WRITE)
247     const_iv (EV_, SIGNAL)
248 root 1.15 const_iv (EV_, IDLE)
249     const_iv (EV_, CHECK)
250 root 1.20 const_iv (EV_, ERROR)
251 root 1.15
252     const_iv (EV, LOOP_ONESHOT)
253 root 1.1 const_iv (EV, LOOP_NONBLOCK)
254 root 1.15
255     const_iv (EV, METHOD_NONE)
256     const_iv (EV, METHOD_SELECT)
257     const_iv (EV, METHOD_EPOLL)
258 root 1.1 };
259    
260     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
261     newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
262    
263 root 1.15 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
264 root 1.28 stash_io = gv_stashpv ("EV::Io" , 1);
265 root 1.15 stash_timer = gv_stashpv ("EV::Timer" , 1);
266     stash_periodic = gv_stashpv ("EV::Periodic", 1);
267     stash_signal = gv_stashpv ("EV::Signal" , 1);
268     stash_idle = gv_stashpv ("EV::Idle" , 1);
269 root 1.22 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
270 root 1.15 stash_check = gv_stashpv ("EV::Check" , 1);
271 root 1.23 stash_child = gv_stashpv ("EV::Child" , 1);
272 root 1.11
273     {
274     SV *sv = perl_get_sv ("EV::API", TRUE);
275     perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
276    
277 root 1.15 /* the poor man's shared library emulator */
278     evapi.ver = EV_API_VERSION;
279     evapi.rev = EV_API_REVISION;
280     evapi.sv_fileno = sv_fileno;
281     evapi.sv_signum = sv_signum;
282     evapi.now = &ev_now;
283     evapi.method = &ev_method;
284     evapi.loop_done = &ev_loop_done;
285     evapi.time = ev_time;
286     evapi.loop = ev_loop;
287 root 1.20 evapi.once = ev_once;
288 root 1.29 evapi.io_start = ev_io_start;
289     evapi.io_stop = ev_io_stop;
290     evapi.timer_start = ev_timer_start;
291     evapi.timer_stop = ev_timer_stop;
292     evapi.timer_again = ev_timer_again;
293     evapi.periodic_start = ev_periodic_start;
294     evapi.periodic_stop = ev_periodic_stop;
295     evapi.signal_start = ev_signal_start;
296     evapi.signal_stop = ev_signal_stop;
297     evapi.idle_start = ev_idle_start;
298     evapi.idle_stop = ev_idle_stop;
299     evapi.prepare_start = ev_prepare_start;
300     evapi.prepare_stop = ev_prepare_stop;
301     evapi.check_start = ev_check_start;
302     evapi.check_stop = ev_check_stop;
303     evapi.child_start = ev_child_start;
304     evapi.child_stop = ev_child_stop;
305 root 1.11
306     sv_setiv (sv, (IV)&evapi);
307     SvREADONLY_on (sv);
308     }
309 root 1.33
310     pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child);
311 root 1.1 }
312    
313 root 1.15 NV ev_now ()
314 root 1.1 CODE:
315 root 1.15 RETVAL = ev_now;
316 root 1.1 OUTPUT:
317     RETVAL
318    
319 root 1.15 int ev_method ()
320 root 1.1 CODE:
321 root 1.15 RETVAL = ev_method;
322 root 1.1 OUTPUT:
323     RETVAL
324    
325 root 1.15 NV ev_time ()
326 root 1.1
327 root 1.15 void ev_init (int flags = 0)
328 root 1.1
329 root 1.15 void ev_loop (int flags = 0)
330 root 1.1
331 root 1.15 void ev_loop_done (int value = 1)
332 root 1.1 CODE:
333 root 1.15 ev_loop_done = value;
334 root 1.1
335 root 1.15 struct ev_io *io (SV *fh, int events, SV *cb)
336     ALIAS:
337     io_ns = 1
338 root 1.1 CODE:
339 root 1.31 {
340     int fd = sv_fileno (fh);
341     CHECK_FD (fh, fd);
342    
343 root 1.15 RETVAL = e_new (sizeof (struct ev_io), cb);
344     RETVAL->fh = newSVsv (fh);
345 root 1.31 ev_io_set (RETVAL, fd, events);
346 root 1.29 if (!ix) ev_io_start (RETVAL);
347 root 1.31 }
348 root 1.1 OUTPUT:
349     RETVAL
350    
351 root 1.15 struct ev_timer *timer (NV after, NV repeat, SV *cb)
352 root 1.1 ALIAS:
353 root 1.15 timer_ns = 1
354 root 1.18 INIT:
355     CHECK_REPEAT (repeat);
356 root 1.1 CODE:
357 root 1.15 RETVAL = e_new (sizeof (struct ev_timer), cb);
358 root 1.29 ev_timer_set (RETVAL, after, repeat);
359     if (!ix) ev_timer_start (RETVAL);
360 root 1.1 OUTPUT:
361     RETVAL
362    
363 root 1.15 struct ev_periodic *periodic (NV at, NV interval, SV *cb)
364 root 1.9 ALIAS:
365 root 1.15 periodic_ns = 1
366 root 1.18 INIT:
367     CHECK_REPEAT (interval);
368 root 1.9 CODE:
369 root 1.15 RETVAL = e_new (sizeof (struct ev_periodic), cb);
370 root 1.29 ev_periodic_set (RETVAL, at, interval);
371     if (!ix) ev_periodic_start (RETVAL);
372 root 1.9 OUTPUT:
373     RETVAL
374    
375 root 1.15 struct ev_signal *signal (Signal signum, SV *cb)
376 root 1.1 ALIAS:
377 root 1.15 signal_ns = 1
378 root 1.1 CODE:
379 root 1.15 RETVAL = e_new (sizeof (struct ev_signal), cb);
380 root 1.29 ev_signal_set (RETVAL, signum);
381     if (!ix) ev_signal_start (RETVAL);
382 root 1.1 OUTPUT:
383     RETVAL
384    
385 root 1.15 struct ev_idle *idle (SV *cb)
386 root 1.1 ALIAS:
387 root 1.15 idle_ns = 1
388 root 1.1 CODE:
389 root 1.15 RETVAL = e_new (sizeof (struct ev_idle), cb);
390 root 1.29 ev_idle_set (RETVAL);
391     if (!ix) ev_idle_start (RETVAL);
392 root 1.1 OUTPUT:
393     RETVAL
394    
395 root 1.22 struct ev_prepare *prepare (SV *cb)
396     ALIAS:
397     prepare_ns = 1
398     CODE:
399     RETVAL = e_new (sizeof (struct ev_prepare), cb);
400 root 1.29 ev_prepare_set (RETVAL);
401     if (!ix) ev_prepare_start (RETVAL);
402 root 1.22 OUTPUT:
403     RETVAL
404    
405 root 1.15 struct ev_check *check (SV *cb)
406 root 1.1 ALIAS:
407 root 1.15 check_ns = 1
408 root 1.1 CODE:
409 root 1.15 RETVAL = e_new (sizeof (struct ev_check), cb);
410 root 1.29 ev_check_set (RETVAL);
411     if (!ix) ev_check_start (RETVAL);
412 root 1.1 OUTPUT:
413     RETVAL
414    
415 root 1.25 struct ev_child *child (int pid, SV *cb)
416 root 1.23 ALIAS:
417     check_ns = 1
418     CODE:
419     RETVAL = e_new (sizeof (struct ev_check), cb);
420 root 1.29 ev_child_set (RETVAL, pid);
421     if (!ix) ev_child_start (RETVAL);
422 root 1.23 OUTPUT:
423     RETVAL
424    
425 root 1.15
426 root 1.1 PROTOTYPES: DISABLE
427    
428 root 1.15 MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
429 root 1.1
430 root 1.15 int ev_is_active (struct ev_watcher *w)
431 root 1.1
432 root 1.15 SV *cb (struct ev_watcher *w, SV *new_cb = 0)
433 root 1.1 CODE:
434 root 1.15 {
435     RETVAL = newSVsv (w->cb_sv);
436    
437     if (items > 1)
438     sv_setsv (w->cb_sv, new_cb);
439     }
440 root 1.1 OUTPUT:
441     RETVAL
442    
443 root 1.28 void trigger (struct ev_watcher *w, int revents = EV_NONE)
444     CODE:
445     w->cb (w, revents);
446    
447 root 1.29 MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_
448 root 1.1
449 root 1.29 void ev_io_start (struct ev_io *w)
450 root 1.1
451 root 1.29 void ev_io_stop (struct ev_io *w)
452 root 1.15
453 root 1.26 void DESTROY (struct ev_io *w)
454     CODE:
455 root 1.29 ev_io_stop (w);
456 root 1.34 e_destroy (w);
457 root 1.26
458 root 1.15 void set (struct ev_io *w, SV *fh, int events)
459 root 1.1 CODE:
460     {
461 root 1.15 int active = w->active;
462 root 1.31 int fd = sv_fileno (fh);
463     CHECK_FD (fh, fd);
464    
465 root 1.29 if (active) ev_io_stop (w);
466 root 1.1
467 root 1.15 sv_setsv (w->fh, fh);
468 root 1.31 ev_io_set (w, fd, events);
469 root 1.1
470 root 1.29 if (active) ev_io_start (w);
471 root 1.15 }
472 root 1.1
473 root 1.15 SV *fh (struct ev_io *w, SV *new_fh = 0)
474 root 1.1 CODE:
475 root 1.15 {
476     RETVAL = newSVsv (w->fh);
477 root 1.1
478 root 1.15 if (items > 1)
479     {
480     int active = w->active;
481 root 1.29 if (active) ev_io_stop (w);
482 root 1.1
483 root 1.15 sv_setsv (w->fh, new_fh);
484 root 1.29 ev_io_set (w, sv_fileno (w->fh), w->events);
485 root 1.1
486 root 1.29 if (active) ev_io_start (w);
487 root 1.15 }
488     }
489 root 1.1 OUTPUT:
490     RETVAL
491    
492 root 1.15 short events (struct ev_io *w, short new_events = EV_UNDEF)
493 root 1.1 CODE:
494 root 1.15 {
495     RETVAL = w->events;
496    
497     if (items > 1)
498     {
499     int active = w->active;
500 root 1.29 if (active) ev_io_stop (w);
501 root 1.15
502 root 1.29 ev_io_set (w, w->fd, new_events);
503 root 1.15
504 root 1.29 if (active) ev_io_start (w);
505 root 1.15 }
506     }
507 root 1.1 OUTPUT:
508     RETVAL
509    
510 root 1.29 MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
511 root 1.15
512 root 1.29 void ev_signal_start (struct ev_signal *w)
513 root 1.15
514 root 1.29 void ev_signal_stop (struct ev_signal *w)
515 root 1.15
516 root 1.26 void DESTROY (struct ev_signal *w)
517     CODE:
518 root 1.29 ev_signal_stop (w);
519 root 1.34 e_destroy (w);
520 root 1.26
521 root 1.15 void set (struct ev_signal *w, SV *signal = 0)
522 root 1.1 CODE:
523 root 1.15 {
524     Signal signum = sv_signum (signal); /* may croak here */
525     int active = w->active;
526    
527 root 1.29 if (active) ev_signal_stop (w);
528     ev_signal_set (w, signum);
529     if (active) ev_signal_start (w);
530 root 1.15 }
531    
532     MODULE = EV PACKAGE = EV::Time
533    
534 root 1.29 MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
535 root 1.15
536 root 1.29 void ev_timer_start (struct ev_timer *w)
537 root 1.18 INIT:
538     CHECK_REPEAT (w->repeat);
539 root 1.15
540 root 1.29 void ev_timer_stop (struct ev_timer *w)
541 root 1.1
542 root 1.29 void ev_timer_again (struct ev_timer *w)
543 root 1.18 INIT:
544     CHECK_REPEAT (w->repeat);
545 root 1.17
546 root 1.26 void DESTROY (struct ev_timer *w)
547     CODE:
548 root 1.29 ev_timer_stop (w);
549 root 1.34 e_destroy (w);
550 root 1.26
551 root 1.15 void set (struct ev_timer *w, NV after, NV repeat = 0.)
552 root 1.18 INIT:
553     CHECK_REPEAT (repeat);
554 root 1.1 CODE:
555 root 1.15 {
556     int active = w->active;
557 root 1.29 if (active) ev_timer_stop (w);
558     ev_timer_set (w, after, repeat);
559     if (active) ev_timer_start (w);
560 root 1.15 }
561 root 1.1
562 root 1.29 MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
563 root 1.15
564 root 1.29 void ev_periodic_start (struct ev_periodic *w)
565 root 1.18 INIT:
566     CHECK_REPEAT (w->interval);
567 root 1.1
568 root 1.29 void ev_periodic_stop (struct ev_periodic *w)
569 root 1.1
570 root 1.26 void DESTROY (struct ev_periodic *w)
571     CODE:
572 root 1.29 ev_periodic_stop (w);
573 root 1.34 e_destroy (w);
574 root 1.26
575 root 1.15 void set (struct ev_periodic *w, NV at, NV interval = 0.)
576 root 1.18 INIT:
577     CHECK_REPEAT (interval);
578 root 1.10 CODE:
579     {
580 root 1.15 int active = w->active;
581 root 1.29 if (active) ev_periodic_stop (w);
582     ev_periodic_set (w, at, interval);
583     if (active) ev_periodic_start (w);
584 root 1.15 }
585 root 1.10
586 root 1.29 MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
587 root 1.10
588 root 1.29 void ev_idle_start (struct ev_idle *w)
589 root 1.10
590 root 1.29 void ev_idle_stop (struct ev_idle *w)
591 root 1.10
592 root 1.26 void DESTROY (struct ev_idle *w)
593     CODE:
594 root 1.29 ev_idle_stop (w);
595 root 1.34 e_destroy (w);
596 root 1.26
597 root 1.29 MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
598 root 1.22
599 root 1.29 void ev_prepare_start (struct ev_prepare *w)
600 root 1.22
601 root 1.29 void ev_prepare_stop (struct ev_prepare *w)
602 root 1.22
603 root 1.26 void DESTROY (struct ev_prepare *w)
604     CODE:
605 root 1.29 ev_prepare_stop (w);
606 root 1.34 e_destroy (w);
607 root 1.26
608 root 1.29 MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
609 root 1.1
610 root 1.29 void ev_check_start (struct ev_check *w)
611 root 1.1
612 root 1.29 void ev_check_stop (struct ev_check *w)
613 root 1.1
614 root 1.26 void DESTROY (struct ev_check *w)
615     CODE:
616 root 1.29 ev_check_stop (w);
617 root 1.34 e_destroy (w);
618 root 1.26
619 root 1.29 MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
620 root 1.23
621 root 1.29 void ev_child_start (struct ev_child *w)
622 root 1.23
623 root 1.29 void ev_child_stop (struct ev_child *w)
624 root 1.23
625 root 1.26 void DESTROY (struct ev_child *w)
626     CODE:
627 root 1.29 ev_child_stop (w);
628 root 1.34 e_destroy (w);
629 root 1.26
630 root 1.23 void set (struct ev_child *w, int pid)
631     CODE:
632     {
633     int active = w->active;
634 root 1.29 if (active) ev_child_stop (w);
635     ev_child_set (w, pid);
636     if (active) ev_child_start (w);
637 root 1.23 }
638    
639 root 1.24 int status (struct ev_child *w)
640     CODE:
641     RETVAL = w->status;
642     OUTPUT:
643     RETVAL
644    
645 root 1.1 MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
646    
647     BOOT:
648     {
649     HV *stash = gv_stashpv ("EV::DNS", 1);
650    
651     static const struct {
652     const char *name;
653     IV iv;
654     } *civ, const_iv[] = {
655     # define const_iv(pfx, name) { # name, (IV) pfx ## name },
656     const_iv (DNS_, ERR_NONE)
657     const_iv (DNS_, ERR_FORMAT)
658     const_iv (DNS_, ERR_SERVERFAILED)
659     const_iv (DNS_, ERR_NOTEXIST)
660     const_iv (DNS_, ERR_NOTIMPL)
661     const_iv (DNS_, ERR_REFUSED)
662     const_iv (DNS_, ERR_TRUNCATED)
663     const_iv (DNS_, ERR_UNKNOWN)
664     const_iv (DNS_, ERR_TIMEOUT)
665     const_iv (DNS_, ERR_SHUTDOWN)
666     const_iv (DNS_, IPv4_A)
667     const_iv (DNS_, PTR)
668     const_iv (DNS_, IPv6_AAAA)
669     const_iv (DNS_, QUERY_NO_SEARCH)
670     const_iv (DNS_, OPTION_SEARCH)
671     const_iv (DNS_, OPTION_NAMESERVERS)
672     const_iv (DNS_, OPTION_MISC)
673     const_iv (DNS_, OPTIONS_ALL)
674     const_iv (DNS_, NO_SEARCH)
675     };
676    
677     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
678     newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
679     }
680    
681     int evdns_init ()
682    
683     void evdns_shutdown (int fail_requests = 1)
684    
685     const char *evdns_err_to_string (int err)
686    
687     int evdns_nameserver_add (U32 address)
688    
689     int evdns_count_nameservers ()
690    
691     int evdns_clear_nameservers_and_suspend ()
692    
693     int evdns_resume ()
694    
695     int evdns_nameserver_ip_add (char *ip_as_string)
696    
697     int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
698     C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
699    
700     int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
701     C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
702    
703     int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
704     ALIAS:
705     evdns_resolve_reverse_ipv6 = 1
706     CODE:
707     {
708     STRLEN len;
709     char *data = SvPVbyte (addr, len);
710     if (len != (ix ? 16 : 4))
711 root 1.8 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
712 root 1.1
713     RETVAL = ix
714     ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
715     : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
716     }
717     OUTPUT:
718     RETVAL
719    
720     int evdns_set_option (char *option, char *val, int flags)
721    
722     int evdns_resolv_conf_parse (int flags, const char *filename)
723    
724     #ifdef MS_WINDOWS
725    
726     int evdns_config_windows_nameservers ()
727    
728     #endif
729    
730     void evdns_search_clear ()
731    
732     void evdns_search_add (char *domain)
733    
734     void evdns_search_ndots_set (int ndots)
735    
736 root 1.36 #if 0
737 root 1.5
738     MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
739    
740     BOOT:
741     {
742     HV *stash = gv_stashpv ("EV::HTTP", 1);
743    
744     static const struct {
745     const char *name;
746     IV iv;
747     } *civ, const_iv[] = {
748     # define const_iv(pfx, name) { # name, (IV) pfx ## name },
749     const_iv (HTTP_, OK)
750     const_iv (HTTP_, NOCONTENT)
751     const_iv (HTTP_, MOVEPERM)
752     const_iv (HTTP_, MOVETEMP)
753     const_iv (HTTP_, NOTMODIFIED)
754     const_iv (HTTP_, BADREQUEST)
755     const_iv (HTTP_, NOTFOUND)
756     const_iv (HTTP_, SERVUNAVAIL)
757     const_iv (EVHTTP_, REQ_OWN_CONNECTION)
758     const_iv (EVHTTP_, PROXY_REQUEST)
759     const_iv (EVHTTP_, REQ_GET)
760     const_iv (EVHTTP_, REQ_POST)
761     const_iv (EVHTTP_, REQ_HEAD)
762     const_iv (EVHTTP_, REQUEST)
763     const_iv (EVHTTP_, RESPONSE)
764     };
765    
766     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
767     newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
768     }
769    
770     MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
771    
772     #HttpRequest new (SV *klass, SV *cb)
773    
774     #void DESTROY (struct evhttp_request *req);
775    
776 root 1.15 #endif
777    
778 root 1.5
779    
780    
781    
782    
783    
784