… | |
… | |
9 | |
9 | |
10 | /* fix perl api breakage */ |
10 | /* fix perl api breakage */ |
11 | #undef signal |
11 | #undef signal |
12 | #undef sigaction |
12 | #undef sigaction |
13 | |
13 | |
|
|
14 | #define EV_USE_MONOTONIC 1 |
|
|
15 | #define EV_USE_REALTIME 1 |
|
|
16 | #define EV_SELECT_IS_WINSOCKET 0 |
|
|
17 | #ifdef _WIN32 |
|
|
18 | # define EV_SELECT_USE_FD_SET 0 |
|
|
19 | # define NFDBITS PERL_NFDBITS |
|
|
20 | # define fd_mask Perl_fd_mask |
|
|
21 | #endif |
14 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
22 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
15 | #include "libev/ev.c" |
23 | #include "libev/ev.c" |
16 | #include "event.c" |
24 | #include "event.c" |
17 | |
25 | |
18 | #ifndef WIN32 |
26 | #ifndef _WIN32 |
19 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
27 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
20 | #if !defined (WIN32) && !defined(__CYGWIN__) |
28 | #if !defined (WIN32) && !defined(__CYGWIN__) |
21 | # define HAVE_STRUCT_IN6_ADDR 1 |
29 | # define HAVE_STRUCT_IN6_ADDR 1 |
22 | #endif |
30 | #endif |
23 | #undef HAVE_STRTOK_R |
31 | #undef HAVE_STRTOK_R |
24 | #undef strtok_r |
32 | #undef strtok_r |
25 | #define strtok_r fake_strtok_r |
33 | #define strtok_r fake_strtok_r |
|
|
34 | #include "evdns.h" |
26 | #include "evdns.c" |
35 | #include "evdns.c" |
27 | #endif |
36 | #endif |
28 | |
37 | |
29 | #ifndef WIN32 |
38 | #ifndef _WIN32 |
30 | # include <pthread.h> |
39 | # include <pthread.h> |
31 | #endif |
40 | #endif |
32 | |
41 | |
33 | typedef int Signal; |
42 | typedef int Signal; |
34 | |
43 | |
… | |
… | |
98 | SvPOK_only (self); |
107 | SvPOK_only (self); |
99 | SvCUR_set (self, size); |
108 | SvCUR_set (self, size); |
100 | |
109 | |
101 | w = (struct ev_watcher *)SvPVX (self); |
110 | w = (struct ev_watcher *)SvPVX (self); |
102 | |
111 | |
103 | ev_watcher_init (w, e_cb); |
112 | ev_init (w, e_cb); |
104 | |
113 | |
|
|
114 | w->data = 0; |
105 | w->fh = 0; |
115 | w->fh = 0; |
106 | w->cb_sv = newSVsv (cb_sv); |
116 | w->cb_sv = newSVsv (cb_sv); |
107 | w->self = self; |
117 | w->self = self; |
108 | |
118 | |
109 | return (void *)w; |
119 | return (void *)w; |
110 | } |
120 | } |
111 | |
121 | |
112 | static void |
122 | static void |
113 | e_destroy (void *w_) |
123 | e_destroy (void *w_) |
114 | { |
124 | { |
115 | struct ev_watcher *w = w_; |
125 | struct ev_watcher *w = (struct ev_watcher *)w_; |
116 | |
126 | |
117 | SvREFCNT_dec (w->fh ); w->fh = 0; |
127 | SvREFCNT_dec (w->fh ); w->fh = 0; |
118 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
128 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
|
|
129 | SvREFCNT_dec (w->data ); w->data = 0; |
119 | } |
130 | } |
120 | |
131 | |
121 | static SV * |
132 | static SV * |
122 | e_bless (struct ev_watcher *w, HV *stash) |
133 | e_bless (struct ev_watcher *w, HV *stash) |
123 | { |
134 | { |
… | |
… | |
158 | PUSHs (sv_self); |
169 | PUSHs (sv_self); |
159 | PUSHs (sv_events); |
170 | PUSHs (sv_events); |
160 | |
171 | |
161 | PUTBACK; |
172 | PUTBACK; |
162 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
173 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
163 | SP = PL_stack_base + mark; PUTBACK; |
|
|
164 | |
174 | |
165 | SvREFCNT_dec (sv_self); |
175 | SvREFCNT_dec (sv_self); |
166 | SvREFCNT_dec (sv_status); |
176 | SvREFCNT_dec (sv_status); |
167 | |
177 | |
168 | if (sv_events_cache) |
178 | if (sv_events_cache) |
… | |
… | |
173 | if (SvTRUE (ERRSV)) |
183 | if (SvTRUE (ERRSV)) |
174 | { |
184 | { |
175 | PUSHMARK (SP); |
185 | PUSHMARK (SP); |
176 | PUTBACK; |
186 | PUTBACK; |
177 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
187 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
178 | SP = PL_stack_base + mark; PUTBACK; |
|
|
179 | } |
188 | } |
|
|
189 | |
|
|
190 | SP = PL_stack_base + mark; |
|
|
191 | PUTBACK; |
|
|
192 | } |
|
|
193 | |
|
|
194 | static ev_tstamp |
|
|
195 | e_periodic_cb (struct ev_periodic *w, ev_tstamp now) |
|
|
196 | { |
|
|
197 | ev_tstamp retval; |
|
|
198 | int count; |
|
|
199 | dSP; |
|
|
200 | |
|
|
201 | ENTER; |
|
|
202 | SAVETMPS; |
|
|
203 | |
|
|
204 | PUSHMARK (SP); |
|
|
205 | EXTEND (SP, 2); |
|
|
206 | PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */ |
|
|
207 | PUSHs (newSVnv (now)); |
|
|
208 | |
|
|
209 | PUTBACK; |
|
|
210 | count = call_sv (w->fh, G_SCALAR | G_EVAL); |
|
|
211 | SPAGAIN; |
|
|
212 | |
|
|
213 | if (SvTRUE (ERRSV)) |
|
|
214 | { |
|
|
215 | PUSHMARK (SP); |
|
|
216 | PUTBACK; |
|
|
217 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
218 | SPAGAIN; |
|
|
219 | } |
|
|
220 | |
|
|
221 | if (count > 0) |
|
|
222 | { |
|
|
223 | retval = SvNV (TOPs); |
|
|
224 | |
|
|
225 | if (retval < now) |
|
|
226 | retval = now; |
|
|
227 | } |
|
|
228 | else |
|
|
229 | retval = now; |
|
|
230 | |
|
|
231 | FREETMPS; |
|
|
232 | LEAVE; |
|
|
233 | |
|
|
234 | return retval; |
180 | } |
235 | } |
181 | |
236 | |
182 | ///////////////////////////////////////////////////////////////////////////// |
237 | ///////////////////////////////////////////////////////////////////////////// |
183 | // DNS |
238 | // DNS |
184 | |
239 | |
185 | #ifndef WIN32 |
240 | #ifndef _WIN32 |
186 | static void |
241 | static void |
187 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
242 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
188 | { |
243 | { |
189 | dSP; |
244 | dSP; |
190 | SV *cb = (SV *)arg; |
245 | SV *cb = (SV *)arg; |
… | |
… | |
268 | const_iv (EV_, CHECK) |
323 | const_iv (EV_, CHECK) |
269 | const_iv (EV_, ERROR) |
324 | const_iv (EV_, ERROR) |
270 | |
325 | |
271 | const_iv (EV, LOOP_ONESHOT) |
326 | const_iv (EV, LOOP_ONESHOT) |
272 | const_iv (EV, LOOP_NONBLOCK) |
327 | const_iv (EV, LOOP_NONBLOCK) |
|
|
328 | const_iv (EV, UNLOOP_ONE) |
|
|
329 | const_iv (EV, UNLOOP_ALL) |
273 | |
330 | |
274 | const_iv (EV, METHOD_AUTO) |
|
|
275 | const_iv (EV, METHOD_SELECT) |
331 | const_iv (EV, METHOD_SELECT) |
276 | const_iv (EV, METHOD_POLL) |
332 | const_iv (EV, METHOD_POLL) |
277 | const_iv (EV, METHOD_EPOLL) |
333 | const_iv (EV, METHOD_EPOLL) |
278 | const_iv (EV, METHOD_KQUEUE) |
334 | const_iv (EV, METHOD_KQUEUE) |
279 | const_iv (EV, METHOD_DEVPOLL) |
335 | const_iv (EV, METHOD_DEVPOLL) |
280 | const_iv (EV, METHOD_PORT) |
336 | const_iv (EV, METHOD_PORT) |
281 | const_iv (EV, METHOD_ANY) |
337 | const_iv (EV, FLAG_AUTO) |
|
|
338 | const_iv (EV, FLAG_NOENV) |
282 | }; |
339 | }; |
283 | |
340 | |
284 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
341 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
285 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
342 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
286 | |
343 | |
… | |
… | |
328 | evapi.child_stop = ev_child_stop; |
385 | evapi.child_stop = ev_child_stop; |
329 | |
386 | |
330 | sv_setiv (sv, (IV)&evapi); |
387 | sv_setiv (sv, (IV)&evapi); |
331 | SvREADONLY_on (sv); |
388 | SvREADONLY_on (sv); |
332 | } |
389 | } |
333 | #ifndef WIN32 |
390 | #ifndef _WIN32 |
334 | pthread_atfork (0, 0, ev_default_fork); |
391 | pthread_atfork (0, 0, ev_default_fork); |
335 | #endif |
392 | #endif |
336 | } |
393 | } |
337 | |
394 | |
338 | NV ev_now () |
395 | NV ev_now () |
339 | |
396 | |
340 | int ev_method () |
397 | int ev_method () |
341 | |
398 | |
342 | NV ev_time () |
399 | NV ev_time () |
343 | |
400 | |
344 | int ev_default_loop (int methods = EVMETHOD_AUTO) |
401 | int ev_default_loop (int methods = EVFLAG_AUTO) |
345 | |
402 | |
346 | void ev_loop (int flags = 0) |
403 | void ev_loop (int flags = 0) |
347 | |
404 | |
348 | void ev_unloop (int how = 1) |
405 | void ev_unloop (int how = 1) |
349 | |
406 | |
… | |
… | |
373 | ev_timer_set (RETVAL, after, repeat); |
430 | ev_timer_set (RETVAL, after, repeat); |
374 | if (!ix) ev_timer_start (RETVAL); |
431 | if (!ix) ev_timer_start (RETVAL); |
375 | OUTPUT: |
432 | OUTPUT: |
376 | RETVAL |
433 | RETVAL |
377 | |
434 | |
378 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
435 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
379 | ALIAS: |
436 | ALIAS: |
380 | periodic_ns = 1 |
437 | periodic_ns = 1 |
381 | INIT: |
438 | INIT: |
382 | CHECK_REPEAT (interval); |
439 | CHECK_REPEAT (interval); |
383 | CODE: |
440 | CODE: |
|
|
441 | { |
|
|
442 | struct ev_periodic *w; |
384 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
443 | w = e_new (sizeof (struct ev_periodic), cb); |
385 | ev_periodic_set (RETVAL, at, interval); |
444 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
445 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
|
|
446 | RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic); |
386 | if (!ix) ev_periodic_start (RETVAL); |
447 | if (!ix) ev_periodic_start (w); |
|
|
448 | } |
387 | OUTPUT: |
449 | OUTPUT: |
388 | RETVAL |
450 | RETVAL |
389 | |
451 | |
390 | struct ev_signal *signal (Signal signum, SV *cb) |
452 | struct ev_signal *signal (Signal signum, SV *cb) |
391 | ALIAS: |
453 | ALIAS: |
… | |
… | |
427 | OUTPUT: |
489 | OUTPUT: |
428 | RETVAL |
490 | RETVAL |
429 | |
491 | |
430 | struct ev_child *child (int pid, SV *cb) |
492 | struct ev_child *child (int pid, SV *cb) |
431 | ALIAS: |
493 | ALIAS: |
432 | check_ns = 1 |
494 | child_ns = 1 |
433 | CODE: |
495 | CODE: |
434 | RETVAL = e_new (sizeof (struct ev_child), cb); |
496 | RETVAL = e_new (sizeof (struct ev_child), cb); |
435 | ev_child_set (RETVAL, pid); |
497 | ev_child_set (RETVAL, pid); |
436 | if (!ix) ev_child_start (RETVAL); |
498 | if (!ix) ev_child_start (RETVAL); |
437 | OUTPUT: |
499 | OUTPUT: |
… | |
… | |
449 | { |
511 | { |
450 | RETVAL = newSVsv (w->cb_sv); |
512 | RETVAL = newSVsv (w->cb_sv); |
451 | |
513 | |
452 | if (items > 1) |
514 | if (items > 1) |
453 | sv_setsv (w->cb_sv, new_cb); |
515 | sv_setsv (w->cb_sv, new_cb); |
|
|
516 | } |
|
|
517 | OUTPUT: |
|
|
518 | RETVAL |
|
|
519 | |
|
|
520 | SV *data (struct ev_watcher *w, SV *new_data = 0) |
|
|
521 | CODE: |
|
|
522 | { |
|
|
523 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
454 | } |
524 | } |
455 | OUTPUT: |
525 | OUTPUT: |
456 | RETVAL |
526 | RETVAL |
457 | |
527 | |
458 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
528 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
… | |
… | |
632 | INIT: |
702 | INIT: |
633 | CHECK_REPEAT (w->interval); |
703 | CHECK_REPEAT (w->interval); |
634 | |
704 | |
635 | void ev_periodic_stop (struct ev_periodic *w) |
705 | void ev_periodic_stop (struct ev_periodic *w) |
636 | |
706 | |
|
|
707 | void ev_periodic_again (struct ev_periodic *w) |
|
|
708 | |
637 | void DESTROY (struct ev_periodic *w) |
709 | void DESTROY (struct ev_periodic *w) |
638 | CODE: |
710 | CODE: |
639 | ev_periodic_stop (w); |
711 | ev_periodic_stop (w); |
640 | e_destroy (w); |
712 | e_destroy (w); |
641 | |
713 | |
642 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
714 | void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
643 | INIT: |
715 | INIT: |
644 | CHECK_REPEAT (interval); |
716 | CHECK_REPEAT (interval); |
645 | CODE: |
717 | CODE: |
646 | { |
718 | { |
647 | int active = ev_is_active (w); |
719 | int active = ev_is_active (w); |
648 | if (active) ev_periodic_stop (w); |
720 | if (active) ev_periodic_stop (w); |
649 | |
721 | |
|
|
722 | SvREFCNT_dec (w->fh); |
|
|
723 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
650 | ev_periodic_set (w, at, interval); |
724 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
651 | |
725 | |
652 | if (active) ev_periodic_start (w); |
726 | if (active) ev_periodic_start (w); |
653 | } |
727 | } |
654 | |
728 | |
655 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
729 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
… | |
… | |
732 | CODE: |
806 | CODE: |
733 | RETVAL = ix ? w->rpid : w->rstatus; |
807 | RETVAL = ix ? w->rpid : w->rstatus; |
734 | OUTPUT: |
808 | OUTPUT: |
735 | RETVAL |
809 | RETVAL |
736 | |
810 | |
737 | #ifndef WIN32 |
811 | #ifndef _WIN32 |
738 | |
812 | |
739 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
813 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
740 | |
814 | |
741 | BOOT: |
815 | BOOT: |
742 | { |
816 | { |
… | |
… | |
813 | |
887 | |
814 | int evdns_set_option (char *option, char *val, int flags) |
888 | int evdns_set_option (char *option, char *val, int flags) |
815 | |
889 | |
816 | int evdns_resolv_conf_parse (int flags, const char *filename) |
890 | int evdns_resolv_conf_parse (int flags, const char *filename) |
817 | |
891 | |
818 | #ifdef MS_WINDOWS |
892 | #ifdef _WIN32 |
819 | |
893 | |
820 | int evdns_config_windows_nameservers () |
894 | int evdns_config_windows_nameservers () |
821 | |
895 | |
822 | #endif |
896 | #endif |
823 | |
897 | |