… | |
… | |
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 |
|
|
28 | #include "evdns.h" |
13 | #include "libev/evdns.c" |
29 | #include "evdns.c" |
|
|
30 | #endif |
|
|
31 | |
|
|
32 | #ifndef WIN32 |
|
|
33 | # include <pthread.h> |
|
|
34 | #endif |
14 | |
35 | |
15 | typedef int Signal; |
36 | typedef int Signal; |
16 | |
37 | |
17 | static struct EVAPI evapi; |
38 | static struct EVAPI evapi; |
18 | |
39 | |
… | |
… | |
80 | SvPOK_only (self); |
101 | SvPOK_only (self); |
81 | SvCUR_set (self, size); |
102 | SvCUR_set (self, size); |
82 | |
103 | |
83 | w = (struct ev_watcher *)SvPVX (self); |
104 | w = (struct ev_watcher *)SvPVX (self); |
84 | |
105 | |
85 | ev_watcher_init (w, e_cb); |
106 | ev_init (w, e_cb); |
86 | |
107 | |
|
|
108 | w->data = 0; |
87 | w->fh = 0; |
109 | w->fh = 0; |
88 | w->cb_sv = newSVsv (cb_sv); |
110 | w->cb_sv = newSVsv (cb_sv); |
89 | w->self = self; |
111 | w->self = self; |
90 | |
112 | |
91 | return (void *)w; |
113 | return (void *)w; |
92 | } |
114 | } |
93 | |
115 | |
94 | static void * |
116 | static void |
95 | e_destroy (void *w_) |
117 | e_destroy (void *w_) |
96 | { |
118 | { |
97 | struct ev_watcher *w = w_; |
119 | struct ev_watcher *w = (struct ev_watcher *)w_; |
98 | |
120 | |
99 | SvREFCNT_dec (w->fh ); w->fh = 0; |
121 | SvREFCNT_dec (w->fh ); w->fh = 0; |
100 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
122 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
|
|
123 | SvREFCNT_dec (w->data ); w->data = 0; |
101 | } |
124 | } |
102 | |
125 | |
103 | static SV * |
126 | static SV * |
104 | e_bless (struct ev_watcher *w, HV *stash) |
127 | e_bless (struct ev_watcher *w, HV *stash) |
105 | { |
128 | { |
… | |
… | |
159 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
182 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
160 | SP = PL_stack_base + mark; PUTBACK; |
183 | SP = PL_stack_base + mark; PUTBACK; |
161 | } |
184 | } |
162 | } |
185 | } |
163 | |
186 | |
|
|
187 | static ev_tstamp |
|
|
188 | e_periodic_cb (struct ev_periodic *w, ev_tstamp now) |
|
|
189 | { |
|
|
190 | ev_tstamp retval; |
|
|
191 | int count; |
|
|
192 | dSP; |
|
|
193 | |
|
|
194 | ENTER; |
|
|
195 | SAVETMPS; |
|
|
196 | |
|
|
197 | PUSHMARK (SP); |
|
|
198 | EXTEND (SP, 2); |
|
|
199 | PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */ |
|
|
200 | PUSHs (newSVnv (now)); |
|
|
201 | |
|
|
202 | PUTBACK; |
|
|
203 | count = call_sv (w->fh, G_SCALAR | G_EVAL); |
|
|
204 | SPAGAIN; |
|
|
205 | |
|
|
206 | if (SvTRUE (ERRSV)) |
|
|
207 | { |
|
|
208 | PUSHMARK (SP); |
|
|
209 | PUTBACK; |
|
|
210 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
211 | SPAGAIN; |
|
|
212 | } |
|
|
213 | |
|
|
214 | if (count > 0) |
|
|
215 | { |
|
|
216 | retval = SvNV (TOPs); |
|
|
217 | |
|
|
218 | if (retval < now) |
|
|
219 | retval = now; |
|
|
220 | } |
|
|
221 | else |
|
|
222 | retval = now; |
|
|
223 | |
|
|
224 | FREETMPS; |
|
|
225 | LEAVE; |
|
|
226 | |
|
|
227 | return retval; |
|
|
228 | } |
|
|
229 | |
164 | ///////////////////////////////////////////////////////////////////////////// |
230 | ///////////////////////////////////////////////////////////////////////////// |
165 | // DNS |
231 | // DNS |
166 | |
232 | |
|
|
233 | #ifndef WIN32 |
167 | static void |
234 | static void |
168 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
235 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
169 | { |
236 | { |
170 | dSP; |
237 | dSP; |
171 | SV *cb = (SV *)arg; |
238 | SV *cb = (SV *)arg; |
… | |
… | |
210 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
277 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
211 | } |
278 | } |
212 | |
279 | |
213 | LEAVE; |
280 | LEAVE; |
214 | } |
281 | } |
|
|
282 | #endif |
215 | |
283 | |
216 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
284 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
217 | croak (# repeat " value must be >= 0"); |
285 | croak (# repeat " value must be >= 0"); |
218 | |
286 | |
219 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
287 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
226 | |
294 | |
227 | PROTOTYPES: ENABLE |
295 | PROTOTYPES: ENABLE |
228 | |
296 | |
229 | BOOT: |
297 | BOOT: |
230 | { |
298 | { |
231 | int i; |
|
|
232 | HV *stash = gv_stashpv ("EV", 1); |
299 | HV *stash = gv_stashpv ("EV", 1); |
233 | |
300 | |
234 | static const struct { |
301 | static const struct { |
235 | const char *name; |
302 | const char *name; |
236 | IV iv; |
303 | IV iv; |
… | |
… | |
282 | /* the poor man's shared library emulator */ |
349 | /* the poor man's shared library emulator */ |
283 | evapi.ver = EV_API_VERSION; |
350 | evapi.ver = EV_API_VERSION; |
284 | evapi.rev = EV_API_REVISION; |
351 | evapi.rev = EV_API_REVISION; |
285 | evapi.sv_fileno = sv_fileno; |
352 | evapi.sv_fileno = sv_fileno; |
286 | evapi.sv_signum = sv_signum; |
353 | evapi.sv_signum = sv_signum; |
287 | evapi.now = &ev_now; |
354 | evapi.now = ev_now; |
288 | evapi.method = &ev_method; |
355 | evapi.method = ev_method; |
289 | evapi.loop_done = &ev_loop_done; |
356 | evapi.unloop = ev_unloop; |
290 | evapi.time = ev_time; |
357 | evapi.time = ev_time; |
291 | evapi.loop = ev_loop; |
358 | evapi.loop = ev_loop; |
292 | evapi.once = ev_once; |
359 | evapi.once = ev_once; |
293 | evapi.io_start = ev_io_start; |
360 | evapi.io_start = ev_io_start; |
294 | evapi.io_stop = ev_io_stop; |
361 | evapi.io_stop = ev_io_stop; |
… | |
… | |
309 | evapi.child_stop = ev_child_stop; |
376 | evapi.child_stop = ev_child_stop; |
310 | |
377 | |
311 | sv_setiv (sv, (IV)&evapi); |
378 | sv_setiv (sv, (IV)&evapi); |
312 | SvREADONLY_on (sv); |
379 | SvREADONLY_on (sv); |
313 | } |
380 | } |
314 | |
381 | #ifndef WIN32 |
315 | pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child); |
382 | pthread_atfork (0, 0, ev_default_fork); |
|
|
383 | #endif |
316 | } |
384 | } |
317 | |
385 | |
318 | NV ev_now () |
386 | NV ev_now () |
319 | CODE: |
|
|
320 | RETVAL = ev_now; |
|
|
321 | OUTPUT: |
|
|
322 | RETVAL |
|
|
323 | |
387 | |
324 | int ev_method () |
388 | int ev_method () |
325 | CODE: |
|
|
326 | RETVAL = ev_method; |
|
|
327 | OUTPUT: |
|
|
328 | RETVAL |
|
|
329 | |
389 | |
330 | NV ev_time () |
390 | NV ev_time () |
331 | |
391 | |
332 | int ev_init (int methods = EVMETHOD_AUTO) |
392 | int ev_default_loop (int methods = EVMETHOD_AUTO) |
333 | |
393 | |
334 | void ev_loop (int flags = 0) |
394 | void ev_loop (int flags = 0) |
335 | |
395 | |
336 | void ev_loop_done (int value = 1) |
396 | void ev_unloop (int how = 1) |
337 | CODE: |
|
|
338 | ev_loop_done = value; |
|
|
339 | |
397 | |
340 | struct ev_io *io (SV *fh, int events, SV *cb) |
398 | struct ev_io *io (SV *fh, int events, SV *cb) |
341 | ALIAS: |
399 | ALIAS: |
342 | io_ns = 1 |
400 | io_ns = 1 |
343 | CODE: |
401 | CODE: |
… | |
… | |
363 | ev_timer_set (RETVAL, after, repeat); |
421 | ev_timer_set (RETVAL, after, repeat); |
364 | if (!ix) ev_timer_start (RETVAL); |
422 | if (!ix) ev_timer_start (RETVAL); |
365 | OUTPUT: |
423 | OUTPUT: |
366 | RETVAL |
424 | RETVAL |
367 | |
425 | |
368 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
426 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
369 | ALIAS: |
427 | ALIAS: |
370 | periodic_ns = 1 |
428 | periodic_ns = 1 |
371 | INIT: |
429 | INIT: |
372 | CHECK_REPEAT (interval); |
430 | CHECK_REPEAT (interval); |
373 | CODE: |
431 | CODE: |
|
|
432 | { |
|
|
433 | struct ev_periodic *w; |
374 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
434 | w = e_new (sizeof (struct ev_periodic), cb); |
375 | ev_periodic_set (RETVAL, at, interval); |
435 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
436 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
|
|
437 | RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic); |
376 | if (!ix) ev_periodic_start (RETVAL); |
438 | if (!ix) ev_periodic_start (w); |
|
|
439 | } |
377 | OUTPUT: |
440 | OUTPUT: |
378 | RETVAL |
441 | RETVAL |
379 | |
442 | |
380 | struct ev_signal *signal (Signal signum, SV *cb) |
443 | struct ev_signal *signal (Signal signum, SV *cb) |
381 | ALIAS: |
444 | ALIAS: |
… | |
… | |
439 | { |
502 | { |
440 | RETVAL = newSVsv (w->cb_sv); |
503 | RETVAL = newSVsv (w->cb_sv); |
441 | |
504 | |
442 | if (items > 1) |
505 | if (items > 1) |
443 | sv_setsv (w->cb_sv, new_cb); |
506 | sv_setsv (w->cb_sv, new_cb); |
|
|
507 | } |
|
|
508 | OUTPUT: |
|
|
509 | RETVAL |
|
|
510 | |
|
|
511 | SV *data (struct ev_watcher *w, SV *new_data = 0) |
|
|
512 | CODE: |
|
|
513 | { |
|
|
514 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
444 | } |
515 | } |
445 | OUTPUT: |
516 | OUTPUT: |
446 | RETVAL |
517 | RETVAL |
447 | |
518 | |
448 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
519 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
… | |
… | |
586 | } |
657 | } |
587 | } |
658 | } |
588 | OUTPUT: |
659 | OUTPUT: |
589 | RETVAL |
660 | RETVAL |
590 | |
661 | |
591 | MODULE = EV PACKAGE = EV::Time |
|
|
592 | |
|
|
593 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
662 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
594 | |
663 | |
595 | void ev_timer_start (struct ev_timer *w) |
664 | void ev_timer_start (struct ev_timer *w) |
596 | INIT: |
665 | INIT: |
597 | CHECK_REPEAT (w->repeat); |
666 | CHECK_REPEAT (w->repeat); |
… | |
… | |
624 | INIT: |
693 | INIT: |
625 | CHECK_REPEAT (w->interval); |
694 | CHECK_REPEAT (w->interval); |
626 | |
695 | |
627 | void ev_periodic_stop (struct ev_periodic *w) |
696 | void ev_periodic_stop (struct ev_periodic *w) |
628 | |
697 | |
|
|
698 | void ev_periodic_again (struct ev_periodic *w) |
|
|
699 | |
629 | void DESTROY (struct ev_periodic *w) |
700 | void DESTROY (struct ev_periodic *w) |
630 | CODE: |
701 | CODE: |
631 | ev_periodic_stop (w); |
702 | ev_periodic_stop (w); |
632 | e_destroy (w); |
703 | e_destroy (w); |
633 | |
704 | |
634 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
705 | void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
635 | INIT: |
706 | INIT: |
636 | CHECK_REPEAT (interval); |
707 | CHECK_REPEAT (interval); |
637 | CODE: |
708 | CODE: |
638 | { |
709 | { |
639 | int active = ev_is_active (w); |
710 | int active = ev_is_active (w); |
640 | if (active) ev_periodic_stop (w); |
711 | if (active) ev_periodic_stop (w); |
641 | |
712 | |
|
|
713 | SvREFCNT_dec (w->fh); |
|
|
714 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
642 | ev_periodic_set (w, at, interval); |
715 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
643 | |
716 | |
644 | if (active) ev_periodic_start (w); |
717 | if (active) ev_periodic_start (w); |
645 | } |
718 | } |
646 | |
719 | |
647 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
720 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
… | |
… | |
723 | rpid = 1 |
796 | rpid = 1 |
724 | CODE: |
797 | CODE: |
725 | RETVAL = ix ? w->rpid : w->rstatus; |
798 | RETVAL = ix ? w->rpid : w->rstatus; |
726 | OUTPUT: |
799 | OUTPUT: |
727 | RETVAL |
800 | RETVAL |
|
|
801 | |
|
|
802 | #ifndef WIN32 |
728 | |
803 | |
729 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
804 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
730 | |
805 | |
731 | BOOT: |
806 | BOOT: |
732 | { |
807 | { |
… | |
… | |
857 | |
932 | |
858 | #void DESTROY (struct evhttp_request *req); |
933 | #void DESTROY (struct evhttp_request *req); |
859 | |
934 | |
860 | #endif |
935 | #endif |
861 | |
936 | |
|
|
937 | #endif |
862 | |
938 | |
863 | |
939 | |
864 | |
940 | |
865 | |
941 | |
866 | |
942 | |