… | |
… | |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | /*#include <netinet/in.h>*/ |
5 | /*#include <netinet/in.h>*/ |
6 | |
6 | |
7 | #define EV_PROTOTYPES 1 |
|
|
8 | #include "EV/EVAPI.h" |
|
|
9 | |
|
|
10 | /* fix perl api breakage */ |
7 | /* fix perl api breakage */ |
11 | #undef signal |
8 | #undef signal |
12 | #undef sigaction |
9 | #undef sigaction |
|
|
10 | |
|
|
11 | #define EV_PROTOTYPES 1 |
|
|
12 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
|
|
13 | #define EV_H <ev.h> |
|
|
14 | #include "EV/EVAPI.h" |
13 | |
15 | |
14 | #define EV_SELECT_IS_WINSOCKET 0 |
16 | #define EV_SELECT_IS_WINSOCKET 0 |
15 | #ifdef _WIN32 |
17 | #ifdef _WIN32 |
16 | # define EV_SELECT_USE_FD_SET 0 |
18 | # define EV_SELECT_USE_FD_SET 0 |
17 | # define NFDBITS PERL_NFDBITS |
19 | # define NFDBITS PERL_NFDBITS |
18 | # define fd_mask Perl_fd_mask |
20 | # define fd_mask Perl_fd_mask |
19 | #endif |
21 | #endif |
20 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
22 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
21 | #include "libev/ev.c" |
23 | #include "libev/ev.c" |
22 | #include "event.c" |
|
|
23 | |
|
|
24 | #ifndef _WIN32 |
|
|
25 | #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 |
|
|
26 | #if !defined (WIN32) && !defined(__CYGWIN__) |
|
|
27 | # define HAVE_STRUCT_IN6_ADDR 1 |
|
|
28 | #endif |
|
|
29 | #undef HAVE_STRTOK_R |
|
|
30 | #undef strtok_r |
|
|
31 | #define strtok_r fake_strtok_r |
|
|
32 | #include "evdns.h" |
|
|
33 | #include "evdns.c" |
|
|
34 | #endif |
|
|
35 | |
24 | |
36 | #ifndef _WIN32 |
25 | #ifndef _WIN32 |
37 | # include <pthread.h> |
26 | # include <pthread.h> |
38 | #endif |
27 | #endif |
39 | |
28 | |
|
|
29 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
|
|
30 | |
40 | #define WFLAG_KEEPALIVE 1 |
31 | #define WFLAG_KEEPALIVE 1 |
41 | |
32 | |
42 | #define UNREF(w) \ |
33 | #define UNREF(w) \ |
43 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
34 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
44 | && !ev_is_active (w)) \ |
35 | && !ev_is_active (w)) \ |
45 | ev_unref (); |
36 | ev_unref (e_loop (w)); |
46 | |
37 | |
47 | #define REF(w) \ |
38 | #define REF(w) \ |
48 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
39 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
49 | && ev_is_active (w)) \ |
40 | && ev_is_active (w)) \ |
50 | ev_ref (); |
41 | ev_ref (e_loop (w)); |
51 | |
42 | |
52 | #define START(type,w) \ |
43 | #define START(type,w) \ |
53 | do { \ |
44 | do { \ |
54 | UNREF (w); \ |
45 | UNREF (w); \ |
55 | ev_ ## type ## _start (w); \ |
46 | ev_ ## type ## _start (e_loop (w), w); \ |
56 | } while (0) |
47 | } while (0) |
57 | |
48 | |
58 | #define STOP(type,w) \ |
49 | #define STOP(type,w) \ |
59 | do { \ |
50 | do { \ |
60 | REF (w); \ |
51 | REF (w); \ |
61 | ev_ ## type ## _stop (w); \ |
52 | ev_ ## type ## _stop (e_loop (w), w); \ |
62 | } while (0) |
53 | } while (0) |
63 | |
54 | |
64 | #define RESET(type,w,seta) \ |
55 | #define RESET(type,w,seta) \ |
65 | do { \ |
56 | do { \ |
66 | int active = ev_is_active (w); \ |
57 | int active = ev_is_active (w); \ |
… | |
… | |
69 | if (active) START (type, w); \ |
60 | if (active) START (type, w); \ |
70 | } while (0) |
61 | } while (0) |
71 | |
62 | |
72 | typedef int Signal; |
63 | typedef int Signal; |
73 | |
64 | |
|
|
65 | static SV *default_loop_sv; |
|
|
66 | |
74 | static struct EVAPI evapi; |
67 | static struct EVAPI evapi; |
75 | |
68 | |
76 | static HV |
69 | static HV |
|
|
70 | *stash_loop, |
77 | *stash_watcher, |
71 | *stash_watcher, |
78 | *stash_io, |
72 | *stash_io, |
79 | *stash_timer, |
73 | *stash_timer, |
80 | *stash_periodic, |
74 | *stash_periodic, |
81 | *stash_signal, |
75 | *stash_signal, |
… | |
… | |
83 | *stash_stat, |
77 | *stash_stat, |
84 | *stash_idle, |
78 | *stash_idle, |
85 | *stash_prepare, |
79 | *stash_prepare, |
86 | *stash_check, |
80 | *stash_check, |
87 | *stash_embed, |
81 | *stash_embed, |
88 | *stash_fork; |
82 | *stash_fork, |
|
|
83 | *stash_async; |
89 | |
84 | |
90 | #ifndef SIG_SIZE |
85 | #ifndef SIG_SIZE |
91 | /* kudos to Slaven Rezic for the idea */ |
86 | /* kudos to Slaven Rezic for the idea */ |
92 | static char sig_size [] = { SIG_NUM }; |
87 | static char sig_size [] = { SIG_NUM }; |
93 | # define SIG_SIZE (sizeof (sig_size) + 1) |
88 | # define SIG_SIZE (sizeof (sig_size) + 1) |
… | |
… | |
113 | } |
108 | } |
114 | |
109 | |
115 | ///////////////////////////////////////////////////////////////////////////// |
110 | ///////////////////////////////////////////////////////////////////////////// |
116 | // Event |
111 | // Event |
117 | |
112 | |
118 | static void e_cb (ev_watcher *w, int revents); |
113 | static void e_cb (EV_P_ ev_watcher *w, int revents); |
119 | |
114 | |
120 | static int |
115 | static int |
121 | sv_fileno (SV *fh) |
116 | sv_fileno (SV *fh) |
122 | { |
117 | { |
123 | SvGETMAGIC (fh); |
118 | SvGETMAGIC (fh); |
… | |
… | |
132 | return SvIV (fh); |
127 | return SvIV (fh); |
133 | |
128 | |
134 | return -1; |
129 | return -1; |
135 | } |
130 | } |
136 | |
131 | |
|
|
132 | static SV * |
|
|
133 | e_get_cv (SV *cb_sv) |
|
|
134 | { |
|
|
135 | HV *st; |
|
|
136 | GV *gvp; |
|
|
137 | CV *cv = sv_2cv (cb_sv, &st, &gvp, 0); |
|
|
138 | |
|
|
139 | if (!cv) |
|
|
140 | croak ("EV watcher callback must be a CODE reference"); |
|
|
141 | |
|
|
142 | return (SV *)cv; |
|
|
143 | } |
|
|
144 | |
137 | static void * |
145 | static void * |
138 | e_new (int size, SV *cb_sv) |
146 | e_new (int size, SV *cb_sv, SV *loop) |
139 | { |
147 | { |
|
|
148 | SV *cv = cb_sv ? e_get_cv (cb_sv) : 0; |
140 | ev_watcher *w; |
149 | ev_watcher *w; |
141 | SV *self = NEWSV (0, size); |
150 | SV *self = NEWSV (0, size); |
142 | SvPOK_only (self); |
151 | SvPOK_only (self); |
143 | SvCUR_set (self, size); |
152 | SvCUR_set (self, size); |
144 | |
153 | |
145 | w = (ev_watcher *)SvPVX (self); |
154 | w = (ev_watcher *)SvPVX (self); |
146 | |
155 | |
147 | ev_init (w, e_cb); |
156 | ev_init (w, cv ? e_cb : 0); |
148 | |
157 | |
|
|
158 | w->loop = SvREFCNT_inc (SvRV (loop)); |
149 | w->flags = WFLAG_KEEPALIVE; |
159 | w->e_flags = WFLAG_KEEPALIVE; |
150 | w->data = 0; |
160 | w->data = 0; |
151 | w->fh = 0; |
161 | w->fh = 0; |
152 | w->cb_sv = newSVsv (cb_sv); |
162 | w->cb_sv = SvREFCNT_inc (cv); |
153 | w->self = self; |
163 | w->self = self; |
154 | |
164 | |
155 | return (void *)w; |
165 | return (void *)w; |
156 | } |
166 | } |
157 | |
167 | |
158 | static void |
168 | static void |
159 | e_destroy (void *w_) |
169 | e_destroy (void *w_) |
160 | { |
170 | { |
161 | ev_watcher *w = (ev_watcher *)w_; |
171 | ev_watcher *w = (ev_watcher *)w_; |
162 | |
172 | |
|
|
173 | SvREFCNT_dec (w->loop ); w->loop = 0; |
163 | SvREFCNT_dec (w->fh ); w->fh = 0; |
174 | SvREFCNT_dec (w->fh ); w->fh = 0; |
164 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
175 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
165 | SvREFCNT_dec (w->data ); w->data = 0; |
176 | SvREFCNT_dec (w->data ); w->data = 0; |
166 | } |
177 | } |
167 | |
178 | |
… | |
… | |
183 | } |
194 | } |
184 | |
195 | |
185 | static SV *sv_events_cache; |
196 | static SV *sv_events_cache; |
186 | |
197 | |
187 | static void |
198 | static void |
188 | e_cb (ev_watcher *w, int revents) |
199 | e_cb (EV_P_ ev_watcher *w, int revents) |
189 | { |
200 | { |
190 | dSP; |
201 | dSP; |
191 | I32 mark = SP - PL_stack_base; |
202 | I32 mark = SP - PL_stack_base; |
192 | SV *sv_self, *sv_events; |
203 | SV *sv_self, *sv_events; |
193 | |
204 | |
… | |
… | |
216 | else |
227 | else |
217 | sv_events_cache = sv_events; |
228 | sv_events_cache = sv_events; |
218 | |
229 | |
219 | if (SvTRUE (ERRSV)) |
230 | if (SvTRUE (ERRSV)) |
220 | { |
231 | { |
|
|
232 | SPAGAIN; |
221 | PUSHMARK (SP); |
233 | PUSHMARK (SP); |
222 | PUTBACK; |
234 | PUTBACK; |
223 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
235 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
224 | } |
236 | } |
225 | |
237 | |
… | |
… | |
255 | else |
267 | else |
256 | sv_events_cache = sv_events; |
268 | sv_events_cache = sv_events; |
257 | |
269 | |
258 | if (SvTRUE (ERRSV)) |
270 | if (SvTRUE (ERRSV)) |
259 | { |
271 | { |
|
|
272 | SPAGAIN; |
260 | PUSHMARK (SP); |
273 | PUSHMARK (SP); |
261 | PUTBACK; |
274 | PUTBACK; |
262 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
275 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
263 | } |
276 | } |
264 | |
277 | |
… | |
… | |
306 | FREETMPS; |
319 | FREETMPS; |
307 | LEAVE; |
320 | LEAVE; |
308 | |
321 | |
309 | return retval; |
322 | return retval; |
310 | } |
323 | } |
311 | |
|
|
312 | ///////////////////////////////////////////////////////////////////////////// |
|
|
313 | // DNS |
|
|
314 | |
|
|
315 | #ifndef _WIN32 |
|
|
316 | static void |
|
|
317 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
|
|
318 | { |
|
|
319 | dSP; |
|
|
320 | SV *cb = (SV *)arg; |
|
|
321 | |
|
|
322 | ENTER; |
|
|
323 | SAVETMPS; |
|
|
324 | PUSHMARK (SP); |
|
|
325 | EXTEND (SP, count + 3); |
|
|
326 | PUSHs (sv_2mortal (newSViv (result))); |
|
|
327 | |
|
|
328 | if (result == DNS_ERR_NONE && ttl >= 0) |
|
|
329 | { |
|
|
330 | int i; |
|
|
331 | |
|
|
332 | PUSHs (sv_2mortal (newSViv (type))); |
|
|
333 | PUSHs (sv_2mortal (newSViv (ttl))); |
|
|
334 | |
|
|
335 | for (i = 0; i < count; ++i) |
|
|
336 | switch (type) |
|
|
337 | { |
|
|
338 | case DNS_IPv6_AAAA: |
|
|
339 | PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16))); |
|
|
340 | break; |
|
|
341 | case DNS_IPv4_A: |
|
|
342 | PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4))); |
|
|
343 | break; |
|
|
344 | case DNS_PTR: |
|
|
345 | PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0))); |
|
|
346 | break; |
|
|
347 | } |
|
|
348 | } |
|
|
349 | |
|
|
350 | PUTBACK; |
|
|
351 | call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); |
|
|
352 | |
|
|
353 | FREETMPS; |
|
|
354 | |
|
|
355 | if (SvTRUE (ERRSV)) |
|
|
356 | { |
|
|
357 | PUSHMARK (SP); |
|
|
358 | PUTBACK; |
|
|
359 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
360 | } |
|
|
361 | |
|
|
362 | LEAVE; |
|
|
363 | } |
|
|
364 | #endif |
|
|
365 | |
324 | |
366 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
325 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
367 | croak (# repeat " value must be >= 0"); |
326 | croak (# repeat " value must be >= 0"); |
368 | |
327 | |
369 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
328 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
418 | }; |
377 | }; |
419 | |
378 | |
420 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
379 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
421 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
380 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
422 | |
381 | |
|
|
382 | stash_loop = gv_stashpv ("EV::Loop" , 1); |
423 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
383 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
424 | stash_io = gv_stashpv ("EV::IO" , 1); |
384 | stash_io = gv_stashpv ("EV::IO" , 1); |
425 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
385 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
426 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
386 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
427 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
387 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
… | |
… | |
429 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
389 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
430 | stash_check = gv_stashpv ("EV::Check" , 1); |
390 | stash_check = gv_stashpv ("EV::Check" , 1); |
431 | stash_child = gv_stashpv ("EV::Child" , 1); |
391 | stash_child = gv_stashpv ("EV::Child" , 1); |
432 | stash_embed = gv_stashpv ("EV::Embed" , 1); |
392 | stash_embed = gv_stashpv ("EV::Embed" , 1); |
433 | stash_stat = gv_stashpv ("EV::Stat" , 1); |
393 | stash_stat = gv_stashpv ("EV::Stat" , 1); |
|
|
394 | stash_fork = gv_stashpv ("EV::Fork" , 1); |
|
|
395 | stash_async = gv_stashpv ("EV::Async" , 1); |
434 | |
396 | |
435 | { |
397 | { |
436 | SV *sv = perl_get_sv ("EV::API", TRUE); |
398 | SV *sv = perl_get_sv ("EV::API", TRUE); |
437 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
399 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
438 | |
400 | |
439 | /* the poor man's shared library emulator */ |
401 | /* the poor man's shared library emulator */ |
440 | evapi.ver = EV_API_VERSION; |
402 | evapi.ver = EV_API_VERSION; |
441 | evapi.rev = EV_API_REVISION; |
403 | evapi.rev = EV_API_REVISION; |
442 | evapi.sv_fileno = sv_fileno; |
404 | evapi.sv_fileno = sv_fileno; |
443 | evapi.sv_signum = sv_signum; |
405 | evapi.sv_signum = sv_signum; |
|
|
406 | evapi.supported_backends = ev_supported_backends (); |
|
|
407 | evapi.recommended_backends = ev_recommended_backends (); |
|
|
408 | evapi.embeddable_backends = ev_embeddable_backends (); |
|
|
409 | evapi.time_ = ev_time; |
|
|
410 | evapi.sleep_ = ev_sleep; |
|
|
411 | evapi.loop_new = ev_loop_new; |
|
|
412 | evapi.loop_destroy = ev_loop_destroy; |
|
|
413 | evapi.loop_fork = ev_loop_fork; |
|
|
414 | evapi.loop_count = ev_loop_count; |
444 | evapi.now = ev_now; |
415 | evapi.now = ev_now; |
|
|
416 | evapi.now_update = ev_now_update; |
445 | evapi.backend = ev_backend; |
417 | evapi.backend = ev_backend; |
446 | evapi.unloop = ev_unloop; |
418 | evapi.unloop = ev_unloop; |
447 | evapi.ref = ev_ref; |
419 | evapi.ref = ev_ref; |
448 | evapi.unref = ev_unref; |
420 | evapi.unref = ev_unref; |
449 | evapi.time = ev_time; |
|
|
450 | evapi.loop = ev_loop; |
421 | evapi.loop = ev_loop; |
451 | evapi.once = ev_once; |
422 | evapi.once = ev_once; |
452 | evapi.io_start = ev_io_start; |
423 | evapi.io_start = ev_io_start; |
453 | evapi.io_stop = ev_io_stop; |
424 | evapi.io_stop = ev_io_stop; |
454 | evapi.timer_start = ev_timer_start; |
425 | evapi.timer_start = ev_timer_start; |
455 | evapi.timer_stop = ev_timer_stop; |
426 | evapi.timer_stop = ev_timer_stop; |
456 | evapi.timer_again = ev_timer_again; |
427 | evapi.timer_again = ev_timer_again; |
457 | evapi.periodic_start = ev_periodic_start; |
428 | evapi.periodic_start = ev_periodic_start; |
458 | evapi.periodic_stop = ev_periodic_stop; |
429 | evapi.periodic_stop = ev_periodic_stop; |
459 | evapi.signal_start = ev_signal_start; |
430 | evapi.signal_start = ev_signal_start; |
460 | evapi.signal_stop = ev_signal_stop; |
431 | evapi.signal_stop = ev_signal_stop; |
461 | evapi.idle_start = ev_idle_start; |
432 | evapi.idle_start = ev_idle_start; |
462 | evapi.idle_stop = ev_idle_stop; |
433 | evapi.idle_stop = ev_idle_stop; |
463 | evapi.prepare_start = ev_prepare_start; |
434 | evapi.prepare_start = ev_prepare_start; |
464 | evapi.prepare_stop = ev_prepare_stop; |
435 | evapi.prepare_stop = ev_prepare_stop; |
465 | evapi.check_start = ev_check_start; |
436 | evapi.check_start = ev_check_start; |
466 | evapi.check_stop = ev_check_stop; |
437 | evapi.check_stop = ev_check_stop; |
467 | evapi.child_start = ev_child_start; |
438 | evapi.child_start = ev_child_start; |
468 | evapi.child_stop = ev_child_stop; |
439 | evapi.child_stop = ev_child_stop; |
469 | evapi.stat_start = ev_stat_start; |
440 | evapi.stat_start = ev_stat_start; |
470 | evapi.stat_stop = ev_stat_stop; |
441 | evapi.stat_stop = ev_stat_stop; |
471 | evapi.stat_stat = ev_stat_stat; |
442 | evapi.stat_stat = ev_stat_stat; |
|
|
443 | evapi.embed_start = ev_embed_start; |
|
|
444 | evapi.embed_stop = ev_embed_stop; |
|
|
445 | evapi.embed_sweep = ev_embed_sweep; |
|
|
446 | evapi.fork_start = ev_fork_start; |
|
|
447 | evapi.fork_stop = ev_fork_stop; |
|
|
448 | evapi.async_start = ev_async_start; |
|
|
449 | evapi.async_stop = ev_async_stop; |
|
|
450 | evapi.async_send = ev_async_send; |
|
|
451 | evapi.clear_pending = ev_clear_pending; |
|
|
452 | evapi.invoke = ev_invoke; |
472 | |
453 | |
473 | sv_setiv (sv, (IV)&evapi); |
454 | sv_setiv (sv, (IV)&evapi); |
474 | SvREADONLY_on (sv); |
455 | SvREADONLY_on (sv); |
475 | } |
456 | } |
476 | #ifndef _WIN32 |
457 | #ifndef _WIN32 |
477 | pthread_atfork (0, 0, ev_default_fork); |
458 | pthread_atfork (0, 0, ev_default_fork); |
478 | #endif |
459 | #endif |
479 | } |
460 | } |
480 | |
461 | |
|
|
462 | SV *ev_default_loop (unsigned int flags = 0) |
|
|
463 | CODE: |
|
|
464 | { |
|
|
465 | if (!default_loop_sv) |
|
|
466 | { |
|
|
467 | evapi.default_loop = ev_default_loop (flags); |
|
|
468 | |
|
|
469 | if (!evapi.default_loop) |
|
|
470 | XSRETURN_UNDEF; |
|
|
471 | |
|
|
472 | default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop); |
|
|
473 | } |
|
|
474 | |
|
|
475 | RETVAL = newSVsv (default_loop_sv); |
|
|
476 | } |
|
|
477 | OUTPUT: |
|
|
478 | RETVAL |
|
|
479 | |
|
|
480 | void ev_default_destroy () |
|
|
481 | CODE: |
|
|
482 | ev_default_destroy (); |
|
|
483 | SvREFCNT_dec (default_loop_sv); |
|
|
484 | default_loop_sv = 0; |
|
|
485 | |
|
|
486 | unsigned int ev_supported_backends () |
|
|
487 | |
|
|
488 | unsigned int ev_recommended_backends () |
|
|
489 | |
|
|
490 | unsigned int ev_embeddable_backends () |
|
|
491 | |
|
|
492 | NV ev_time () |
|
|
493 | |
481 | NV ev_now () |
494 | NV ev_now () |
|
|
495 | C_ARGS: evapi.default_loop |
|
|
496 | |
|
|
497 | void ev_now_update () |
|
|
498 | C_ARGS: evapi.default_loop |
482 | |
499 | |
483 | unsigned int ev_backend () |
500 | unsigned int ev_backend () |
|
|
501 | C_ARGS: evapi.default_loop |
484 | |
502 | |
485 | NV ev_time () |
503 | unsigned int ev_loop_count () |
|
|
504 | C_ARGS: evapi.default_loop |
486 | |
505 | |
487 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
506 | void ev_set_io_collect_interval (NV interval) |
|
|
507 | C_ARGS: evapi.default_loop, interval |
|
|
508 | |
|
|
509 | void ev_set_timeout_collect_interval (NV interval) |
|
|
510 | C_ARGS: evapi.default_loop, interval |
488 | |
511 | |
489 | void ev_loop (int flags = 0) |
512 | void ev_loop (int flags = 0) |
|
|
513 | C_ARGS: evapi.default_loop, flags |
490 | |
514 | |
491 | void ev_unloop (int how = 1) |
515 | void ev_unloop (int how = EVUNLOOP_ONE) |
|
|
516 | C_ARGS: evapi.default_loop, how |
|
|
517 | |
|
|
518 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
|
|
519 | C_ARGS: evapi.default_loop, fd, revents |
|
|
520 | |
|
|
521 | void ev_feed_signal_event (SV *signal) |
|
|
522 | CODE: |
|
|
523 | { |
|
|
524 | Signal signum = sv_signum (signal); |
|
|
525 | CHECK_SIG (signal, signum); |
|
|
526 | |
|
|
527 | ev_feed_signal_event (evapi.default_loop, signum); |
|
|
528 | } |
492 | |
529 | |
493 | ev_io *io (SV *fh, int events, SV *cb) |
530 | ev_io *io (SV *fh, int events, SV *cb) |
494 | ALIAS: |
531 | ALIAS: |
495 | io_ns = 1 |
532 | io_ns = 1 |
496 | CODE: |
533 | CODE: |
497 | { |
534 | { |
498 | int fd = sv_fileno (fh); |
535 | int fd = sv_fileno (fh); |
499 | CHECK_FD (fh, fd); |
536 | CHECK_FD (fh, fd); |
500 | |
537 | |
501 | RETVAL = e_new (sizeof (ev_io), cb); |
538 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
502 | RETVAL->fh = newSVsv (fh); |
539 | RETVAL->fh = newSVsv (fh); |
503 | ev_io_set (RETVAL, fd, events); |
540 | ev_io_set (RETVAL, fd, events); |
504 | if (!ix) START (io, RETVAL); |
541 | if (!ix) START (io, RETVAL); |
505 | } |
542 | } |
506 | OUTPUT: |
543 | OUTPUT: |
… | |
… | |
510 | ALIAS: |
547 | ALIAS: |
511 | timer_ns = 1 |
548 | timer_ns = 1 |
512 | INIT: |
549 | INIT: |
513 | CHECK_REPEAT (repeat); |
550 | CHECK_REPEAT (repeat); |
514 | CODE: |
551 | CODE: |
515 | RETVAL = e_new (sizeof (ev_timer), cb); |
552 | RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv); |
516 | ev_timer_set (RETVAL, after, repeat); |
553 | ev_timer_set (RETVAL, after, repeat); |
517 | if (!ix) START (timer, RETVAL); |
554 | if (!ix) START (timer, RETVAL); |
518 | OUTPUT: |
555 | OUTPUT: |
519 | RETVAL |
556 | RETVAL |
520 | |
557 | |
… | |
… | |
524 | INIT: |
561 | INIT: |
525 | CHECK_REPEAT (interval); |
562 | CHECK_REPEAT (interval); |
526 | CODE: |
563 | CODE: |
527 | { |
564 | { |
528 | ev_periodic *w; |
565 | ev_periodic *w; |
529 | w = e_new (sizeof (ev_periodic), cb); |
566 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
530 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
567 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
531 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
568 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
532 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
569 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
533 | if (!ix) START (periodic, w); |
570 | if (!ix) START (periodic, w); |
534 | } |
571 | } |
… | |
… | |
541 | CODE: |
578 | CODE: |
542 | { |
579 | { |
543 | Signal signum = sv_signum (signal); |
580 | Signal signum = sv_signum (signal); |
544 | CHECK_SIG (signal, signum); |
581 | CHECK_SIG (signal, signum); |
545 | |
582 | |
546 | RETVAL = e_new (sizeof (ev_signal), cb); |
583 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
547 | ev_signal_set (RETVAL, signum); |
584 | ev_signal_set (RETVAL, signum); |
548 | if (!ix) START (signal, RETVAL); |
585 | if (!ix) START (signal, RETVAL); |
549 | } |
586 | } |
550 | OUTPUT: |
587 | OUTPUT: |
551 | RETVAL |
588 | RETVAL |
552 | |
589 | |
553 | ev_idle *idle (SV *cb) |
590 | ev_idle *idle (SV *cb) |
554 | ALIAS: |
591 | ALIAS: |
555 | idle_ns = 1 |
592 | idle_ns = 1 |
556 | CODE: |
593 | CODE: |
557 | RETVAL = e_new (sizeof (ev_idle), cb); |
594 | RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv); |
558 | ev_idle_set (RETVAL); |
595 | ev_idle_set (RETVAL); |
559 | if (!ix) START (idle, RETVAL); |
596 | if (!ix) START (idle, RETVAL); |
560 | OUTPUT: |
597 | OUTPUT: |
561 | RETVAL |
598 | RETVAL |
562 | |
599 | |
563 | ev_prepare *prepare (SV *cb) |
600 | ev_prepare *prepare (SV *cb) |
564 | ALIAS: |
601 | ALIAS: |
565 | prepare_ns = 1 |
602 | prepare_ns = 1 |
566 | CODE: |
603 | CODE: |
567 | RETVAL = e_new (sizeof (ev_prepare), cb); |
604 | RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv); |
568 | ev_prepare_set (RETVAL); |
605 | ev_prepare_set (RETVAL); |
569 | if (!ix) START (prepare, RETVAL); |
606 | if (!ix) START (prepare, RETVAL); |
570 | OUTPUT: |
607 | OUTPUT: |
571 | RETVAL |
608 | RETVAL |
572 | |
609 | |
573 | ev_check *check (SV *cb) |
610 | ev_check *check (SV *cb) |
574 | ALIAS: |
611 | ALIAS: |
575 | check_ns = 1 |
612 | check_ns = 1 |
576 | CODE: |
613 | CODE: |
577 | RETVAL = e_new (sizeof (ev_check), cb); |
614 | RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv); |
578 | ev_check_set (RETVAL); |
615 | ev_check_set (RETVAL); |
579 | if (!ix) START (check, RETVAL); |
616 | if (!ix) START (check, RETVAL); |
580 | OUTPUT: |
617 | OUTPUT: |
581 | RETVAL |
618 | RETVAL |
582 | |
619 | |
|
|
620 | ev_fork *fork (SV *cb) |
|
|
621 | ALIAS: |
|
|
622 | fork_ns = 1 |
|
|
623 | CODE: |
|
|
624 | RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv); |
|
|
625 | ev_fork_set (RETVAL); |
|
|
626 | if (!ix) START (fork, RETVAL); |
|
|
627 | OUTPUT: |
|
|
628 | RETVAL |
|
|
629 | |
583 | ev_child *child (int pid, SV *cb) |
630 | ev_child *child (int pid, int trace, SV *cb) |
584 | ALIAS: |
631 | ALIAS: |
585 | child_ns = 1 |
632 | child_ns = 1 |
586 | CODE: |
633 | CODE: |
587 | RETVAL = e_new (sizeof (ev_child), cb); |
634 | RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); |
588 | ev_child_set (RETVAL, pid); |
635 | ev_child_set (RETVAL, pid, trace); |
589 | if (!ix) START (child, RETVAL); |
636 | if (!ix) START (child, RETVAL); |
590 | OUTPUT: |
637 | OUTPUT: |
591 | RETVAL |
638 | RETVAL |
592 | |
639 | |
593 | ev_stat *stat (SV *path, NV interval, SV *cb) |
640 | ev_stat *stat (SV *path, NV interval, SV *cb) |
594 | ALIAS: |
641 | ALIAS: |
595 | stat_ns = 1 |
642 | stat_ns = 1 |
596 | CODE: |
643 | CODE: |
597 | RETVAL = e_new (sizeof (ev_stat), cb); |
644 | RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv); |
598 | RETVAL->fh = newSVsv (path); |
645 | RETVAL->fh = newSVsv (path); |
599 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
646 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
600 | if (!ix) START (stat, RETVAL); |
647 | if (!ix) START (stat, RETVAL); |
601 | OUTPUT: |
648 | OUTPUT: |
602 | RETVAL |
649 | RETVAL |
603 | |
650 | |
|
|
651 | ev_embed *embed (struct ev_loop *loop, SV *cb = 0) |
|
|
652 | ALIAS: |
|
|
653 | embed_ns = 1 |
|
|
654 | CODE: |
|
|
655 | { |
|
|
656 | if (!(ev_backend (loop) & ev_embeddable_backends ())) |
|
|
657 | croak ("passed loop is not embeddable via EV::embed,"); |
|
|
658 | |
|
|
659 | RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); |
|
|
660 | RETVAL->fh = newSVsv (ST (0)); |
|
|
661 | ev_embed_set (RETVAL, loop); |
|
|
662 | if (!ix) START (embed, RETVAL); |
|
|
663 | } |
|
|
664 | OUTPUT: |
|
|
665 | RETVAL |
|
|
666 | |
|
|
667 | ev_async *async (SV *cb) |
|
|
668 | ALIAS: |
|
|
669 | async_ns = 1 |
|
|
670 | CODE: |
|
|
671 | RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv); |
|
|
672 | ev_async_set (RETVAL); |
|
|
673 | if (!ix) START (async, RETVAL); |
|
|
674 | OUTPUT: |
|
|
675 | RETVAL |
|
|
676 | |
604 | void once (SV *fh, int events, SV *timeout, SV *cb) |
677 | void once (SV *fh, int events, SV *timeout, SV *cb) |
605 | CODE: |
678 | CODE: |
606 | ev_once ( |
679 | ev_once ( |
|
|
680 | evapi.default_loop, |
607 | sv_fileno (fh), events, |
681 | sv_fileno (fh), events, |
608 | SvOK (timeout) ? SvNV (timeout) : -1., |
682 | SvOK (timeout) ? SvNV (timeout) : -1., |
609 | e_once_cb, |
683 | e_once_cb, |
610 | newSVsv (cb) |
684 | newSVsv (cb) |
611 | ); |
685 | ); |
… | |
… | |
616 | |
690 | |
617 | int ev_is_active (ev_watcher *w) |
691 | int ev_is_active (ev_watcher *w) |
618 | |
692 | |
619 | int ev_is_pending (ev_watcher *w) |
693 | int ev_is_pending (ev_watcher *w) |
620 | |
694 | |
|
|
695 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
|
|
696 | C_ARGS: e_loop (w), w, revents |
|
|
697 | |
|
|
698 | int ev_clear_pending (ev_watcher *w) |
|
|
699 | C_ARGS: e_loop (w), w |
|
|
700 | |
|
|
701 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
|
|
702 | C_ARGS: e_loop (w), w, revents |
|
|
703 | |
621 | int keepalive (ev_watcher *w, int new_value = 0) |
704 | int keepalive (ev_watcher *w, int new_value = 0) |
622 | CODE: |
705 | CODE: |
623 | { |
706 | { |
624 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
707 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
625 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
708 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
626 | |
709 | |
627 | if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) |
710 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
628 | { |
711 | { |
629 | REF (w); |
712 | REF (w); |
630 | w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; |
713 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
631 | UNREF (w); |
714 | UNREF (w); |
632 | } |
715 | } |
633 | } |
716 | } |
634 | OUTPUT: |
717 | OUTPUT: |
635 | RETVAL |
718 | RETVAL |
636 | |
719 | |
637 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
720 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
638 | CODE: |
721 | CODE: |
639 | { |
722 | { |
640 | RETVAL = newSVsv (w->cb_sv); |
|
|
641 | |
|
|
642 | if (items > 1) |
723 | if (items > 1) |
643 | sv_setsv (w->cb_sv, new_cb); |
724 | { |
|
|
725 | new_cb = e_get_cv (new_cb); |
|
|
726 | RETVAL = newRV_noinc (w->cb_sv); |
|
|
727 | w->cb_sv = SvREFCNT_inc (new_cb); |
|
|
728 | } |
|
|
729 | else |
|
|
730 | RETVAL = newRV_inc (w->cb_sv); |
644 | } |
731 | } |
645 | OUTPUT: |
732 | OUTPUT: |
646 | RETVAL |
733 | RETVAL |
647 | |
734 | |
648 | SV *data (ev_watcher *w, SV *new_data = 0) |
735 | SV *data (ev_watcher *w, SV *new_data = 0) |
… | |
… | |
657 | } |
744 | } |
658 | } |
745 | } |
659 | OUTPUT: |
746 | OUTPUT: |
660 | RETVAL |
747 | RETVAL |
661 | |
748 | |
662 | void trigger (ev_watcher *w, int revents = EV_NONE) |
749 | SV *loop (ev_watcher *w) |
663 | CODE: |
750 | CODE: |
664 | w->cb (w, revents); |
751 | RETVAL = newRV_inc (w->loop); |
|
|
752 | OUTPUT: |
|
|
753 | RETVAL |
665 | |
754 | |
666 | int priority (ev_watcher *w, int new_priority = 0) |
755 | int priority (ev_watcher *w, int new_priority = 0) |
667 | CODE: |
756 | CODE: |
668 | { |
757 | { |
669 | RETVAL = w->priority; |
758 | RETVAL = w->priority; |
670 | |
759 | |
671 | if (items > 1) |
760 | if (items > 1) |
672 | { |
761 | { |
673 | int active = ev_is_active (w); |
762 | int active = ev_is_active (w); |
674 | |
|
|
675 | if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI) |
|
|
676 | croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI); |
|
|
677 | |
763 | |
678 | if (active) |
764 | if (active) |
679 | { |
765 | { |
680 | /* grrr. */ |
766 | /* grrr. */ |
681 | PUSHMARK (SP); |
767 | PUSHMARK (SP); |
682 | XPUSHs (ST (0)); |
768 | XPUSHs (ST (0)); |
|
|
769 | PUTBACK; |
683 | call_method ("stop", G_DISCARD | G_VOID); |
770 | call_method ("stop", G_DISCARD | G_VOID); |
684 | } |
771 | } |
685 | |
772 | |
686 | ev_set_priority (w, new_priority); |
773 | ev_set_priority (w, new_priority); |
687 | |
774 | |
688 | if (active) |
775 | if (active) |
689 | { |
776 | { |
690 | PUSHMARK (SP); |
777 | PUSHMARK (SP); |
691 | XPUSHs (ST (0)); |
778 | XPUSHs (ST (0)); |
|
|
779 | PUTBACK; |
692 | call_method ("start", G_DISCARD | G_VOID); |
780 | call_method ("start", G_DISCARD | G_VOID); |
693 | } |
781 | } |
694 | } |
782 | } |
695 | } |
783 | } |
696 | OUTPUT: |
784 | OUTPUT: |
… | |
… | |
806 | void ev_timer_again (ev_timer *w) |
894 | void ev_timer_again (ev_timer *w) |
807 | INIT: |
895 | INIT: |
808 | CHECK_REPEAT (w->repeat); |
896 | CHECK_REPEAT (w->repeat); |
809 | CODE: |
897 | CODE: |
810 | REF (w); |
898 | REF (w); |
811 | ev_timer_again (w); |
899 | ev_timer_again (e_loop (w), w); |
812 | UNREF (w); |
900 | UNREF (w); |
813 | |
901 | |
814 | void DESTROY (ev_timer *w) |
902 | void DESTROY (ev_timer *w) |
815 | CODE: |
903 | CODE: |
816 | STOP (timer, w); |
904 | STOP (timer, w); |
… | |
… | |
835 | STOP (periodic, w); |
923 | STOP (periodic, w); |
836 | |
924 | |
837 | void ev_periodic_again (ev_periodic *w) |
925 | void ev_periodic_again (ev_periodic *w) |
838 | CODE: |
926 | CODE: |
839 | REF (w); |
927 | REF (w); |
840 | ev_periodic_again (w); |
928 | ev_periodic_again (e_loop (w), w); |
841 | UNREF (w); |
929 | UNREF (w); |
842 | |
930 | |
843 | void DESTROY (ev_periodic *w) |
931 | void DESTROY (ev_periodic *w) |
844 | CODE: |
932 | CODE: |
845 | STOP (periodic, w); |
933 | STOP (periodic, w); |
… | |
… | |
854 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
942 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
855 | |
943 | |
856 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
944 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
857 | } |
945 | } |
858 | |
946 | |
|
|
947 | NV at (ev_periodic *w) |
|
|
948 | CODE: |
|
|
949 | RETVAL = ev_periodic_at (w); |
|
|
950 | OUTPUT: |
|
|
951 | RETVAL |
|
|
952 | |
859 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
953 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
860 | |
954 | |
861 | void ev_idle_start (ev_idle *w) |
955 | void ev_idle_start (ev_idle *w) |
862 | CODE: |
956 | CODE: |
863 | START (idle, w); |
957 | START (idle, w); |
… | |
… | |
869 | void DESTROY (ev_idle *w) |
963 | void DESTROY (ev_idle *w) |
870 | CODE: |
964 | CODE: |
871 | STOP (idle, w); |
965 | STOP (idle, w); |
872 | e_destroy (w); |
966 | e_destroy (w); |
873 | |
967 | |
874 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ |
968 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_ |
875 | |
969 | |
876 | void ev_prepare_start (ev_prepare *w) |
970 | void ev_prepare_start (ev_prepare *w) |
877 | CODE: |
971 | CODE: |
878 | START (prepare, w); |
972 | START (prepare, w); |
879 | |
973 | |
… | |
… | |
899 | void DESTROY (ev_check *w) |
993 | void DESTROY (ev_check *w) |
900 | CODE: |
994 | CODE: |
901 | STOP (check, w); |
995 | STOP (check, w); |
902 | e_destroy (w); |
996 | e_destroy (w); |
903 | |
997 | |
|
|
998 | MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_ |
|
|
999 | |
|
|
1000 | void ev_fork_start (ev_fork *w) |
|
|
1001 | CODE: |
|
|
1002 | START (fork, w); |
|
|
1003 | |
|
|
1004 | void ev_fork_stop (ev_fork *w) |
|
|
1005 | CODE: |
|
|
1006 | STOP (fork, w); |
|
|
1007 | |
|
|
1008 | void DESTROY (ev_fork *w) |
|
|
1009 | CODE: |
|
|
1010 | STOP (fork, w); |
|
|
1011 | e_destroy (w); |
|
|
1012 | |
904 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
1013 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
905 | |
1014 | |
906 | void ev_child_start (ev_child *w) |
1015 | void ev_child_start (ev_child *w) |
907 | CODE: |
1016 | CODE: |
908 | START (child, w); |
1017 | START (child, w); |
… | |
… | |
914 | void DESTROY (ev_child *w) |
1023 | void DESTROY (ev_child *w) |
915 | CODE: |
1024 | CODE: |
916 | STOP (child, w); |
1025 | STOP (child, w); |
917 | e_destroy (w); |
1026 | e_destroy (w); |
918 | |
1027 | |
919 | void set (ev_child *w, int pid) |
1028 | void set (ev_child *w, int pid, int trace) |
920 | CODE: |
1029 | CODE: |
921 | RESET (child, w, (w, pid)); |
1030 | RESET (child, w, (w, pid, trace)); |
922 | |
1031 | |
923 | int pid (ev_child *w, int new_pid = 0) |
|
|
924 | CODE: |
|
|
925 | { |
|
|
926 | RETVAL = w->pid; |
|
|
927 | |
|
|
928 | if (items > 1) |
|
|
929 | RESET (child, w, (w, new_pid)); |
|
|
930 | } |
|
|
931 | OUTPUT: |
|
|
932 | RETVAL |
|
|
933 | |
|
|
934 | |
|
|
935 | int rstatus (ev_child *w) |
1032 | int pid (ev_child *w) |
936 | ALIAS: |
1033 | ALIAS: |
937 | rpid = 1 |
1034 | rpid = 1 |
|
|
1035 | rstatus = 2 |
938 | CODE: |
1036 | CODE: |
939 | RETVAL = ix ? w->rpid : w->rstatus; |
1037 | RETVAL = ix == 0 ? w->pid |
|
|
1038 | : ix == 1 ? w->rpid |
|
|
1039 | : w->rstatus; |
940 | OUTPUT: |
1040 | OUTPUT: |
941 | RETVAL |
1041 | RETVAL |
942 | |
1042 | |
943 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
1043 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
944 | |
1044 | |
… | |
… | |
995 | PPCODE: |
1095 | PPCODE: |
996 | { |
1096 | { |
997 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1097 | ev_statdata *s = ix ? &w->attr : &w->prev; |
998 | |
1098 | |
999 | if (ix == 1) |
1099 | if (ix == 1) |
1000 | ev_stat_stat (w); |
1100 | ev_stat_stat (e_loop (w), w); |
1001 | else if (!s->st_nlink) |
1101 | else if (!s->st_nlink) |
1002 | errno = ENOENT; |
1102 | errno = ENOENT; |
1003 | |
1103 | |
1004 | PL_statcache.st_dev = s->st_nlink; |
1104 | PL_statcache.st_dev = s->st_nlink; |
1005 | PL_statcache.st_ino = s->st_ino; |
1105 | PL_statcache.st_ino = s->st_ino; |
… | |
… | |
1032 | PUSHs (sv_2mortal (newSVuv (4096))); |
1132 | PUSHs (sv_2mortal (newSVuv (4096))); |
1033 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
1133 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
1034 | } |
1134 | } |
1035 | } |
1135 | } |
1036 | |
1136 | |
1037 | #ifndef _WIN32 |
|
|
1038 | |
|
|
1039 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
1137 | MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_ |
1040 | |
1138 | |
1041 | BOOT: |
1139 | void ev_embed_start (ev_embed *w) |
1042 | { |
1140 | CODE: |
1043 | HV *stash = gv_stashpv ("EV::DNS", 1); |
1141 | START (embed, w); |
1044 | |
1142 | |
1045 | static const struct { |
1143 | void ev_embed_stop (ev_embed *w) |
1046 | const char *name; |
1144 | CODE: |
1047 | IV iv; |
1145 | STOP (embed, w); |
1048 | } *civ, const_iv[] = { |
|
|
1049 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
1050 | const_iv (DNS_, ERR_NONE) |
|
|
1051 | const_iv (DNS_, ERR_FORMAT) |
|
|
1052 | const_iv (DNS_, ERR_SERVERFAILED) |
|
|
1053 | const_iv (DNS_, ERR_NOTEXIST) |
|
|
1054 | const_iv (DNS_, ERR_NOTIMPL) |
|
|
1055 | const_iv (DNS_, ERR_REFUSED) |
|
|
1056 | const_iv (DNS_, ERR_TRUNCATED) |
|
|
1057 | const_iv (DNS_, ERR_UNKNOWN) |
|
|
1058 | const_iv (DNS_, ERR_TIMEOUT) |
|
|
1059 | const_iv (DNS_, ERR_SHUTDOWN) |
|
|
1060 | const_iv (DNS_, IPv4_A) |
|
|
1061 | const_iv (DNS_, PTR) |
|
|
1062 | const_iv (DNS_, IPv6_AAAA) |
|
|
1063 | const_iv (DNS_, QUERY_NO_SEARCH) |
|
|
1064 | const_iv (DNS_, OPTION_SEARCH) |
|
|
1065 | const_iv (DNS_, OPTION_NAMESERVERS) |
|
|
1066 | const_iv (DNS_, OPTION_MISC) |
|
|
1067 | const_iv (DNS_, OPTIONS_ALL) |
|
|
1068 | const_iv (DNS_, NO_SEARCH) |
|
|
1069 | }; |
|
|
1070 | |
1146 | |
1071 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1147 | void DESTROY (ev_embed *w) |
1072 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1148 | CODE: |
1073 | } |
1149 | STOP (embed, w); |
|
|
1150 | e_destroy (w); |
1074 | |
1151 | |
1075 | int evdns_init () |
1152 | void set (ev_embed *w, struct ev_loop *loop) |
|
|
1153 | CODE: |
|
|
1154 | { |
|
|
1155 | sv_setsv (w->fh, ST (1)); |
|
|
1156 | RESET (embed, w, (w, loop)); |
|
|
1157 | } |
1076 | |
1158 | |
1077 | void evdns_shutdown (int fail_requests = 1) |
1159 | SV *other (ev_embed *w) |
|
|
1160 | CODE: |
|
|
1161 | RETVAL = newSVsv (w->fh); |
|
|
1162 | OUTPUT: |
|
|
1163 | RETVAL |
1078 | |
1164 | |
1079 | const char *evdns_err_to_string (int err) |
1165 | void ev_embed_sweep (ev_embed *w) |
|
|
1166 | C_ARGS: e_loop (w), w |
1080 | |
1167 | |
1081 | int evdns_nameserver_add (U32 address) |
1168 | MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_ |
1082 | |
1169 | |
1083 | int evdns_count_nameservers () |
1170 | void ev_async_start (ev_async *w) |
|
|
1171 | CODE: |
|
|
1172 | START (async, w); |
1084 | |
1173 | |
1085 | int evdns_clear_nameservers_and_suspend () |
1174 | void ev_async_stop (ev_async *w) |
|
|
1175 | CODE: |
|
|
1176 | STOP (async, w); |
1086 | |
1177 | |
1087 | int evdns_resume () |
1178 | void DESTROY (ev_async *w) |
|
|
1179 | CODE: |
|
|
1180 | STOP (async, w); |
|
|
1181 | e_destroy (w); |
1088 | |
1182 | |
1089 | int evdns_nameserver_ip_add (char *ip_as_string) |
1183 | void ev_async_send (ev_async *w) |
|
|
1184 | C_ARGS: e_loop (w), w |
1090 | |
1185 | |
1091 | int evdns_resolve_ipv4 (const char *name, int flags, SV *cb) |
1186 | SV *ev_async_async_pending (ev_async *w) |
1092 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1093 | |
|
|
1094 | int evdns_resolve_ipv6 (const char *name, int flags, SV *cb) |
|
|
1095 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1096 | |
|
|
1097 | int evdns_resolve_reverse (SV *addr, int flags, SV *cb) |
|
|
1098 | ALIAS: |
|
|
1099 | evdns_resolve_reverse_ipv6 = 1 |
|
|
1100 | CODE: |
1187 | CODE: |
1101 | { |
1188 | RETVAL = boolSV (ev_async_pending (w)); |
1102 | STRLEN len; |
1189 | OUTPUT: |
1103 | char *data = SvPVbyte (addr, len); |
|
|
1104 | if (len != (ix ? 16 : 4)) |
|
|
1105 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
|
|
1106 | |
|
|
1107 | RETVAL = ix |
1190 | RETVAL |
1108 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
|
|
1109 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
|
|
1110 | } |
|
|
1111 | OUTPUT: |
|
|
1112 | RETVAL |
|
|
1113 | |
1191 | |
1114 | int evdns_set_option (char *option, char *val, int flags) |
1192 | MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ |
1115 | |
1193 | |
1116 | int evdns_resolv_conf_parse (int flags, const char *filename) |
1194 | SV *new (SV *klass, unsigned int flags = 0) |
|
|
1195 | CODE: |
|
|
1196 | { |
|
|
1197 | struct ev_loop *loop = ev_loop_new (flags); |
1117 | |
1198 | |
1118 | #ifdef _WIN32 |
1199 | if (!loop) |
|
|
1200 | XSRETURN_UNDEF; |
1119 | |
1201 | |
1120 | int evdns_config_windows_nameservers () |
1202 | RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop); |
|
|
1203 | } |
|
|
1204 | OUTPUT: |
|
|
1205 | RETVAL |
|
|
1206 | |
|
|
1207 | void DESTROY (struct ev_loop *loop) |
|
|
1208 | CODE: |
|
|
1209 | if (loop != evapi.default_loop) /* global destruction sucks */ |
|
|
1210 | ev_loop_destroy (loop); |
|
|
1211 | |
|
|
1212 | void ev_loop_fork (struct ev_loop *loop) |
|
|
1213 | |
|
|
1214 | void ev_loop_verify (struct ev_loop *loop) |
|
|
1215 | |
|
|
1216 | NV ev_now (struct ev_loop *loop) |
|
|
1217 | |
|
|
1218 | void ev_now_update (struct ev_loop *loop) |
|
|
1219 | |
|
|
1220 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1221 | |
|
|
1222 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1223 | |
|
|
1224 | unsigned int ev_backend (struct ev_loop *loop) |
|
|
1225 | |
|
|
1226 | unsigned int ev_loop_count (struct ev_loop *loop) |
|
|
1227 | |
|
|
1228 | void ev_loop (struct ev_loop *loop, int flags = 0) |
|
|
1229 | |
|
|
1230 | void ev_unloop (struct ev_loop *loop, int how = 1) |
|
|
1231 | |
|
|
1232 | void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) |
|
|
1233 | |
|
|
1234 | #if 0 |
|
|
1235 | |
|
|
1236 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
|
|
1237 | CODE: |
|
|
1238 | { |
|
|
1239 | Signal signum = sv_signum (signal); |
|
|
1240 | CHECK_SIG (signal, signum); |
|
|
1241 | |
|
|
1242 | ev_feed_signal_event (loop, signum); |
|
|
1243 | } |
1121 | |
1244 | |
1122 | #endif |
1245 | #endif |
1123 | |
1246 | |
1124 | void evdns_search_clear () |
1247 | ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) |
|
|
1248 | ALIAS: |
|
|
1249 | io_ns = 1 |
|
|
1250 | CODE: |
|
|
1251 | { |
|
|
1252 | int fd = sv_fileno (fh); |
|
|
1253 | CHECK_FD (fh, fd); |
1125 | |
1254 | |
1126 | void evdns_search_add (char *domain) |
1255 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
|
|
1256 | RETVAL->fh = newSVsv (fh); |
|
|
1257 | ev_io_set (RETVAL, fd, events); |
|
|
1258 | if (!ix) START (io, RETVAL); |
|
|
1259 | } |
|
|
1260 | OUTPUT: |
|
|
1261 | RETVAL |
1127 | |
1262 | |
1128 | void evdns_search_ndots_set (int ndots) |
1263 | ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb) |
|
|
1264 | ALIAS: |
|
|
1265 | timer_ns = 1 |
|
|
1266 | INIT: |
|
|
1267 | CHECK_REPEAT (repeat); |
|
|
1268 | CODE: |
|
|
1269 | RETVAL = e_new (sizeof (ev_timer), cb, ST (0)); |
|
|
1270 | ev_timer_set (RETVAL, after, repeat); |
|
|
1271 | if (!ix) START (timer, RETVAL); |
|
|
1272 | OUTPUT: |
|
|
1273 | RETVAL |
|
|
1274 | |
|
|
1275 | SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb) |
|
|
1276 | ALIAS: |
|
|
1277 | periodic_ns = 1 |
|
|
1278 | INIT: |
|
|
1279 | CHECK_REPEAT (interval); |
|
|
1280 | CODE: |
|
|
1281 | { |
|
|
1282 | ev_periodic *w; |
|
|
1283 | w = e_new (sizeof (ev_periodic), cb, ST (0)); |
|
|
1284 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
1285 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
|
|
1286 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
|
|
1287 | if (!ix) START (periodic, w); |
|
|
1288 | } |
|
|
1289 | OUTPUT: |
|
|
1290 | RETVAL |
1129 | |
1291 | |
1130 | #if 0 |
1292 | #if 0 |
1131 | |
1293 | |
1132 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1294 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1133 | |
1295 | ALIAS: |
1134 | BOOT: |
1296 | signal_ns = 1 |
|
|
1297 | CODE: |
1135 | { |
1298 | { |
1136 | HV *stash = gv_stashpv ("EV::HTTP", 1); |
1299 | Signal signum = sv_signum (signal); |
|
|
1300 | CHECK_SIG (signal, signum); |
1137 | |
1301 | |
1138 | static const struct { |
1302 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1139 | const char *name; |
1303 | ev_signal_set (RETVAL, signum); |
1140 | IV iv; |
1304 | if (!ix) START (signal, RETVAL); |
1141 | } *civ, const_iv[] = { |
|
|
1142 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
1143 | const_iv (HTTP_, OK) |
|
|
1144 | const_iv (HTTP_, NOCONTENT) |
|
|
1145 | const_iv (HTTP_, MOVEPERM) |
|
|
1146 | const_iv (HTTP_, MOVETEMP) |
|
|
1147 | const_iv (HTTP_, NOTMODIFIED) |
|
|
1148 | const_iv (HTTP_, BADREQUEST) |
|
|
1149 | const_iv (HTTP_, NOTFOUND) |
|
|
1150 | const_iv (HTTP_, SERVUNAVAIL) |
|
|
1151 | const_iv (EVHTTP_, REQ_OWN_CONNECTION) |
|
|
1152 | const_iv (EVHTTP_, PROXY_REQUEST) |
|
|
1153 | const_iv (EVHTTP_, REQ_GET) |
|
|
1154 | const_iv (EVHTTP_, REQ_POST) |
|
|
1155 | const_iv (EVHTTP_, REQ_HEAD) |
|
|
1156 | const_iv (EVHTTP_, REQUEST) |
|
|
1157 | const_iv (EVHTTP_, RESPONSE) |
|
|
1158 | }; |
|
|
1159 | |
|
|
1160 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
1161 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
1162 | } |
1305 | } |
1163 | |
1306 | OUTPUT: |
1164 | MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_ |
1307 | RETVAL |
1165 | |
|
|
1166 | #HttpRequest new (SV *klass, SV *cb) |
|
|
1167 | |
|
|
1168 | #void DESTROY (struct evhttp_request *req); |
|
|
1169 | |
1308 | |
1170 | #endif |
1309 | #endif |
1171 | |
1310 | |
1172 | #endif |
1311 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
|
|
1312 | ALIAS: |
|
|
1313 | idle_ns = 1 |
|
|
1314 | CODE: |
|
|
1315 | RETVAL = e_new (sizeof (ev_idle), cb, ST (0)); |
|
|
1316 | ev_idle_set (RETVAL); |
|
|
1317 | if (!ix) START (idle, RETVAL); |
|
|
1318 | OUTPUT: |
|
|
1319 | RETVAL |
1173 | |
1320 | |
|
|
1321 | ev_prepare *prepare (struct ev_loop *loop, SV *cb) |
|
|
1322 | ALIAS: |
|
|
1323 | prepare_ns = 1 |
|
|
1324 | CODE: |
|
|
1325 | RETVAL = e_new (sizeof (ev_prepare), cb, ST (0)); |
|
|
1326 | ev_prepare_set (RETVAL); |
|
|
1327 | if (!ix) START (prepare, RETVAL); |
|
|
1328 | OUTPUT: |
|
|
1329 | RETVAL |
1174 | |
1330 | |
|
|
1331 | ev_check *check (struct ev_loop *loop, SV *cb) |
|
|
1332 | ALIAS: |
|
|
1333 | check_ns = 1 |
|
|
1334 | CODE: |
|
|
1335 | RETVAL = e_new (sizeof (ev_check), cb, ST (0)); |
|
|
1336 | ev_check_set (RETVAL); |
|
|
1337 | if (!ix) START (check, RETVAL); |
|
|
1338 | OUTPUT: |
|
|
1339 | RETVAL |
1175 | |
1340 | |
|
|
1341 | ev_fork *fork (struct ev_loop *loop, SV *cb) |
|
|
1342 | ALIAS: |
|
|
1343 | fork_ns = 1 |
|
|
1344 | CODE: |
|
|
1345 | RETVAL = e_new (sizeof (ev_fork), cb, ST (0)); |
|
|
1346 | ev_fork_set (RETVAL); |
|
|
1347 | if (!ix) START (fork, RETVAL); |
|
|
1348 | OUTPUT: |
|
|
1349 | RETVAL |
1176 | |
1350 | |
|
|
1351 | ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) |
|
|
1352 | ALIAS: |
|
|
1353 | child_ns = 1 |
|
|
1354 | CODE: |
|
|
1355 | RETVAL = e_new (sizeof (ev_child), cb, ST (0)); |
|
|
1356 | ev_child_set (RETVAL, pid, trace); |
|
|
1357 | if (!ix) START (child, RETVAL); |
|
|
1358 | OUTPUT: |
|
|
1359 | RETVAL |
1177 | |
1360 | |
|
|
1361 | ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) |
|
|
1362 | ALIAS: |
|
|
1363 | stat_ns = 1 |
|
|
1364 | CODE: |
|
|
1365 | RETVAL = e_new (sizeof (ev_stat), cb, ST (0)); |
|
|
1366 | RETVAL->fh = newSVsv (path); |
|
|
1367 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
|
|
1368 | if (!ix) START (stat, RETVAL); |
|
|
1369 | OUTPUT: |
|
|
1370 | RETVAL |
1178 | |
1371 | |
|
|
1372 | ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0) |
|
|
1373 | ALIAS: |
|
|
1374 | embed_ns = 1 |
|
|
1375 | CODE: |
|
|
1376 | { |
|
|
1377 | if (!(ev_backend (other) & ev_embeddable_backends ())) |
|
|
1378 | croak ("passed loop is not embeddable via EV::embed,"); |
1179 | |
1379 | |
|
|
1380 | RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); |
|
|
1381 | RETVAL->fh = newSVsv (ST (1)); |
|
|
1382 | ev_embed_set (RETVAL, other); |
|
|
1383 | if (!ix) START (embed, RETVAL); |
|
|
1384 | } |
|
|
1385 | OUTPUT: |
|
|
1386 | RETVAL |
|
|
1387 | |
|
|
1388 | ev_async *async (struct ev_loop *loop, SV *cb) |
|
|
1389 | ALIAS: |
|
|
1390 | async_ns = 1 |
|
|
1391 | CODE: |
|
|
1392 | RETVAL = e_new (sizeof (ev_async), cb, ST (0)); |
|
|
1393 | ev_async_set (RETVAL); |
|
|
1394 | if (!ix) START (async, RETVAL); |
|
|
1395 | OUTPUT: |
|
|
1396 | RETVAL |
|
|
1397 | |
|
|
1398 | void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) |
|
|
1399 | CODE: |
|
|
1400 | ev_once ( |
|
|
1401 | loop, |
|
|
1402 | sv_fileno (fh), events, |
|
|
1403 | SvOK (timeout) ? SvNV (timeout) : -1., |
|
|
1404 | e_once_cb, |
|
|
1405 | newSVsv (cb) |
|
|
1406 | ); |
|
|
1407 | |