… | |
… | |
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_USE_WIN32_HANDLES 0 |
|
|
15 | #define EV_SELECT_USE_FD_SET 0 |
10 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
16 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
11 | #include "libev/ev.c" |
17 | #include "libev/ev.c" |
12 | #include "event.c" |
18 | #include "event.c" |
|
|
19 | |
|
|
20 | #ifndef WIN32 |
13 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
21 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
14 | #if !defined (WIN32) && !defined(__CYGWIN__) |
22 | #if !defined (WIN32) && !defined(__CYGWIN__) |
15 | # define HAVE_STRUCT_IN6_ADDR 1 |
23 | # define HAVE_STRUCT_IN6_ADDR 1 |
16 | #endif |
24 | #endif |
17 | #undef HAVE_STRTOK_R |
25 | #undef HAVE_STRTOK_R |
18 | #undef strtok_r |
26 | #undef strtok_r |
19 | #define strtok_r fake_strtok_r |
27 | #define strtok_r fake_strtok_r |
20 | #include "evdns.c" |
28 | #include "evdns.c" |
|
|
29 | #endif |
21 | |
30 | |
22 | #ifndef WIN32 |
31 | #ifndef WIN32 |
23 | # include <pthread.h> |
32 | # include <pthread.h> |
24 | #endif |
33 | #endif |
25 | |
34 | |
… | |
… | |
93 | |
102 | |
94 | w = (struct ev_watcher *)SvPVX (self); |
103 | w = (struct ev_watcher *)SvPVX (self); |
95 | |
104 | |
96 | ev_watcher_init (w, e_cb); |
105 | ev_watcher_init (w, e_cb); |
97 | |
106 | |
|
|
107 | w->data = 0; |
98 | w->fh = 0; |
108 | w->fh = 0; |
99 | w->cb_sv = newSVsv (cb_sv); |
109 | w->cb_sv = newSVsv (cb_sv); |
100 | w->self = self; |
110 | w->self = self; |
101 | |
111 | |
102 | return (void *)w; |
112 | return (void *)w; |
103 | } |
113 | } |
104 | |
114 | |
105 | static void * |
115 | static void |
106 | e_destroy (void *w_) |
116 | e_destroy (void *w_) |
107 | { |
117 | { |
108 | struct ev_watcher *w = w_; |
118 | struct ev_watcher *w = (struct ev_watcher *)w_; |
109 | |
119 | |
110 | SvREFCNT_dec (w->fh ); w->fh = 0; |
120 | SvREFCNT_dec (w->fh ); w->fh = 0; |
111 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
121 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
|
|
122 | SvREFCNT_dec (w->data ); w->data = 0; |
112 | } |
123 | } |
113 | |
124 | |
114 | static SV * |
125 | static SV * |
115 | e_bless (struct ev_watcher *w, HV *stash) |
126 | e_bless (struct ev_watcher *w, HV *stash) |
116 | { |
127 | { |
… | |
… | |
170 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
181 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
171 | SP = PL_stack_base + mark; PUTBACK; |
182 | SP = PL_stack_base + mark; PUTBACK; |
172 | } |
183 | } |
173 | } |
184 | } |
174 | |
185 | |
|
|
186 | static ev_tstamp |
|
|
187 | e_periodic_cb (struct ev_periodic *w, ev_tstamp now) |
|
|
188 | { |
|
|
189 | ev_tstamp retval; |
|
|
190 | int count; |
|
|
191 | dSP; |
|
|
192 | |
|
|
193 | ENTER; |
|
|
194 | SAVETMPS; |
|
|
195 | |
|
|
196 | PUSHMARK (SP); |
|
|
197 | EXTEND (SP, 2); |
|
|
198 | PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */ |
|
|
199 | PUSHs (newSVnv (now)); |
|
|
200 | |
|
|
201 | PUTBACK; |
|
|
202 | count = call_sv (w->fh, G_SCALAR | G_EVAL); |
|
|
203 | SPAGAIN; |
|
|
204 | |
|
|
205 | if (SvTRUE (ERRSV)) |
|
|
206 | { |
|
|
207 | PUSHMARK (SP); |
|
|
208 | PUTBACK; |
|
|
209 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
210 | SPAGAIN; |
|
|
211 | } |
|
|
212 | |
|
|
213 | if (count > 0) |
|
|
214 | { |
|
|
215 | retval = SvNV (TOPs); |
|
|
216 | |
|
|
217 | if (retval < now) |
|
|
218 | retval = now; |
|
|
219 | } |
|
|
220 | else |
|
|
221 | retval = now; |
|
|
222 | |
|
|
223 | FREETMPS; |
|
|
224 | LEAVE; |
|
|
225 | |
|
|
226 | return retval; |
|
|
227 | } |
|
|
228 | |
175 | ///////////////////////////////////////////////////////////////////////////// |
229 | ///////////////////////////////////////////////////////////////////////////// |
176 | // DNS |
230 | // DNS |
177 | |
231 | |
|
|
232 | #ifndef WIN32 |
178 | static void |
233 | static void |
179 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
234 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
180 | { |
235 | { |
181 | dSP; |
236 | dSP; |
182 | SV *cb = (SV *)arg; |
237 | SV *cb = (SV *)arg; |
… | |
… | |
221 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
276 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
222 | } |
277 | } |
223 | |
278 | |
224 | LEAVE; |
279 | LEAVE; |
225 | } |
280 | } |
|
|
281 | #endif |
226 | |
282 | |
227 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
283 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
228 | croak (# repeat " value must be >= 0"); |
284 | croak (# repeat " value must be >= 0"); |
229 | |
285 | |
230 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
286 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
237 | |
293 | |
238 | PROTOTYPES: ENABLE |
294 | PROTOTYPES: ENABLE |
239 | |
295 | |
240 | BOOT: |
296 | BOOT: |
241 | { |
297 | { |
242 | int i; |
|
|
243 | HV *stash = gv_stashpv ("EV", 1); |
298 | HV *stash = gv_stashpv ("EV", 1); |
244 | |
299 | |
245 | static const struct { |
300 | static const struct { |
246 | const char *name; |
301 | const char *name; |
247 | IV iv; |
302 | IV iv; |
… | |
… | |
320 | evapi.child_stop = ev_child_stop; |
375 | evapi.child_stop = ev_child_stop; |
321 | |
376 | |
322 | sv_setiv (sv, (IV)&evapi); |
377 | sv_setiv (sv, (IV)&evapi); |
323 | SvREADONLY_on (sv); |
378 | SvREADONLY_on (sv); |
324 | } |
379 | } |
325 | |
|
|
326 | #ifndef WIN32 |
380 | #ifndef WIN32 |
327 | pthread_atfork (0, 0, ev_default_fork); |
381 | pthread_atfork (0, 0, ev_default_fork); |
328 | #endif |
382 | #endif |
329 | } |
383 | } |
330 | |
384 | |
331 | NV ev_now () |
385 | NV ev_now () |
332 | |
386 | |
333 | int ev_method () |
387 | int ev_method () |
… | |
… | |
366 | ev_timer_set (RETVAL, after, repeat); |
420 | ev_timer_set (RETVAL, after, repeat); |
367 | if (!ix) ev_timer_start (RETVAL); |
421 | if (!ix) ev_timer_start (RETVAL); |
368 | OUTPUT: |
422 | OUTPUT: |
369 | RETVAL |
423 | RETVAL |
370 | |
424 | |
371 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
425 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
372 | ALIAS: |
426 | ALIAS: |
373 | periodic_ns = 1 |
427 | periodic_ns = 1 |
374 | INIT: |
428 | INIT: |
375 | CHECK_REPEAT (interval); |
429 | CHECK_REPEAT (interval); |
376 | CODE: |
430 | CODE: |
|
|
431 | { |
|
|
432 | struct ev_periodic *w; |
377 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
433 | w = e_new (sizeof (struct ev_periodic), cb); |
378 | ev_periodic_set (RETVAL, at, interval); |
434 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
435 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
|
|
436 | RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic); |
379 | if (!ix) ev_periodic_start (RETVAL); |
437 | if (!ix) ev_periodic_start (w); |
|
|
438 | } |
380 | OUTPUT: |
439 | OUTPUT: |
381 | RETVAL |
440 | RETVAL |
382 | |
441 | |
383 | struct ev_signal *signal (Signal signum, SV *cb) |
442 | struct ev_signal *signal (Signal signum, SV *cb) |
384 | ALIAS: |
443 | ALIAS: |
… | |
… | |
442 | { |
501 | { |
443 | RETVAL = newSVsv (w->cb_sv); |
502 | RETVAL = newSVsv (w->cb_sv); |
444 | |
503 | |
445 | if (items > 1) |
504 | if (items > 1) |
446 | sv_setsv (w->cb_sv, new_cb); |
505 | sv_setsv (w->cb_sv, new_cb); |
|
|
506 | } |
|
|
507 | OUTPUT: |
|
|
508 | RETVAL |
|
|
509 | |
|
|
510 | SV *data (struct ev_watcher *w, SV *new_data = 0) |
|
|
511 | CODE: |
|
|
512 | { |
|
|
513 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
447 | } |
514 | } |
448 | OUTPUT: |
515 | OUTPUT: |
449 | RETVAL |
516 | RETVAL |
450 | |
517 | |
451 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
518 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
… | |
… | |
625 | INIT: |
692 | INIT: |
626 | CHECK_REPEAT (w->interval); |
693 | CHECK_REPEAT (w->interval); |
627 | |
694 | |
628 | void ev_periodic_stop (struct ev_periodic *w) |
695 | void ev_periodic_stop (struct ev_periodic *w) |
629 | |
696 | |
|
|
697 | void ev_periodic_again (struct ev_periodic *w) |
|
|
698 | |
630 | void DESTROY (struct ev_periodic *w) |
699 | void DESTROY (struct ev_periodic *w) |
631 | CODE: |
700 | CODE: |
632 | ev_periodic_stop (w); |
701 | ev_periodic_stop (w); |
633 | e_destroy (w); |
702 | e_destroy (w); |
634 | |
703 | |
635 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
704 | void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
636 | INIT: |
705 | INIT: |
637 | CHECK_REPEAT (interval); |
706 | CHECK_REPEAT (interval); |
638 | CODE: |
707 | CODE: |
639 | { |
708 | { |
640 | int active = ev_is_active (w); |
709 | int active = ev_is_active (w); |
641 | if (active) ev_periodic_stop (w); |
710 | if (active) ev_periodic_stop (w); |
642 | |
711 | |
|
|
712 | SvREFCNT_dec (w->fh); |
|
|
713 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
643 | ev_periodic_set (w, at, interval); |
714 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
644 | |
715 | |
645 | if (active) ev_periodic_start (w); |
716 | if (active) ev_periodic_start (w); |
646 | } |
717 | } |
647 | |
718 | |
648 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
719 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
… | |
… | |
724 | rpid = 1 |
795 | rpid = 1 |
725 | CODE: |
796 | CODE: |
726 | RETVAL = ix ? w->rpid : w->rstatus; |
797 | RETVAL = ix ? w->rpid : w->rstatus; |
727 | OUTPUT: |
798 | OUTPUT: |
728 | RETVAL |
799 | RETVAL |
|
|
800 | |
|
|
801 | #ifndef WIN32 |
729 | |
802 | |
730 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
803 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
731 | |
804 | |
732 | BOOT: |
805 | BOOT: |
733 | { |
806 | { |
… | |
… | |
858 | |
931 | |
859 | #void DESTROY (struct evhttp_request *req); |
932 | #void DESTROY (struct evhttp_request *req); |
860 | |
933 | |
861 | #endif |
934 | #endif |
862 | |
935 | |
|
|
936 | #endif |
863 | |
937 | |
864 | |
938 | |
865 | |
939 | |
866 | |
940 | |
867 | |
941 | |