… | |
… | |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | /*#include <netinet/in.h>*/ |
5 | /*#include <netinet/in.h>*/ |
6 | |
6 | |
7 | #define EV_PROTOTYPES 1 |
7 | #define EV_PROTOTYPES 1 |
|
|
8 | #define EV_H <ev.h> |
8 | #include "EV/EVAPI.h" |
9 | #include "EV/EVAPI.h" |
9 | |
10 | |
10 | /* fix perl api breakage */ |
11 | /* fix perl api breakage */ |
11 | #undef signal |
12 | #undef signal |
12 | #undef sigaction |
13 | #undef sigaction |
… | |
… | |
17 | # define NFDBITS PERL_NFDBITS |
18 | # define NFDBITS PERL_NFDBITS |
18 | # define fd_mask Perl_fd_mask |
19 | # define fd_mask Perl_fd_mask |
19 | #endif |
20 | #endif |
20 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
21 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
21 | #include "libev/ev.c" |
22 | #include "libev/ev.c" |
22 | #include "event.c" |
|
|
23 | |
|
|
24 | #ifndef _WIN32 |
|
|
25 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
|
|
26 | #if !defined (WIN32) && !defined(__CYGWIN__) |
|
|
27 | # define HAVE_STRUCT_IN6_ADDR 1 |
|
|
28 | #endif |
|
|
29 | #undef HAVE_STRTOK_R |
|
|
30 | #undef strtok_r |
|
|
31 | #define strtok_r fake_strtok_r |
|
|
32 | #include "evdns.h" |
|
|
33 | #include "evdns.c" |
|
|
34 | #endif |
|
|
35 | |
23 | |
36 | #ifndef _WIN32 |
24 | #ifndef _WIN32 |
37 | # include <pthread.h> |
25 | # include <pthread.h> |
38 | #endif |
26 | #endif |
39 | |
27 | |
40 | #define WFLAG_KEEPALIVE 1 |
28 | #define WFLAG_KEEPALIVE 1 |
41 | |
29 | |
42 | #define UNREF(w) \ |
30 | #define UNREF(w) \ |
43 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
31 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
44 | && !ev_is_active (w)) \ |
32 | && !ev_is_active (w)) \ |
45 | ev_unref (); |
33 | ev_unref (w->loop); |
46 | |
34 | |
47 | #define REF(w) \ |
35 | #define REF(w) \ |
48 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
36 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
49 | && ev_is_active (w)) \ |
37 | && ev_is_active (w)) \ |
50 | ev_ref (); |
38 | ev_ref (w->loop); |
51 | |
39 | |
52 | #define START(type,w) \ |
40 | #define START(type,w) \ |
53 | do { \ |
41 | do { \ |
54 | UNREF (w); \ |
42 | UNREF (w); \ |
55 | ev_ ## type ## _start (w); \ |
43 | ev_ ## type ## _start (w->loop, w); \ |
56 | } while (0) |
44 | } while (0) |
57 | |
45 | |
58 | #define STOP(type,w) \ |
46 | #define STOP(type,w) \ |
59 | do { \ |
47 | do { \ |
60 | REF (w); \ |
48 | REF (w); \ |
61 | ev_ ## type ## _stop (w); \ |
49 | ev_ ## type ## _stop (w->loop, w); \ |
62 | } while (0) |
50 | } while (0) |
63 | |
51 | |
64 | #define RESET(type,w,seta) \ |
52 | #define RESET(type,w,seta) \ |
65 | do { \ |
53 | do { \ |
66 | int active = ev_is_active (w); \ |
54 | int active = ev_is_active (w); \ |
… | |
… | |
113 | } |
101 | } |
114 | |
102 | |
115 | ///////////////////////////////////////////////////////////////////////////// |
103 | ///////////////////////////////////////////////////////////////////////////// |
116 | // Event |
104 | // Event |
117 | |
105 | |
118 | static void e_cb (ev_watcher *w, int revents); |
106 | static void e_cb (EV_P_ ev_watcher *w, int revents); |
119 | |
107 | |
120 | static int |
108 | static int |
121 | sv_fileno (SV *fh) |
109 | sv_fileno (SV *fh) |
122 | { |
110 | { |
123 | SvGETMAGIC (fh); |
111 | SvGETMAGIC (fh); |
… | |
… | |
144 | |
132 | |
145 | w = (ev_watcher *)SvPVX (self); |
133 | w = (ev_watcher *)SvPVX (self); |
146 | |
134 | |
147 | ev_init (w, e_cb); |
135 | ev_init (w, e_cb); |
148 | |
136 | |
|
|
137 | w->loop = EV_DEFAULT; |
149 | w->flags = WFLAG_KEEPALIVE; |
138 | w->flags = WFLAG_KEEPALIVE; |
150 | w->data = 0; |
139 | w->data = 0; |
151 | w->fh = 0; |
140 | w->fh = 0; |
152 | w->cb_sv = newSVsv (cb_sv); |
141 | w->cb_sv = newSVsv (cb_sv); |
153 | w->self = self; |
142 | w->self = self; |
… | |
… | |
183 | } |
172 | } |
184 | |
173 | |
185 | static SV *sv_events_cache; |
174 | static SV *sv_events_cache; |
186 | |
175 | |
187 | static void |
176 | static void |
188 | e_cb (ev_watcher *w, int revents) |
177 | e_cb (EV_P_ ev_watcher *w, int revents) |
189 | { |
178 | { |
190 | dSP; |
179 | dSP; |
191 | I32 mark = SP - PL_stack_base; |
180 | I32 mark = SP - PL_stack_base; |
192 | SV *sv_self, *sv_events; |
181 | SV *sv_self, *sv_events; |
193 | |
182 | |
… | |
… | |
216 | else |
205 | else |
217 | sv_events_cache = sv_events; |
206 | sv_events_cache = sv_events; |
218 | |
207 | |
219 | if (SvTRUE (ERRSV)) |
208 | if (SvTRUE (ERRSV)) |
220 | { |
209 | { |
|
|
210 | SPAGAIN; |
221 | PUSHMARK (SP); |
211 | PUSHMARK (SP); |
222 | PUTBACK; |
212 | PUTBACK; |
223 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
213 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
224 | } |
214 | } |
225 | |
215 | |
… | |
… | |
255 | else |
245 | else |
256 | sv_events_cache = sv_events; |
246 | sv_events_cache = sv_events; |
257 | |
247 | |
258 | if (SvTRUE (ERRSV)) |
248 | if (SvTRUE (ERRSV)) |
259 | { |
249 | { |
|
|
250 | SPAGAIN; |
260 | PUSHMARK (SP); |
251 | PUSHMARK (SP); |
261 | PUTBACK; |
252 | PUTBACK; |
262 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
253 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
263 | } |
254 | } |
264 | |
255 | |
… | |
… | |
306 | FREETMPS; |
297 | FREETMPS; |
307 | LEAVE; |
298 | LEAVE; |
308 | |
299 | |
309 | return retval; |
300 | return retval; |
310 | } |
301 | } |
311 | |
|
|
312 | ///////////////////////////////////////////////////////////////////////////// |
|
|
313 | // DNS |
|
|
314 | |
|
|
315 | #ifndef _WIN32 |
|
|
316 | static void |
|
|
317 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
|
|
318 | { |
|
|
319 | dSP; |
|
|
320 | SV *cb = (SV *)arg; |
|
|
321 | |
|
|
322 | ENTER; |
|
|
323 | SAVETMPS; |
|
|
324 | PUSHMARK (SP); |
|
|
325 | EXTEND (SP, count + 3); |
|
|
326 | PUSHs (sv_2mortal (newSViv (result))); |
|
|
327 | |
|
|
328 | if (result == DNS_ERR_NONE && ttl >= 0) |
|
|
329 | { |
|
|
330 | int i; |
|
|
331 | |
|
|
332 | PUSHs (sv_2mortal (newSViv (type))); |
|
|
333 | PUSHs (sv_2mortal (newSViv (ttl))); |
|
|
334 | |
|
|
335 | for (i = 0; i < count; ++i) |
|
|
336 | switch (type) |
|
|
337 | { |
|
|
338 | case DNS_IPv6_AAAA: |
|
|
339 | PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16))); |
|
|
340 | break; |
|
|
341 | case DNS_IPv4_A: |
|
|
342 | PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4))); |
|
|
343 | break; |
|
|
344 | case DNS_PTR: |
|
|
345 | PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0))); |
|
|
346 | break; |
|
|
347 | } |
|
|
348 | } |
|
|
349 | |
|
|
350 | PUTBACK; |
|
|
351 | call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); |
|
|
352 | |
|
|
353 | FREETMPS; |
|
|
354 | |
|
|
355 | if (SvTRUE (ERRSV)) |
|
|
356 | { |
|
|
357 | PUSHMARK (SP); |
|
|
358 | PUTBACK; |
|
|
359 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
360 | } |
|
|
361 | |
|
|
362 | LEAVE; |
|
|
363 | } |
|
|
364 | #endif |
|
|
365 | |
302 | |
366 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
303 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
367 | croak (# repeat " value must be >= 0"); |
304 | croak (# repeat " value must be >= 0"); |
368 | |
305 | |
369 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
306 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
412 | const_iv (EV, BACKEND_KQUEUE) |
349 | const_iv (EV, BACKEND_KQUEUE) |
413 | const_iv (EV, BACKEND_DEVPOLL) |
350 | const_iv (EV, BACKEND_DEVPOLL) |
414 | const_iv (EV, BACKEND_PORT) |
351 | const_iv (EV, BACKEND_PORT) |
415 | const_iv (EV, FLAG_AUTO) |
352 | const_iv (EV, FLAG_AUTO) |
416 | const_iv (EV, FLAG_NOENV) |
353 | const_iv (EV, FLAG_NOENV) |
|
|
354 | const_iv (EV, FLAG_FORKCHECK) |
417 | }; |
355 | }; |
418 | |
356 | |
419 | 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; ) |
420 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
358 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
421 | |
359 | |
… | |
… | |
428 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
366 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
429 | stash_check = gv_stashpv ("EV::Check" , 1); |
367 | stash_check = gv_stashpv ("EV::Check" , 1); |
430 | stash_child = gv_stashpv ("EV::Child" , 1); |
368 | stash_child = gv_stashpv ("EV::Child" , 1); |
431 | stash_embed = gv_stashpv ("EV::Embed" , 1); |
369 | stash_embed = gv_stashpv ("EV::Embed" , 1); |
432 | stash_stat = gv_stashpv ("EV::Stat" , 1); |
370 | stash_stat = gv_stashpv ("EV::Stat" , 1); |
|
|
371 | stash_fork = gv_stashpv ("EV::Fork" , 1); |
433 | |
372 | |
434 | { |
373 | { |
435 | SV *sv = perl_get_sv ("EV::API", TRUE); |
374 | SV *sv = perl_get_sv ("EV::API", TRUE); |
436 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
375 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
437 | |
376 | |
438 | /* the poor man's shared library emulator */ |
377 | /* the poor man's shared library emulator */ |
439 | evapi.ver = EV_API_VERSION; |
378 | evapi.ver = EV_API_VERSION; |
440 | evapi.rev = EV_API_REVISION; |
379 | evapi.rev = EV_API_REVISION; |
441 | evapi.sv_fileno = sv_fileno; |
380 | evapi.sv_fileno = sv_fileno; |
442 | evapi.sv_signum = sv_signum; |
381 | evapi.sv_signum = sv_signum; |
|
|
382 | evapi.supported_backends = ev_supported_backends (); |
|
|
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; |
443 | evapi.now = ev_now; |
390 | evapi.now = ev_now; |
444 | evapi.backend = ev_backend; |
391 | evapi.backend = ev_backend; |
445 | evapi.unloop = ev_unloop; |
392 | evapi.unloop = ev_unloop; |
446 | evapi.ref = ev_ref; |
393 | evapi.ref = ev_ref; |
447 | evapi.unref = ev_unref; |
394 | evapi.unref = ev_unref; |
448 | evapi.time = ev_time; |
|
|
449 | evapi.loop = ev_loop; |
395 | evapi.loop = ev_loop; |
450 | evapi.once = ev_once; |
396 | evapi.once = ev_once; |
451 | evapi.io_start = ev_io_start; |
397 | evapi.io_start = ev_io_start; |
452 | evapi.io_stop = ev_io_stop; |
398 | evapi.io_stop = ev_io_stop; |
453 | evapi.timer_start = ev_timer_start; |
399 | evapi.timer_start = ev_timer_start; |
454 | evapi.timer_stop = ev_timer_stop; |
400 | evapi.timer_stop = ev_timer_stop; |
455 | evapi.timer_again = ev_timer_again; |
401 | evapi.timer_again = ev_timer_again; |
456 | evapi.periodic_start = ev_periodic_start; |
402 | evapi.periodic_start = ev_periodic_start; |
457 | evapi.periodic_stop = ev_periodic_stop; |
403 | evapi.periodic_stop = ev_periodic_stop; |
458 | evapi.signal_start = ev_signal_start; |
404 | evapi.signal_start = ev_signal_start; |
459 | evapi.signal_stop = ev_signal_stop; |
405 | evapi.signal_stop = ev_signal_stop; |
460 | evapi.idle_start = ev_idle_start; |
406 | evapi.idle_start = ev_idle_start; |
461 | evapi.idle_stop = ev_idle_stop; |
407 | evapi.idle_stop = ev_idle_stop; |
462 | evapi.prepare_start = ev_prepare_start; |
408 | evapi.prepare_start = ev_prepare_start; |
463 | evapi.prepare_stop = ev_prepare_stop; |
409 | evapi.prepare_stop = ev_prepare_stop; |
464 | evapi.check_start = ev_check_start; |
410 | evapi.check_start = ev_check_start; |
465 | evapi.check_stop = ev_check_stop; |
411 | evapi.check_stop = ev_check_stop; |
466 | evapi.child_start = ev_child_start; |
412 | evapi.child_start = ev_child_start; |
467 | evapi.child_stop = ev_child_stop; |
413 | evapi.child_stop = ev_child_stop; |
468 | evapi.stat_start = ev_stat_start; |
414 | evapi.stat_start = ev_stat_start; |
469 | evapi.stat_stop = ev_stat_stop; |
415 | evapi.stat_stop = ev_stat_stop; |
470 | evapi.stat_stat = ev_stat_stat; |
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; |
471 | |
424 | |
472 | sv_setiv (sv, (IV)&evapi); |
425 | sv_setiv (sv, (IV)&evapi); |
473 | SvREADONLY_on (sv); |
426 | SvREADONLY_on (sv); |
474 | } |
427 | } |
475 | #ifndef _WIN32 |
428 | #ifndef _WIN32 |
476 | pthread_atfork (0, 0, ev_default_fork); |
429 | pthread_atfork (0, 0, ev_default_fork); |
477 | #endif |
430 | #endif |
478 | } |
431 | } |
479 | |
432 | |
|
|
433 | SV *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; |
|
|
439 | |
|
|
440 | RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))), |
|
|
441 | gv_stashpv ("EV::Loop::Default", 1)); |
|
|
442 | } |
|
|
443 | OUTPUT: |
|
|
444 | RETVAL |
|
|
445 | |
|
|
446 | NV ev_time () |
|
|
447 | |
480 | NV ev_now () |
448 | NV ev_now () |
|
|
449 | C_ARGS: evapi.default_loop |
481 | |
450 | |
482 | unsigned int ev_backend () |
451 | unsigned int ev_backend () |
|
|
452 | C_ARGS: evapi.default_loop |
483 | |
453 | |
484 | NV ev_time () |
454 | unsigned int ev_loop_count () |
485 | |
455 | C_ARGS: evapi.default_loop |
486 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
|
|
487 | |
456 | |
488 | void ev_loop (int flags = 0) |
457 | void ev_loop (int flags = 0) |
|
|
458 | C_ARGS: evapi.default_loop, flags |
489 | |
459 | |
490 | void ev_unloop (int how = 1) |
460 | void ev_unloop (int how = 1) |
|
|
461 | C_ARGS: evapi.default_loop, how |
|
|
462 | |
|
|
463 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
|
|
464 | C_ARGS: evapi.default_loop, fd, revents |
|
|
465 | |
|
|
466 | void 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 | } |
491 | |
474 | |
492 | ev_io *io (SV *fh, int events, SV *cb) |
475 | ev_io *io (SV *fh, int events, SV *cb) |
493 | ALIAS: |
476 | ALIAS: |
494 | io_ns = 1 |
477 | io_ns = 1 |
495 | CODE: |
478 | CODE: |
… | |
… | |
577 | ev_check_set (RETVAL); |
560 | ev_check_set (RETVAL); |
578 | if (!ix) START (check, RETVAL); |
561 | if (!ix) START (check, RETVAL); |
579 | OUTPUT: |
562 | OUTPUT: |
580 | RETVAL |
563 | RETVAL |
581 | |
564 | |
|
|
565 | ev_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 | |
582 | ev_child *child (int pid, SV *cb) |
575 | ev_child *child (int pid, SV *cb) |
583 | ALIAS: |
576 | ALIAS: |
584 | child_ns = 1 |
577 | child_ns = 1 |
585 | CODE: |
578 | CODE: |
586 | RETVAL = e_new (sizeof (ev_child), cb); |
579 | RETVAL = e_new (sizeof (ev_child), cb); |
… | |
… | |
601 | RETVAL |
594 | RETVAL |
602 | |
595 | |
603 | void once (SV *fh, int events, SV *timeout, SV *cb) |
596 | void once (SV *fh, int events, SV *timeout, SV *cb) |
604 | CODE: |
597 | CODE: |
605 | ev_once ( |
598 | ev_once ( |
|
|
599 | evapi.default_loop, |
606 | sv_fileno (fh), events, |
600 | sv_fileno (fh), events, |
607 | SvOK (timeout) ? SvNV (timeout) : -1., |
601 | SvOK (timeout) ? SvNV (timeout) : -1., |
608 | e_once_cb, |
602 | e_once_cb, |
609 | newSVsv (cb) |
603 | newSVsv (cb) |
610 | ); |
604 | ); |
… | |
… | |
614 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
608 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
615 | |
609 | |
616 | int ev_is_active (ev_watcher *w) |
610 | int ev_is_active (ev_watcher *w) |
617 | |
611 | |
618 | int ev_is_pending (ev_watcher *w) |
612 | int ev_is_pending (ev_watcher *w) |
|
|
613 | |
|
|
614 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
|
|
615 | C_ARGS: w->loop, w, revents |
|
|
616 | |
|
|
617 | int ev_clear_pending (ev_watcher *w) |
|
|
618 | C_ARGS: w->loop, w |
|
|
619 | |
|
|
620 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
|
|
621 | C_ARGS: w->loop, w, revents |
619 | |
622 | |
620 | int keepalive (ev_watcher *w, int new_value = 0) |
623 | int keepalive (ev_watcher *w, int new_value = 0) |
621 | CODE: |
624 | CODE: |
622 | { |
625 | { |
623 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
626 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
… | |
… | |
656 | } |
659 | } |
657 | } |
660 | } |
658 | OUTPUT: |
661 | OUTPUT: |
659 | RETVAL |
662 | RETVAL |
660 | |
663 | |
661 | void trigger (ev_watcher *w, int revents = EV_NONE) |
|
|
662 | CODE: |
|
|
663 | w->cb (w, revents); |
|
|
664 | |
|
|
665 | int priority (ev_watcher *w, int new_priority = 0) |
664 | int priority (ev_watcher *w, int new_priority = 0) |
666 | CODE: |
665 | CODE: |
667 | { |
666 | { |
668 | RETVAL = w->priority; |
667 | RETVAL = w->priority; |
669 | |
668 | |
670 | if (items > 1) |
669 | if (items > 1) |
671 | { |
670 | { |
672 | int active = ev_is_active (w); |
671 | int active = ev_is_active (w); |
673 | |
|
|
674 | if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI) |
|
|
675 | croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI); |
|
|
676 | |
672 | |
677 | if (active) |
673 | if (active) |
678 | { |
674 | { |
679 | /* grrr. */ |
675 | /* grrr. */ |
680 | PUSHMARK (SP); |
676 | PUSHMARK (SP); |
681 | XPUSHs (ST (0)); |
677 | XPUSHs (ST (0)); |
|
|
678 | PUTBACK; |
682 | call_method ("stop", G_DISCARD | G_VOID); |
679 | call_method ("stop", G_DISCARD | G_VOID); |
683 | } |
680 | } |
684 | |
681 | |
685 | ev_set_priority (w, new_priority); |
682 | ev_set_priority (w, new_priority); |
686 | |
683 | |
687 | if (active) |
684 | if (active) |
688 | { |
685 | { |
689 | PUSHMARK (SP); |
686 | PUSHMARK (SP); |
690 | XPUSHs (ST (0)); |
687 | XPUSHs (ST (0)); |
|
|
688 | PUTBACK; |
691 | call_method ("start", G_DISCARD | G_VOID); |
689 | call_method ("start", G_DISCARD | G_VOID); |
692 | } |
690 | } |
693 | } |
691 | } |
694 | } |
692 | } |
695 | OUTPUT: |
693 | OUTPUT: |
… | |
… | |
805 | void ev_timer_again (ev_timer *w) |
803 | void ev_timer_again (ev_timer *w) |
806 | INIT: |
804 | INIT: |
807 | CHECK_REPEAT (w->repeat); |
805 | CHECK_REPEAT (w->repeat); |
808 | CODE: |
806 | CODE: |
809 | REF (w); |
807 | REF (w); |
810 | ev_timer_again (w); |
808 | ev_timer_again (w->loop, w); |
811 | UNREF (w); |
809 | UNREF (w); |
812 | |
810 | |
813 | void DESTROY (ev_timer *w) |
811 | void DESTROY (ev_timer *w) |
814 | CODE: |
812 | CODE: |
815 | STOP (timer, w); |
813 | STOP (timer, w); |
… | |
… | |
819 | INIT: |
817 | INIT: |
820 | CHECK_REPEAT (repeat); |
818 | CHECK_REPEAT (repeat); |
821 | CODE: |
819 | CODE: |
822 | RESET (timer, w, (w, after, repeat)); |
820 | RESET (timer, w, (w, after, repeat)); |
823 | |
821 | |
|
|
822 | NV at (ev_timer *w) |
|
|
823 | CODE: |
|
|
824 | RETVAL = w->at; |
|
|
825 | OUTPUT: |
|
|
826 | RETVAL |
|
|
827 | |
824 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
828 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
825 | |
829 | |
826 | void ev_periodic_start (ev_periodic *w) |
830 | void ev_periodic_start (ev_periodic *w) |
827 | INIT: |
831 | INIT: |
828 | CHECK_REPEAT (w->interval); |
832 | CHECK_REPEAT (w->interval); |
… | |
… | |
834 | STOP (periodic, w); |
838 | STOP (periodic, w); |
835 | |
839 | |
836 | void ev_periodic_again (ev_periodic *w) |
840 | void ev_periodic_again (ev_periodic *w) |
837 | CODE: |
841 | CODE: |
838 | REF (w); |
842 | REF (w); |
839 | ev_periodic_again (w); |
843 | ev_periodic_again (w->loop, w); |
840 | UNREF (w); |
844 | UNREF (w); |
841 | |
845 | |
842 | void DESTROY (ev_periodic *w) |
846 | void DESTROY (ev_periodic *w) |
843 | CODE: |
847 | CODE: |
844 | STOP (periodic, w); |
848 | STOP (periodic, w); |
… | |
… | |
853 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
857 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
854 | |
858 | |
855 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
859 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
856 | } |
860 | } |
857 | |
861 | |
|
|
862 | NV at (ev_periodic *w) |
|
|
863 | CODE: |
|
|
864 | RETVAL = w->at; |
|
|
865 | OUTPUT: |
|
|
866 | RETVAL |
|
|
867 | |
858 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
868 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
859 | |
869 | |
860 | void ev_idle_start (ev_idle *w) |
870 | void ev_idle_start (ev_idle *w) |
861 | CODE: |
871 | CODE: |
862 | START (idle, w); |
872 | START (idle, w); |
… | |
… | |
896 | STOP (check, w); |
906 | STOP (check, w); |
897 | |
907 | |
898 | void DESTROY (ev_check *w) |
908 | void DESTROY (ev_check *w) |
899 | CODE: |
909 | CODE: |
900 | STOP (check, w); |
910 | STOP (check, w); |
|
|
911 | e_destroy (w); |
|
|
912 | |
|
|
913 | MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_ |
|
|
914 | |
|
|
915 | void ev_fork_start (ev_fork *w) |
|
|
916 | CODE: |
|
|
917 | START (fork, w); |
|
|
918 | |
|
|
919 | void ev_fork_stop (ev_fork *w) |
|
|
920 | CODE: |
|
|
921 | STOP (fork, w); |
|
|
922 | |
|
|
923 | void DESTROY (ev_fork *w) |
|
|
924 | CODE: |
|
|
925 | STOP (fork, w); |
901 | e_destroy (w); |
926 | e_destroy (w); |
902 | |
927 | |
903 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
928 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
904 | |
929 | |
905 | void ev_child_start (ev_child *w) |
930 | void ev_child_start (ev_child *w) |
… | |
… | |
985 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
1010 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
986 | } |
1011 | } |
987 | OUTPUT: |
1012 | OUTPUT: |
988 | RETVAL |
1013 | RETVAL |
989 | |
1014 | |
990 | #ifndef _WIN32 |
1015 | void prev (ev_stat *w) |
991 | |
|
|
992 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
|
|
993 | |
|
|
994 | BOOT: |
|
|
995 | { |
|
|
996 | HV *stash = gv_stashpv ("EV::DNS", 1); |
|
|
997 | |
|
|
998 | static const struct { |
|
|
999 | const char *name; |
|
|
1000 | IV iv; |
|
|
1001 | } *civ, const_iv[] = { |
|
|
1002 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
1003 | const_iv (DNS_, ERR_NONE) |
|
|
1004 | const_iv (DNS_, ERR_FORMAT) |
|
|
1005 | const_iv (DNS_, ERR_SERVERFAILED) |
|
|
1006 | const_iv (DNS_, ERR_NOTEXIST) |
|
|
1007 | const_iv (DNS_, ERR_NOTIMPL) |
|
|
1008 | const_iv (DNS_, ERR_REFUSED) |
|
|
1009 | const_iv (DNS_, ERR_TRUNCATED) |
|
|
1010 | const_iv (DNS_, ERR_UNKNOWN) |
|
|
1011 | const_iv (DNS_, ERR_TIMEOUT) |
|
|
1012 | const_iv (DNS_, ERR_SHUTDOWN) |
|
|
1013 | const_iv (DNS_, IPv4_A) |
|
|
1014 | const_iv (DNS_, PTR) |
|
|
1015 | const_iv (DNS_, IPv6_AAAA) |
|
|
1016 | const_iv (DNS_, QUERY_NO_SEARCH) |
|
|
1017 | const_iv (DNS_, OPTION_SEARCH) |
|
|
1018 | const_iv (DNS_, OPTION_NAMESERVERS) |
|
|
1019 | const_iv (DNS_, OPTION_MISC) |
|
|
1020 | const_iv (DNS_, OPTIONS_ALL) |
|
|
1021 | const_iv (DNS_, NO_SEARCH) |
|
|
1022 | }; |
|
|
1023 | |
|
|
1024 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
1025 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
1026 | } |
|
|
1027 | |
|
|
1028 | int evdns_init () |
|
|
1029 | |
|
|
1030 | void evdns_shutdown (int fail_requests = 1) |
|
|
1031 | |
|
|
1032 | const char *evdns_err_to_string (int err) |
|
|
1033 | |
|
|
1034 | int evdns_nameserver_add (U32 address) |
|
|
1035 | |
|
|
1036 | int evdns_count_nameservers () |
|
|
1037 | |
|
|
1038 | int evdns_clear_nameservers_and_suspend () |
|
|
1039 | |
|
|
1040 | int evdns_resume () |
|
|
1041 | |
|
|
1042 | int evdns_nameserver_ip_add (char *ip_as_string) |
|
|
1043 | |
|
|
1044 | int evdns_resolve_ipv4 (const char *name, int flags, SV *cb) |
|
|
1045 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1046 | |
|
|
1047 | int evdns_resolve_ipv6 (const char *name, int flags, SV *cb) |
|
|
1048 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1049 | |
|
|
1050 | int evdns_resolve_reverse (SV *addr, int flags, SV *cb) |
|
|
1051 | ALIAS: |
1016 | ALIAS: |
1052 | evdns_resolve_reverse_ipv6 = 1 |
1017 | stat = 1 |
1053 | CODE: |
1018 | attr = 2 |
|
|
1019 | PPCODE: |
1054 | { |
1020 | { |
1055 | STRLEN len; |
1021 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1056 | char *data = SvPVbyte (addr, len); |
|
|
1057 | if (len != (ix ? 16 : 4)) |
|
|
1058 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
|
|
1059 | |
1022 | |
1060 | RETVAL = ix |
1023 | if (ix == 1) |
1061 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
1024 | ev_stat_stat (w->loop, w); |
1062 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
1025 | else if (!s->st_nlink) |
1063 | } |
1026 | errno = ENOENT; |
1064 | OUTPUT: |
|
|
1065 | RETVAL |
|
|
1066 | |
1027 | |
1067 | int evdns_set_option (char *option, char *val, int flags) |
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; |
1068 | |
1039 | |
1069 | int evdns_resolv_conf_parse (int flags, const char *filename) |
1040 | if (GIMME_V == G_SCALAR) |
1070 | |
1041 | XPUSHs (boolSV (s->st_nlink)); |
1071 | #ifdef _WIN32 |
1042 | else if (GIMME_V == G_ARRAY && s->st_nlink) |
1072 | |
1043 | { |
1073 | int evdns_config_windows_nameservers () |
1044 | EXTEND (SP, 13); |
1074 | |
1045 | PUSHs (sv_2mortal (newSViv (s->st_dev))); |
1075 | #endif |
1046 | PUSHs (sv_2mortal (newSViv (s->st_ino))); |
1076 | |
1047 | PUSHs (sv_2mortal (newSVuv (s->st_mode))); |
1077 | void evdns_search_clear () |
1048 | PUSHs (sv_2mortal (newSVuv (s->st_nlink))); |
1078 | |
1049 | PUSHs (sv_2mortal (newSViv (s->st_uid))); |
1079 | void evdns_search_add (char *domain) |
1050 | PUSHs (sv_2mortal (newSViv (s->st_gid))); |
1080 | |
1051 | PUSHs (sv_2mortal (newSViv (s->st_rdev))); |
1081 | void evdns_search_ndots_set (int ndots) |
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 | } |
1082 | |
1060 | |
1083 | #if 0 |
1061 | #if 0 |
1084 | |
1062 | |
1085 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1063 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1086 | |
1064 | |
… | |
… | |
1120 | |
1098 | |
1121 | #void DESTROY (struct evhttp_request *req); |
1099 | #void DESTROY (struct evhttp_request *req); |
1122 | |
1100 | |
1123 | #endif |
1101 | #endif |
1124 | |
1102 | |
1125 | #endif |
|
|
1126 | |
1103 | |
1127 | |
1104 | |
1128 | |
1105 | |
1129 | |
1106 | |
1130 | |
1107 | |