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