… | |
… | |
5 | /*#include <netinet/in.h>*/ |
5 | /*#include <netinet/in.h>*/ |
6 | |
6 | |
7 | #define EV_PROTOTYPES 1 |
7 | #define EV_PROTOTYPES 1 |
8 | #include "EV/EVAPI.h" |
8 | #include "EV/EVAPI.h" |
9 | |
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 |
10 | /* 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 */ |
11 | #include "libev/ev.c" |
21 | #include "libev/ev.c" |
12 | #include "event.c" |
22 | #include "event.c" |
|
|
23 | |
|
|
24 | #ifndef _WIN32 |
13 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
25 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
14 | #if !defined (WIN32) && !defined(__CYGWIN__) |
26 | #if !defined (WIN32) && !defined(__CYGWIN__) |
15 | # define HAVE_STRUCT_IN6_ADDR 1 |
27 | # define HAVE_STRUCT_IN6_ADDR 1 |
16 | #endif |
28 | #endif |
17 | #undef HAVE_STRTOK_R |
29 | #undef HAVE_STRTOK_R |
18 | #undef strtok_r |
30 | #undef strtok_r |
19 | #define strtok_r fake_strtok_r |
31 | #define strtok_r fake_strtok_r |
|
|
32 | #include "evdns.h" |
20 | #include "evdns.c" |
33 | #include "evdns.c" |
|
|
34 | #endif |
21 | |
35 | |
22 | #ifndef WIN32 |
36 | #ifndef _WIN32 |
23 | # include <pthread.h> |
37 | # include <pthread.h> |
24 | #endif |
38 | #endif |
25 | |
39 | |
26 | typedef int Signal; |
40 | typedef int Signal; |
27 | |
41 | |
… | |
… | |
91 | SvPOK_only (self); |
105 | SvPOK_only (self); |
92 | SvCUR_set (self, size); |
106 | SvCUR_set (self, size); |
93 | |
107 | |
94 | w = (struct ev_watcher *)SvPVX (self); |
108 | w = (struct ev_watcher *)SvPVX (self); |
95 | |
109 | |
96 | ev_watcher_init (w, e_cb); |
110 | ev_init (w, e_cb); |
97 | |
111 | |
|
|
112 | w->data = 0; |
98 | w->fh = 0; |
113 | w->fh = 0; |
99 | w->cb_sv = newSVsv (cb_sv); |
114 | w->cb_sv = newSVsv (cb_sv); |
100 | w->self = self; |
115 | w->self = self; |
101 | |
116 | |
102 | return (void *)w; |
117 | return (void *)w; |
103 | } |
118 | } |
104 | |
119 | |
105 | static void * |
120 | static void |
106 | e_destroy (void *w_) |
121 | e_destroy (void *w_) |
107 | { |
122 | { |
108 | struct ev_watcher *w = w_; |
123 | struct ev_watcher *w = (struct ev_watcher *)w_; |
109 | |
124 | |
110 | SvREFCNT_dec (w->fh ); w->fh = 0; |
125 | SvREFCNT_dec (w->fh ); w->fh = 0; |
111 | 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; |
112 | } |
128 | } |
113 | |
129 | |
114 | static SV * |
130 | static SV * |
115 | e_bless (struct ev_watcher *w, HV *stash) |
131 | e_bless (struct ev_watcher *w, HV *stash) |
116 | { |
132 | { |
… | |
… | |
151 | PUSHs (sv_self); |
167 | PUSHs (sv_self); |
152 | PUSHs (sv_events); |
168 | PUSHs (sv_events); |
153 | |
169 | |
154 | PUTBACK; |
170 | PUTBACK; |
155 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
171 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
156 | SP = PL_stack_base + mark; PUTBACK; |
|
|
157 | |
172 | |
158 | SvREFCNT_dec (sv_self); |
173 | SvREFCNT_dec (sv_self); |
159 | SvREFCNT_dec (sv_status); |
174 | SvREFCNT_dec (sv_status); |
160 | |
175 | |
161 | if (sv_events_cache) |
176 | if (sv_events_cache) |
… | |
… | |
166 | if (SvTRUE (ERRSV)) |
181 | if (SvTRUE (ERRSV)) |
167 | { |
182 | { |
168 | PUSHMARK (SP); |
183 | PUSHMARK (SP); |
169 | PUTBACK; |
184 | PUTBACK; |
170 | 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); |
171 | SP = PL_stack_base + mark; PUTBACK; |
|
|
172 | } |
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; |
173 | } |
233 | } |
174 | |
234 | |
175 | ///////////////////////////////////////////////////////////////////////////// |
235 | ///////////////////////////////////////////////////////////////////////////// |
176 | // DNS |
236 | // DNS |
177 | |
237 | |
|
|
238 | #ifndef _WIN32 |
178 | static void |
239 | static void |
179 | 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) |
180 | { |
241 | { |
181 | dSP; |
242 | dSP; |
182 | SV *cb = (SV *)arg; |
243 | SV *cb = (SV *)arg; |
… | |
… | |
221 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
282 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
222 | } |
283 | } |
223 | |
284 | |
224 | LEAVE; |
285 | LEAVE; |
225 | } |
286 | } |
|
|
287 | #endif |
226 | |
288 | |
227 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
289 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
228 | croak (# repeat " value must be >= 0"); |
290 | croak (# repeat " value must be >= 0"); |
229 | |
291 | |
230 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
292 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
237 | |
299 | |
238 | PROTOTYPES: ENABLE |
300 | PROTOTYPES: ENABLE |
239 | |
301 | |
240 | BOOT: |
302 | BOOT: |
241 | { |
303 | { |
242 | int i; |
|
|
243 | HV *stash = gv_stashpv ("EV", 1); |
304 | HV *stash = gv_stashpv ("EV", 1); |
244 | |
305 | |
245 | static const struct { |
306 | static const struct { |
246 | const char *name; |
307 | const char *name; |
247 | IV iv; |
308 | IV iv; |
… | |
… | |
260 | const_iv (EV_, CHECK) |
321 | const_iv (EV_, CHECK) |
261 | const_iv (EV_, ERROR) |
322 | const_iv (EV_, ERROR) |
262 | |
323 | |
263 | const_iv (EV, LOOP_ONESHOT) |
324 | const_iv (EV, LOOP_ONESHOT) |
264 | const_iv (EV, LOOP_NONBLOCK) |
325 | const_iv (EV, LOOP_NONBLOCK) |
|
|
326 | const_iv (EV, UNLOOP_ONE) |
|
|
327 | const_iv (EV, UNLOOP_ALL) |
265 | |
328 | |
266 | const_iv (EV, METHOD_AUTO) |
|
|
267 | const_iv (EV, METHOD_SELECT) |
329 | const_iv (EV, METHOD_SELECT) |
268 | const_iv (EV, METHOD_POLL) |
330 | const_iv (EV, METHOD_POLL) |
269 | const_iv (EV, METHOD_EPOLL) |
331 | const_iv (EV, METHOD_EPOLL) |
270 | const_iv (EV, METHOD_KQUEUE) |
332 | const_iv (EV, METHOD_KQUEUE) |
271 | const_iv (EV, METHOD_DEVPOLL) |
333 | const_iv (EV, METHOD_DEVPOLL) |
272 | const_iv (EV, METHOD_PORT) |
334 | const_iv (EV, METHOD_PORT) |
273 | const_iv (EV, METHOD_ANY) |
335 | const_iv (EV, FLAG_AUTO) |
|
|
336 | const_iv (EV, FLAG_NOENV) |
274 | }; |
337 | }; |
275 | |
338 | |
276 | 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; ) |
277 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
340 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
278 | |
341 | |
… | |
… | |
320 | evapi.child_stop = ev_child_stop; |
383 | evapi.child_stop = ev_child_stop; |
321 | |
384 | |
322 | sv_setiv (sv, (IV)&evapi); |
385 | sv_setiv (sv, (IV)&evapi); |
323 | SvREADONLY_on (sv); |
386 | SvREADONLY_on (sv); |
324 | } |
387 | } |
325 | |
|
|
326 | #ifndef WIN32 |
388 | #ifndef _WIN32 |
327 | pthread_atfork (0, 0, ev_default_fork); |
389 | pthread_atfork (0, 0, ev_default_fork); |
328 | #endif |
390 | #endif |
329 | } |
391 | } |
330 | |
392 | |
331 | NV ev_now () |
393 | NV ev_now () |
332 | |
394 | |
333 | int ev_method () |
395 | int ev_method () |
334 | |
396 | |
335 | NV ev_time () |
397 | NV ev_time () |
336 | |
398 | |
337 | int ev_default_loop (int methods = EVMETHOD_AUTO) |
399 | int ev_default_loop (int methods = EVMETHOD_ALL) |
338 | |
400 | |
339 | void ev_loop (int flags = 0) |
401 | void ev_loop (int flags = 0) |
340 | |
402 | |
341 | void ev_unloop (int how = 1) |
403 | void ev_unloop (int how = 1) |
342 | |
404 | |
… | |
… | |
366 | ev_timer_set (RETVAL, after, repeat); |
428 | ev_timer_set (RETVAL, after, repeat); |
367 | if (!ix) ev_timer_start (RETVAL); |
429 | if (!ix) ev_timer_start (RETVAL); |
368 | OUTPUT: |
430 | OUTPUT: |
369 | RETVAL |
431 | RETVAL |
370 | |
432 | |
371 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
433 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
372 | ALIAS: |
434 | ALIAS: |
373 | periodic_ns = 1 |
435 | periodic_ns = 1 |
374 | INIT: |
436 | INIT: |
375 | CHECK_REPEAT (interval); |
437 | CHECK_REPEAT (interval); |
376 | CODE: |
438 | CODE: |
|
|
439 | { |
|
|
440 | struct ev_periodic *w; |
377 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
441 | w = e_new (sizeof (struct ev_periodic), cb); |
378 | 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); |
379 | if (!ix) ev_periodic_start (RETVAL); |
445 | if (!ix) ev_periodic_start (w); |
|
|
446 | } |
380 | OUTPUT: |
447 | OUTPUT: |
381 | RETVAL |
448 | RETVAL |
382 | |
449 | |
383 | struct ev_signal *signal (Signal signum, SV *cb) |
450 | struct ev_signal *signal (Signal signum, SV *cb) |
384 | ALIAS: |
451 | ALIAS: |
… | |
… | |
420 | OUTPUT: |
487 | OUTPUT: |
421 | RETVAL |
488 | RETVAL |
422 | |
489 | |
423 | struct ev_child *child (int pid, SV *cb) |
490 | struct ev_child *child (int pid, SV *cb) |
424 | ALIAS: |
491 | ALIAS: |
425 | check_ns = 1 |
492 | child_ns = 1 |
426 | CODE: |
493 | CODE: |
427 | RETVAL = e_new (sizeof (struct ev_child), cb); |
494 | RETVAL = e_new (sizeof (struct ev_child), cb); |
428 | ev_child_set (RETVAL, pid); |
495 | ev_child_set (RETVAL, pid); |
429 | if (!ix) ev_child_start (RETVAL); |
496 | if (!ix) ev_child_start (RETVAL); |
430 | OUTPUT: |
497 | OUTPUT: |
… | |
… | |
442 | { |
509 | { |
443 | RETVAL = newSVsv (w->cb_sv); |
510 | RETVAL = newSVsv (w->cb_sv); |
444 | |
511 | |
445 | if (items > 1) |
512 | if (items > 1) |
446 | 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; |
447 | } |
522 | } |
448 | OUTPUT: |
523 | OUTPUT: |
449 | RETVAL |
524 | RETVAL |
450 | |
525 | |
451 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
526 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
… | |
… | |
625 | INIT: |
700 | INIT: |
626 | CHECK_REPEAT (w->interval); |
701 | CHECK_REPEAT (w->interval); |
627 | |
702 | |
628 | void ev_periodic_stop (struct ev_periodic *w) |
703 | void ev_periodic_stop (struct ev_periodic *w) |
629 | |
704 | |
|
|
705 | void ev_periodic_again (struct ev_periodic *w) |
|
|
706 | |
630 | void DESTROY (struct ev_periodic *w) |
707 | void DESTROY (struct ev_periodic *w) |
631 | CODE: |
708 | CODE: |
632 | ev_periodic_stop (w); |
709 | ev_periodic_stop (w); |
633 | e_destroy (w); |
710 | e_destroy (w); |
634 | |
711 | |
635 | 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) |
636 | INIT: |
713 | INIT: |
637 | CHECK_REPEAT (interval); |
714 | CHECK_REPEAT (interval); |
638 | CODE: |
715 | CODE: |
639 | { |
716 | { |
640 | int active = ev_is_active (w); |
717 | int active = ev_is_active (w); |
641 | if (active) ev_periodic_stop (w); |
718 | if (active) ev_periodic_stop (w); |
642 | |
719 | |
|
|
720 | SvREFCNT_dec (w->fh); |
|
|
721 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
643 | ev_periodic_set (w, at, interval); |
722 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
644 | |
723 | |
645 | if (active) ev_periodic_start (w); |
724 | if (active) ev_periodic_start (w); |
646 | } |
725 | } |
647 | |
726 | |
648 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
727 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
… | |
… | |
724 | rpid = 1 |
803 | rpid = 1 |
725 | CODE: |
804 | CODE: |
726 | RETVAL = ix ? w->rpid : w->rstatus; |
805 | RETVAL = ix ? w->rpid : w->rstatus; |
727 | OUTPUT: |
806 | OUTPUT: |
728 | RETVAL |
807 | RETVAL |
|
|
808 | |
|
|
809 | #ifndef _WIN32 |
729 | |
810 | |
730 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
811 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
731 | |
812 | |
732 | BOOT: |
813 | BOOT: |
733 | { |
814 | { |
… | |
… | |
804 | |
885 | |
805 | int evdns_set_option (char *option, char *val, int flags) |
886 | int evdns_set_option (char *option, char *val, int flags) |
806 | |
887 | |
807 | int evdns_resolv_conf_parse (int flags, const char *filename) |
888 | int evdns_resolv_conf_parse (int flags, const char *filename) |
808 | |
889 | |
809 | #ifdef MS_WINDOWS |
890 | #ifdef _WIN32 |
810 | |
891 | |
811 | int evdns_config_windows_nameservers () |
892 | int evdns_config_windows_nameservers () |
812 | |
893 | |
813 | #endif |
894 | #endif |
814 | |
895 | |
… | |
… | |
858 | |
939 | |
859 | #void DESTROY (struct evhttp_request *req); |
940 | #void DESTROY (struct evhttp_request *req); |
860 | |
941 | |
861 | #endif |
942 | #endif |
862 | |
943 | |
|
|
944 | #endif |
863 | |
945 | |
864 | |
946 | |
865 | |
947 | |
866 | |
948 | |
867 | |
949 | |