ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
(Generate patch)

Comparing EV/EV.xs (file contents):
Revision 1.1 by root, Fri Oct 26 16:50:05 2007 UTC vs.
Revision 1.91 by root, Thu Dec 20 07:12:57 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines