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