… | |
… | |
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 |
|
|
16 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
10 | #include "libev/ev.c" |
17 | #include "libev/ev.c" |
11 | #include "libev/event.h" |
|
|
12 | #include "libev/event.c" |
18 | #include "event.c" |
|
|
19 | |
|
|
20 | #ifndef WIN32 |
|
|
21 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
|
|
22 | #if !defined (WIN32) && !defined(__CYGWIN__) |
|
|
23 | # define HAVE_STRUCT_IN6_ADDR 1 |
|
|
24 | #endif |
|
|
25 | #undef HAVE_STRTOK_R |
|
|
26 | #undef strtok_r |
|
|
27 | #define strtok_r fake_strtok_r |
13 | #include "libev/evdns.c" |
28 | #include "evdns.c" |
|
|
29 | #endif |
|
|
30 | |
|
|
31 | #ifndef WIN32 |
|
|
32 | # include <pthread.h> |
|
|
33 | #endif |
14 | |
34 | |
15 | typedef int Signal; |
35 | typedef int Signal; |
16 | |
36 | |
17 | static struct EVAPI evapi; |
37 | static struct EVAPI evapi; |
18 | |
38 | |
… | |
… | |
25 | *stash_idle, |
45 | *stash_idle, |
26 | *stash_prepare, |
46 | *stash_prepare, |
27 | *stash_check, |
47 | *stash_check, |
28 | *stash_child; |
48 | *stash_child; |
29 | |
49 | |
|
|
50 | #ifndef SIG_SIZE |
|
|
51 | /* kudos to Slaven Rezic for the idea */ |
|
|
52 | static char sig_size [] = { SIG_NUM }; |
|
|
53 | # define SIG_SIZE (sizeof (sig_size) + 1) |
|
|
54 | #endif |
|
|
55 | |
30 | static int |
56 | static int |
31 | sv_signum (SV *sig) |
57 | sv_signum (SV *sig) |
32 | { |
58 | { |
33 | int signum; |
59 | int signum; |
34 | |
60 | |
… | |
… | |
76 | |
102 | |
77 | w = (struct ev_watcher *)SvPVX (self); |
103 | w = (struct ev_watcher *)SvPVX (self); |
78 | |
104 | |
79 | ev_watcher_init (w, e_cb); |
105 | ev_watcher_init (w, e_cb); |
80 | |
106 | |
|
|
107 | w->data = 0; |
81 | w->fh = 0; |
108 | w->fh = 0; |
82 | w->cb_sv = newSVsv (cb_sv); |
109 | w->cb_sv = newSVsv (cb_sv); |
83 | w->self = self; |
110 | w->self = self; |
84 | |
111 | |
85 | return (void *)w; |
112 | return (void *)w; |
86 | } |
113 | } |
87 | |
114 | |
88 | static void * |
115 | static void |
89 | e_destroy (void *w_) |
116 | e_destroy (void *w_) |
90 | { |
117 | { |
91 | struct ev_watcher *w = w_; |
118 | struct ev_watcher *w = (struct ev_watcher *)w_; |
92 | |
119 | |
93 | SvREFCNT_dec (w->fh ); w->fh = 0; |
120 | SvREFCNT_dec (w->fh ); w->fh = 0; |
94 | 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; |
95 | } |
123 | } |
96 | |
124 | |
97 | static SV * |
125 | static SV * |
98 | e_bless (struct ev_watcher *w, HV *stash) |
126 | e_bless (struct ev_watcher *w, HV *stash) |
99 | { |
127 | { |
… | |
… | |
132 | PUSHMARK (SP); |
160 | PUSHMARK (SP); |
133 | EXTEND (SP, 2); |
161 | EXTEND (SP, 2); |
134 | PUSHs (sv_self); |
162 | PUSHs (sv_self); |
135 | PUSHs (sv_events); |
163 | PUSHs (sv_events); |
136 | |
164 | |
137 | if (revents & EV_CHILD) |
|
|
138 | XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status)); |
|
|
139 | |
|
|
140 | PUTBACK; |
165 | PUTBACK; |
141 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
166 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
142 | SP = PL_stack_base + mark; PUTBACK; |
167 | SP = PL_stack_base + mark; PUTBACK; |
143 | |
168 | |
144 | SvREFCNT_dec (sv_self); |
169 | SvREFCNT_dec (sv_self); |
… | |
… | |
156 | 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); |
157 | SP = PL_stack_base + mark; PUTBACK; |
182 | SP = PL_stack_base + mark; PUTBACK; |
158 | } |
183 | } |
159 | } |
184 | } |
160 | |
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 | |
161 | ///////////////////////////////////////////////////////////////////////////// |
229 | ///////////////////////////////////////////////////////////////////////////// |
162 | // DNS |
230 | // DNS |
163 | |
231 | |
|
|
232 | #ifndef WIN32 |
164 | static void |
233 | static void |
165 | 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) |
166 | { |
235 | { |
167 | dSP; |
236 | dSP; |
168 | SV *cb = (SV *)arg; |
237 | SV *cb = (SV *)arg; |
… | |
… | |
207 | 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); |
208 | } |
277 | } |
209 | |
278 | |
210 | LEAVE; |
279 | LEAVE; |
211 | } |
280 | } |
|
|
281 | #endif |
212 | |
282 | |
213 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
283 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
214 | croak (# repeat " value must be >= 0"); |
284 | croak (# repeat " value must be >= 0"); |
215 | |
285 | |
216 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
286 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
223 | |
293 | |
224 | PROTOTYPES: ENABLE |
294 | PROTOTYPES: ENABLE |
225 | |
295 | |
226 | BOOT: |
296 | BOOT: |
227 | { |
297 | { |
228 | int i; |
|
|
229 | HV *stash = gv_stashpv ("EV", 1); |
298 | HV *stash = gv_stashpv ("EV", 1); |
230 | |
299 | |
231 | static const struct { |
300 | static const struct { |
232 | const char *name; |
301 | const char *name; |
233 | IV iv; |
302 | IV iv; |
… | |
… | |
279 | /* the poor man's shared library emulator */ |
348 | /* the poor man's shared library emulator */ |
280 | evapi.ver = EV_API_VERSION; |
349 | evapi.ver = EV_API_VERSION; |
281 | evapi.rev = EV_API_REVISION; |
350 | evapi.rev = EV_API_REVISION; |
282 | evapi.sv_fileno = sv_fileno; |
351 | evapi.sv_fileno = sv_fileno; |
283 | evapi.sv_signum = sv_signum; |
352 | evapi.sv_signum = sv_signum; |
284 | evapi.now = &ev_now; |
353 | evapi.now = ev_now; |
285 | evapi.method = &ev_method; |
354 | evapi.method = ev_method; |
286 | evapi.loop_done = &ev_loop_done; |
355 | evapi.unloop = ev_unloop; |
287 | evapi.time = ev_time; |
356 | evapi.time = ev_time; |
288 | evapi.loop = ev_loop; |
357 | evapi.loop = ev_loop; |
289 | evapi.once = ev_once; |
358 | evapi.once = ev_once; |
290 | evapi.io_start = ev_io_start; |
359 | evapi.io_start = ev_io_start; |
291 | evapi.io_stop = ev_io_stop; |
360 | evapi.io_stop = ev_io_stop; |
… | |
… | |
306 | evapi.child_stop = ev_child_stop; |
375 | evapi.child_stop = ev_child_stop; |
307 | |
376 | |
308 | sv_setiv (sv, (IV)&evapi); |
377 | sv_setiv (sv, (IV)&evapi); |
309 | SvREADONLY_on (sv); |
378 | SvREADONLY_on (sv); |
310 | } |
379 | } |
311 | |
380 | #ifndef WIN32 |
312 | pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child); |
381 | pthread_atfork (0, 0, ev_default_fork); |
|
|
382 | #endif |
313 | } |
383 | } |
314 | |
384 | |
315 | NV ev_now () |
385 | NV ev_now () |
316 | CODE: |
|
|
317 | RETVAL = ev_now; |
|
|
318 | OUTPUT: |
|
|
319 | RETVAL |
|
|
320 | |
386 | |
321 | int ev_method () |
387 | int ev_method () |
322 | CODE: |
|
|
323 | RETVAL = ev_method; |
|
|
324 | OUTPUT: |
|
|
325 | RETVAL |
|
|
326 | |
388 | |
327 | NV ev_time () |
389 | NV ev_time () |
328 | |
390 | |
329 | void ev_init (int methods = EVMETHOD_AUTO) |
391 | int ev_default_loop (int methods = EVMETHOD_AUTO) |
330 | |
392 | |
331 | void ev_loop (int flags = 0) |
393 | void ev_loop (int flags = 0) |
332 | |
394 | |
333 | void ev_loop_done (int value = 1) |
395 | void ev_unloop (int how = 1) |
334 | CODE: |
|
|
335 | ev_loop_done = value; |
|
|
336 | |
396 | |
337 | struct ev_io *io (SV *fh, int events, SV *cb) |
397 | struct ev_io *io (SV *fh, int events, SV *cb) |
338 | ALIAS: |
398 | ALIAS: |
339 | io_ns = 1 |
399 | io_ns = 1 |
340 | CODE: |
400 | CODE: |
… | |
… | |
360 | ev_timer_set (RETVAL, after, repeat); |
420 | ev_timer_set (RETVAL, after, repeat); |
361 | if (!ix) ev_timer_start (RETVAL); |
421 | if (!ix) ev_timer_start (RETVAL); |
362 | OUTPUT: |
422 | OUTPUT: |
363 | RETVAL |
423 | RETVAL |
364 | |
424 | |
365 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
425 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
366 | ALIAS: |
426 | ALIAS: |
367 | periodic_ns = 1 |
427 | periodic_ns = 1 |
368 | INIT: |
428 | INIT: |
369 | CHECK_REPEAT (interval); |
429 | CHECK_REPEAT (interval); |
370 | CODE: |
430 | CODE: |
|
|
431 | { |
|
|
432 | struct ev_periodic *w; |
371 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
433 | w = e_new (sizeof (struct ev_periodic), cb); |
372 | 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); |
373 | if (!ix) ev_periodic_start (RETVAL); |
437 | if (!ix) ev_periodic_start (w); |
|
|
438 | } |
374 | OUTPUT: |
439 | OUTPUT: |
375 | RETVAL |
440 | RETVAL |
376 | |
441 | |
377 | struct ev_signal *signal (Signal signum, SV *cb) |
442 | struct ev_signal *signal (Signal signum, SV *cb) |
378 | ALIAS: |
443 | ALIAS: |
… | |
… | |
416 | |
481 | |
417 | struct ev_child *child (int pid, SV *cb) |
482 | struct ev_child *child (int pid, SV *cb) |
418 | ALIAS: |
483 | ALIAS: |
419 | check_ns = 1 |
484 | check_ns = 1 |
420 | CODE: |
485 | CODE: |
421 | RETVAL = e_new (sizeof (struct ev_check), cb); |
486 | RETVAL = e_new (sizeof (struct ev_child), cb); |
422 | ev_child_set (RETVAL, pid); |
487 | ev_child_set (RETVAL, pid); |
423 | if (!ix) ev_child_start (RETVAL); |
488 | if (!ix) ev_child_start (RETVAL); |
424 | OUTPUT: |
489 | OUTPUT: |
425 | RETVAL |
490 | RETVAL |
426 | |
491 | |
… | |
… | |
436 | { |
501 | { |
437 | RETVAL = newSVsv (w->cb_sv); |
502 | RETVAL = newSVsv (w->cb_sv); |
438 | |
503 | |
439 | if (items > 1) |
504 | if (items > 1) |
440 | 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; |
441 | } |
514 | } |
442 | OUTPUT: |
515 | OUTPUT: |
443 | RETVAL |
516 | RETVAL |
444 | |
517 | |
445 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
518 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
… | |
… | |
583 | } |
656 | } |
584 | } |
657 | } |
585 | OUTPUT: |
658 | OUTPUT: |
586 | RETVAL |
659 | RETVAL |
587 | |
660 | |
588 | MODULE = EV PACKAGE = EV::Time |
|
|
589 | |
|
|
590 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
661 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
591 | |
662 | |
592 | void ev_timer_start (struct ev_timer *w) |
663 | void ev_timer_start (struct ev_timer *w) |
593 | INIT: |
664 | INIT: |
594 | CHECK_REPEAT (w->repeat); |
665 | CHECK_REPEAT (w->repeat); |
… | |
… | |
621 | INIT: |
692 | INIT: |
622 | CHECK_REPEAT (w->interval); |
693 | CHECK_REPEAT (w->interval); |
623 | |
694 | |
624 | void ev_periodic_stop (struct ev_periodic *w) |
695 | void ev_periodic_stop (struct ev_periodic *w) |
625 | |
696 | |
|
|
697 | void ev_periodic_again (struct ev_periodic *w) |
|
|
698 | |
626 | void DESTROY (struct ev_periodic *w) |
699 | void DESTROY (struct ev_periodic *w) |
627 | CODE: |
700 | CODE: |
628 | ev_periodic_stop (w); |
701 | ev_periodic_stop (w); |
629 | e_destroy (w); |
702 | e_destroy (w); |
630 | |
703 | |
631 | 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) |
632 | INIT: |
705 | INIT: |
633 | CHECK_REPEAT (interval); |
706 | CHECK_REPEAT (interval); |
634 | CODE: |
707 | CODE: |
635 | { |
708 | { |
636 | int active = ev_is_active (w); |
709 | int active = ev_is_active (w); |
637 | if (active) ev_periodic_stop (w); |
710 | if (active) ev_periodic_stop (w); |
638 | |
711 | |
|
|
712 | SvREFCNT_dec (w->fh); |
|
|
713 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
639 | ev_periodic_set (w, at, interval); |
714 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
640 | |
715 | |
641 | if (active) ev_periodic_start (w); |
716 | if (active) ev_periodic_start (w); |
642 | } |
717 | } |
643 | |
718 | |
644 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
719 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
… | |
… | |
713 | } |
788 | } |
714 | OUTPUT: |
789 | OUTPUT: |
715 | RETVAL |
790 | RETVAL |
716 | |
791 | |
717 | |
792 | |
718 | int status (struct ev_child *w) |
793 | int rstatus (struct ev_child *w) |
|
|
794 | ALIAS: |
|
|
795 | rpid = 1 |
719 | CODE: |
796 | CODE: |
720 | RETVAL = w->status; |
797 | RETVAL = ix ? w->rpid : w->rstatus; |
721 | OUTPUT: |
798 | OUTPUT: |
722 | RETVAL |
799 | RETVAL |
|
|
800 | |
|
|
801 | #ifndef WIN32 |
723 | |
802 | |
724 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
803 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
725 | |
804 | |
726 | BOOT: |
805 | BOOT: |
727 | { |
806 | { |
… | |
… | |
852 | |
931 | |
853 | #void DESTROY (struct evhttp_request *req); |
932 | #void DESTROY (struct evhttp_request *req); |
854 | |
933 | |
855 | #endif |
934 | #endif |
856 | |
935 | |
|
|
936 | #endif |
857 | |
937 | |
858 | |
938 | |
859 | |
939 | |
860 | |
940 | |
861 | |
941 | |