… | |
… | |
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 TIMEOUT_NONE HUGE_VAL |
7 | /* fix perl api breakage */ |
8 | #define EV_USE_EPOLL 1 |
8 | #undef signal |
|
|
9 | #undef sigaction |
9 | |
10 | |
10 | #define EV_PROTOTYPES 1 |
11 | #define EV_PROTOTYPES 1 |
|
|
12 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
|
|
13 | #define EV_H <ev.h> |
11 | #include "EV/EVAPI.h" |
14 | #include "EV/EVAPI.h" |
12 | |
15 | |
|
|
16 | #define EV_SELECT_IS_WINSOCKET 0 |
|
|
17 | #ifdef _WIN32 |
|
|
18 | # define EV_SELECT_USE_FD_SET 0 |
|
|
19 | # define NFDBITS PERL_NFDBITS |
|
|
20 | # define fd_mask Perl_fd_mask |
|
|
21 | #endif |
|
|
22 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
13 | #include "libev/ev.c" |
23 | #include "libev/ev.c" |
14 | |
24 | |
|
|
25 | #ifndef _WIN32 |
|
|
26 | # include <pthread.h> |
|
|
27 | #endif |
|
|
28 | |
|
|
29 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
|
|
30 | |
|
|
31 | #define WFLAG_KEEPALIVE 1 |
|
|
32 | |
|
|
33 | #define UNREF(w) \ |
|
|
34 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
|
|
35 | && !ev_is_active (w)) \ |
|
|
36 | ev_unref (e_loop (w)); |
|
|
37 | |
|
|
38 | #define REF(w) \ |
|
|
39 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
|
|
40 | && ev_is_active (w)) \ |
|
|
41 | ev_ref (e_loop (w)); |
|
|
42 | |
|
|
43 | #define START(type,w) \ |
|
|
44 | do { \ |
|
|
45 | UNREF (w); \ |
|
|
46 | ev_ ## type ## _start (e_loop (w), w); \ |
|
|
47 | } while (0) |
|
|
48 | |
|
|
49 | #define STOP(type,w) \ |
|
|
50 | do { \ |
|
|
51 | REF (w); \ |
|
|
52 | ev_ ## type ## _stop (e_loop (w), w); \ |
|
|
53 | } while (0) |
|
|
54 | |
|
|
55 | #define RESET(type,w,seta) \ |
|
|
56 | do { \ |
|
|
57 | int active = ev_is_active (w); \ |
|
|
58 | if (active) STOP (type, w); \ |
|
|
59 | ev_ ## type ## _set seta; \ |
|
|
60 | if (active) START (type, w); \ |
|
|
61 | } while (0) |
|
|
62 | |
15 | typedef int Signal; |
63 | typedef int Signal; |
16 | |
64 | |
|
|
65 | static SV *default_loop_sv; |
|
|
66 | |
17 | static struct EVAPI evapi; |
67 | static struct EVAPI evapi; |
18 | |
68 | |
19 | static HV |
69 | static HV |
|
|
70 | *stash_loop, |
20 | *stash_watcher, |
71 | *stash_watcher, |
21 | *stash_io, |
72 | *stash_io, |
22 | *stash_timer, |
73 | *stash_timer, |
23 | *stash_periodic, |
74 | *stash_periodic, |
24 | *stash_signal, |
75 | *stash_signal, |
|
|
76 | *stash_child, |
|
|
77 | *stash_stat, |
25 | *stash_idle, |
78 | *stash_idle, |
26 | *stash_prepare, |
79 | *stash_prepare, |
27 | *stash_check, |
80 | *stash_check, |
28 | *stash_child; |
81 | *stash_embed, |
|
|
82 | *stash_fork, |
|
|
83 | *stash_async; |
29 | |
84 | |
|
|
85 | #ifndef SIG_SIZE |
|
|
86 | /* kudos to Slaven Rezic for the idea */ |
|
|
87 | static char sig_size [] = { SIG_NUM }; |
|
|
88 | # define SIG_SIZE (sizeof (sig_size) + 1) |
|
|
89 | #endif |
|
|
90 | |
30 | static int |
91 | static Signal |
31 | sv_signum (SV *sig) |
92 | sv_signum (SV *sig) |
32 | { |
93 | { |
33 | int signum; |
94 | Signal signum; |
34 | |
95 | |
35 | SvGETMAGIC (sig); |
96 | SvGETMAGIC (sig); |
36 | |
97 | |
37 | for (signum = 1; signum < SIG_SIZE; ++signum) |
98 | for (signum = 1; signum < SIG_SIZE; ++signum) |
38 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
99 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
39 | return signum; |
100 | return signum; |
40 | |
101 | |
41 | if (SvIV (sig) > 0) |
102 | signum = SvIV (sig); |
|
|
103 | |
|
|
104 | if (signum > 0 && signum < SIG_SIZE) |
42 | return SvIV (sig); |
105 | return signum; |
43 | |
106 | |
44 | return -1; |
107 | return -1; |
45 | } |
108 | } |
46 | |
109 | |
47 | ///////////////////////////////////////////////////////////////////////////// |
110 | ///////////////////////////////////////////////////////////////////////////// |
48 | // Event |
111 | // Event |
49 | |
112 | |
50 | static void e_cb (struct ev_watcher *w, int revents); |
113 | static void e_cb (EV_P_ ev_watcher *w, int revents); |
51 | |
114 | |
52 | static int |
115 | static int |
53 | sv_fileno (SV *fh) |
116 | sv_fileno (SV *fh) |
54 | { |
117 | { |
55 | SvGETMAGIC (fh); |
118 | SvGETMAGIC (fh); |
… | |
… | |
58 | fh = SvRV (fh); |
121 | fh = SvRV (fh); |
59 | |
122 | |
60 | if (SvTYPE (fh) == SVt_PVGV) |
123 | if (SvTYPE (fh) == SVt_PVGV) |
61 | return PerlIO_fileno (IoIFP (sv_2io (fh))); |
124 | return PerlIO_fileno (IoIFP (sv_2io (fh))); |
62 | |
125 | |
63 | if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff)) |
126 | if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL)) |
64 | return SvIV (fh); |
127 | return SvIV (fh); |
65 | |
128 | |
66 | return -1; |
129 | return -1; |
67 | } |
130 | } |
68 | |
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 | |
69 | static void * |
145 | static void * |
70 | e_new (int size, SV *cb_sv) |
146 | e_new (int size, SV *cb_sv, SV *loop) |
71 | { |
147 | { |
|
|
148 | SV *cv = cb_sv ? e_get_cv (cb_sv) : 0; |
72 | struct ev_watcher *w; |
149 | ev_watcher *w; |
73 | SV *self = NEWSV (0, size); |
150 | SV *self = NEWSV (0, size); |
74 | SvPOK_only (self); |
151 | SvPOK_only (self); |
75 | SvCUR_set (self, size); |
152 | SvCUR_set (self, size); |
76 | |
153 | |
77 | w = (struct ev_watcher *)SvPVX (self); |
154 | w = (ev_watcher *)SvPVX (self); |
78 | |
155 | |
79 | ev_watcher_init (w, e_cb); |
156 | ev_init (w, cv ? e_cb : 0); |
80 | |
157 | |
|
|
158 | w->loop = SvREFCNT_inc (SvRV (loop)); |
|
|
159 | w->e_flags = WFLAG_KEEPALIVE; |
|
|
160 | w->data = 0; |
81 | w->fh = 0; |
161 | w->fh = 0; |
82 | w->cb_sv = newSVsv (cb_sv); |
162 | w->cb_sv = SvREFCNT_inc (cv); |
83 | w->self = self; |
163 | w->self = self; |
84 | |
164 | |
85 | return (void *)w; |
165 | return (void *)w; |
86 | } |
166 | } |
87 | |
167 | |
|
|
168 | static void |
|
|
169 | e_destroy (void *w_) |
|
|
170 | { |
|
|
171 | ev_watcher *w = (ev_watcher *)w_; |
|
|
172 | |
|
|
173 | SvREFCNT_dec (w->loop ); w->loop = 0; |
|
|
174 | SvREFCNT_dec (w->fh ); w->fh = 0; |
|
|
175 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
|
|
176 | SvREFCNT_dec (w->data ); w->data = 0; |
|
|
177 | } |
|
|
178 | |
88 | static SV * |
179 | static SV * |
89 | e_bless (struct ev_watcher *w, HV *stash) |
180 | e_bless (ev_watcher *w, HV *stash) |
90 | { |
181 | { |
91 | SV *rv; |
182 | SV *rv; |
92 | |
183 | |
93 | if (SvOBJECT (w->self)) |
184 | if (SvOBJECT (w->self)) |
94 | rv = newRV_inc (w->self); |
185 | rv = newRV_inc (w->self); |
… | |
… | |
100 | } |
191 | } |
101 | |
192 | |
102 | return rv; |
193 | return rv; |
103 | } |
194 | } |
104 | |
195 | |
|
|
196 | static SV *sv_events_cache; |
|
|
197 | |
105 | static void |
198 | static void |
106 | e_cb (struct ev_watcher *w, int revents) |
199 | e_cb (EV_P_ ev_watcher *w, int revents) |
107 | { |
200 | { |
108 | dSP; |
201 | dSP; |
109 | I32 mark = SP - PL_stack_base; |
202 | I32 mark = SP - PL_stack_base; |
110 | SV *sv_self, *sv_events, *sv_status = 0; |
203 | SV *sv_self, *sv_events; |
111 | static SV *sv_events_cache; |
|
|
112 | |
204 | |
113 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
205 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
114 | |
206 | |
115 | if (sv_events_cache) |
207 | if (sv_events_cache) |
116 | { |
208 | { |
… | |
… | |
123 | PUSHMARK (SP); |
215 | PUSHMARK (SP); |
124 | EXTEND (SP, 2); |
216 | EXTEND (SP, 2); |
125 | PUSHs (sv_self); |
217 | PUSHs (sv_self); |
126 | PUSHs (sv_events); |
218 | PUSHs (sv_events); |
127 | |
219 | |
128 | if (revents & EV_CHILD) |
|
|
129 | XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status)); |
|
|
130 | |
|
|
131 | PUTBACK; |
220 | PUTBACK; |
132 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
221 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
133 | SP = PL_stack_base + mark; PUTBACK; |
|
|
134 | |
222 | |
135 | SvREFCNT_dec (sv_self); |
223 | SvREFCNT_dec (sv_self); |
136 | SvREFCNT_dec (sv_status); |
|
|
137 | |
224 | |
138 | if (sv_events_cache) |
225 | if (sv_events_cache) |
139 | SvREFCNT_dec (sv_events); |
226 | SvREFCNT_dec (sv_events); |
140 | else |
227 | else |
141 | sv_events_cache = sv_events; |
228 | sv_events_cache = sv_events; |
|
|
229 | |
|
|
230 | if (SvTRUE (ERRSV)) |
|
|
231 | { |
|
|
232 | SPAGAIN; |
|
|
233 | PUSHMARK (SP); |
|
|
234 | PUTBACK; |
|
|
235 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
236 | } |
|
|
237 | |
|
|
238 | SP = PL_stack_base + mark; |
|
|
239 | PUTBACK; |
|
|
240 | } |
|
|
241 | |
|
|
242 | static void |
|
|
243 | e_once_cb (int revents, void *arg) |
|
|
244 | { |
|
|
245 | dSP; |
|
|
246 | I32 mark = SP - PL_stack_base; |
|
|
247 | SV *sv_events; |
|
|
248 | |
|
|
249 | if (sv_events_cache) |
|
|
250 | { |
|
|
251 | sv_events = sv_events_cache; sv_events_cache = 0; |
|
|
252 | SvIV_set (sv_events, revents); |
|
|
253 | } |
|
|
254 | else |
|
|
255 | sv_events = newSViv (revents); |
|
|
256 | |
|
|
257 | PUSHMARK (SP); |
|
|
258 | XPUSHs (sv_events); |
|
|
259 | |
|
|
260 | PUTBACK; |
|
|
261 | call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL); |
|
|
262 | |
|
|
263 | SvREFCNT_dec ((SV *)arg); |
|
|
264 | |
|
|
265 | if (sv_events_cache) |
|
|
266 | SvREFCNT_dec (sv_events); |
|
|
267 | else |
|
|
268 | sv_events_cache = sv_events; |
|
|
269 | |
|
|
270 | if (SvTRUE (ERRSV)) |
|
|
271 | { |
|
|
272 | SPAGAIN; |
|
|
273 | PUSHMARK (SP); |
|
|
274 | PUTBACK; |
|
|
275 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
276 | } |
|
|
277 | |
|
|
278 | SP = PL_stack_base + mark; |
|
|
279 | PUTBACK; |
|
|
280 | } |
|
|
281 | |
|
|
282 | static ev_tstamp |
|
|
283 | e_periodic_cb (ev_periodic *w, ev_tstamp now) |
|
|
284 | { |
|
|
285 | ev_tstamp retval; |
|
|
286 | int count; |
|
|
287 | dSP; |
|
|
288 | |
|
|
289 | ENTER; |
|
|
290 | SAVETMPS; |
|
|
291 | |
|
|
292 | PUSHMARK (SP); |
|
|
293 | EXTEND (SP, 2); |
|
|
294 | PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */ |
|
|
295 | PUSHs (newSVnv (now)); |
|
|
296 | |
|
|
297 | PUTBACK; |
|
|
298 | count = call_sv (w->fh, G_SCALAR | G_EVAL); |
|
|
299 | SPAGAIN; |
142 | |
300 | |
143 | if (SvTRUE (ERRSV)) |
301 | if (SvTRUE (ERRSV)) |
144 | { |
302 | { |
145 | PUSHMARK (SP); |
303 | PUSHMARK (SP); |
146 | PUTBACK; |
304 | PUTBACK; |
147 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
305 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
148 | SP = PL_stack_base + mark; PUTBACK; |
306 | SPAGAIN; |
149 | } |
307 | } |
150 | } |
|
|
151 | |
308 | |
152 | #if 0 |
309 | if (count > 0) |
153 | ///////////////////////////////////////////////////////////////////////////// |
|
|
154 | // DNS |
|
|
155 | |
|
|
156 | static void |
|
|
157 | dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) |
|
|
158 | { |
|
|
159 | dSP; |
|
|
160 | SV *cb = (SV *)arg; |
|
|
161 | |
|
|
162 | ENTER; |
|
|
163 | SAVETMPS; |
|
|
164 | PUSHMARK (SP); |
|
|
165 | EXTEND (SP, count + 3); |
|
|
166 | PUSHs (sv_2mortal (newSViv (result))); |
|
|
167 | |
|
|
168 | if (result == DNS_ERR_NONE && ttl >= 0) |
|
|
169 | { |
310 | { |
170 | int i; |
311 | retval = SvNV (TOPs); |
171 | |
312 | |
172 | PUSHs (sv_2mortal (newSViv (type))); |
313 | if (retval < now) |
173 | PUSHs (sv_2mortal (newSViv (ttl))); |
314 | retval = now; |
174 | |
|
|
175 | for (i = 0; i < count; ++i) |
|
|
176 | switch (type) |
|
|
177 | { |
|
|
178 | case DNS_IPv6_AAAA: |
|
|
179 | PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16))); |
|
|
180 | break; |
|
|
181 | case DNS_IPv4_A: |
|
|
182 | PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4))); |
|
|
183 | break; |
|
|
184 | case DNS_PTR: |
|
|
185 | PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0))); |
|
|
186 | break; |
|
|
187 | } |
|
|
188 | } |
315 | } |
189 | |
316 | else |
190 | PUTBACK; |
317 | retval = now; |
191 | call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); |
|
|
192 | |
318 | |
193 | FREETMPS; |
319 | FREETMPS; |
194 | |
|
|
195 | if (SvTRUE (ERRSV)) |
|
|
196 | { |
|
|
197 | PUSHMARK (SP); |
|
|
198 | PUTBACK; |
|
|
199 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
200 | } |
|
|
201 | |
|
|
202 | LEAVE; |
320 | LEAVE; |
|
|
321 | |
|
|
322 | return retval; |
203 | } |
323 | } |
204 | #endif |
|
|
205 | |
324 | |
206 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
325 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
207 | croak (# repeat " value must be >= 0"); |
326 | croak (# repeat " value must be >= 0"); |
208 | |
327 | |
209 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
328 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
210 | croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); |
329 | croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); |
211 | |
330 | |
|
|
331 | #define CHECK_SIG(sv,num) if ((num) < 0) \ |
|
|
332 | croak ("illegal signal number or name: %s", SvPV_nolen (sv)); |
|
|
333 | |
212 | ///////////////////////////////////////////////////////////////////////////// |
334 | ///////////////////////////////////////////////////////////////////////////// |
213 | // XS interface functions |
335 | // XS interface functions |
214 | |
336 | |
215 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
337 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
216 | |
338 | |
217 | PROTOTYPES: ENABLE |
339 | PROTOTYPES: ENABLE |
218 | |
340 | |
219 | BOOT: |
341 | BOOT: |
220 | { |
342 | { |
221 | int i; |
|
|
222 | HV *stash = gv_stashpv ("EV", 1); |
343 | HV *stash = gv_stashpv ("EV", 1); |
223 | |
344 | |
224 | static const struct { |
345 | static const struct { |
225 | const char *name; |
346 | const char *name; |
226 | IV iv; |
347 | IV iv; |
227 | } *civ, const_iv[] = { |
348 | } *civ, const_iv[] = { |
228 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
349 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
350 | const_iv (EV_, MINPRI) |
|
|
351 | const_iv (EV_, MAXPRI) |
|
|
352 | |
229 | const_iv (EV_, UNDEF) |
353 | const_iv (EV_, UNDEF) |
230 | const_iv (EV_, NONE) |
354 | const_iv (EV_, NONE) |
231 | const_iv (EV_, TIMEOUT) |
355 | const_iv (EV_, TIMEOUT) |
232 | const_iv (EV_, READ) |
356 | const_iv (EV_, READ) |
233 | const_iv (EV_, WRITE) |
357 | const_iv (EV_, WRITE) |
… | |
… | |
236 | const_iv (EV_, CHECK) |
360 | const_iv (EV_, CHECK) |
237 | const_iv (EV_, ERROR) |
361 | const_iv (EV_, ERROR) |
238 | |
362 | |
239 | const_iv (EV, LOOP_ONESHOT) |
363 | const_iv (EV, LOOP_ONESHOT) |
240 | const_iv (EV, LOOP_NONBLOCK) |
364 | const_iv (EV, LOOP_NONBLOCK) |
241 | |
|
|
242 | const_iv (EV, METHOD_NONE) |
365 | const_iv (EV, UNLOOP_ONE) |
|
|
366 | const_iv (EV, UNLOOP_ALL) |
|
|
367 | |
243 | const_iv (EV, METHOD_SELECT) |
368 | const_iv (EV, BACKEND_SELECT) |
|
|
369 | const_iv (EV, BACKEND_POLL) |
244 | const_iv (EV, METHOD_EPOLL) |
370 | const_iv (EV, BACKEND_EPOLL) |
|
|
371 | const_iv (EV, BACKEND_KQUEUE) |
|
|
372 | const_iv (EV, BACKEND_DEVPOLL) |
|
|
373 | const_iv (EV, BACKEND_PORT) |
|
|
374 | const_iv (EV, FLAG_AUTO) |
|
|
375 | const_iv (EV, FLAG_NOENV) |
|
|
376 | const_iv (EV, FLAG_FORKCHECK) |
245 | }; |
377 | }; |
246 | |
378 | |
247 | 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; ) |
248 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
380 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
249 | |
381 | |
|
|
382 | stash_loop = gv_stashpv ("EV::Loop" , 1); |
250 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
383 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
251 | stash_io = gv_stashpv ("EV::Io" , 1); |
384 | stash_io = gv_stashpv ("EV::IO" , 1); |
252 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
385 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
253 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
386 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
254 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
387 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
255 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
388 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
256 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
389 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
257 | stash_check = gv_stashpv ("EV::Check" , 1); |
390 | stash_check = gv_stashpv ("EV::Check" , 1); |
258 | stash_child = gv_stashpv ("EV::Child" , 1); |
391 | stash_child = gv_stashpv ("EV::Child" , 1); |
|
|
392 | stash_embed = gv_stashpv ("EV::Embed" , 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); |
259 | |
396 | |
260 | { |
397 | { |
261 | SV *sv = perl_get_sv ("EV::API", TRUE); |
398 | SV *sv = perl_get_sv ("EV::API", TRUE); |
262 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
399 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
263 | |
400 | |
264 | /* the poor man's shared library emulator */ |
401 | /* the poor man's shared library emulator */ |
265 | evapi.ver = EV_API_VERSION; |
402 | evapi.ver = EV_API_VERSION; |
266 | evapi.rev = EV_API_REVISION; |
403 | evapi.rev = EV_API_REVISION; |
267 | evapi.sv_fileno = sv_fileno; |
404 | evapi.sv_fileno = sv_fileno; |
268 | evapi.sv_signum = sv_signum; |
405 | evapi.sv_signum = sv_signum; |
269 | evapi.now = &ev_now; |
406 | evapi.supported_backends = ev_supported_backends (); |
270 | evapi.method = &ev_method; |
407 | evapi.recommended_backends = ev_recommended_backends (); |
271 | evapi.loop_done = &ev_loop_done; |
408 | evapi.embeddable_backends = ev_embeddable_backends (); |
272 | evapi.time = ev_time; |
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; |
|
|
415 | evapi.now = ev_now; |
|
|
416 | evapi.now_update = ev_now_update; |
|
|
417 | evapi.backend = ev_backend; |
|
|
418 | evapi.unloop = ev_unloop; |
|
|
419 | evapi.ref = ev_ref; |
|
|
420 | evapi.unref = ev_unref; |
273 | evapi.loop = ev_loop; |
421 | evapi.loop = ev_loop; |
274 | evapi.once = ev_once; |
422 | evapi.once = ev_once; |
275 | evapi.io_start = ev_io_start; |
423 | evapi.io_start = ev_io_start; |
276 | evapi.io_stop = ev_io_stop; |
424 | evapi.io_stop = ev_io_stop; |
277 | evapi.timer_start = ev_timer_start; |
425 | evapi.timer_start = ev_timer_start; |
278 | evapi.timer_stop = ev_timer_stop; |
426 | evapi.timer_stop = ev_timer_stop; |
279 | evapi.timer_again = ev_timer_again; |
427 | evapi.timer_again = ev_timer_again; |
280 | evapi.periodic_start = ev_periodic_start; |
428 | evapi.periodic_start = ev_periodic_start; |
281 | evapi.periodic_stop = ev_periodic_stop; |
429 | evapi.periodic_stop = ev_periodic_stop; |
282 | evapi.signal_start = ev_signal_start; |
430 | evapi.signal_start = ev_signal_start; |
283 | evapi.signal_stop = ev_signal_stop; |
431 | evapi.signal_stop = ev_signal_stop; |
284 | evapi.idle_start = ev_idle_start; |
432 | evapi.idle_start = ev_idle_start; |
285 | evapi.idle_stop = ev_idle_stop; |
433 | evapi.idle_stop = ev_idle_stop; |
286 | evapi.prepare_start = ev_prepare_start; |
434 | evapi.prepare_start = ev_prepare_start; |
287 | evapi.prepare_stop = ev_prepare_stop; |
435 | evapi.prepare_stop = ev_prepare_stop; |
288 | evapi.check_start = ev_check_start; |
436 | evapi.check_start = ev_check_start; |
289 | evapi.check_stop = ev_check_stop; |
437 | evapi.check_stop = ev_check_stop; |
290 | evapi.child_start = ev_child_start; |
438 | evapi.child_start = ev_child_start; |
291 | evapi.child_stop = ev_child_stop; |
439 | evapi.child_stop = ev_child_stop; |
|
|
440 | evapi.stat_start = ev_stat_start; |
|
|
441 | evapi.stat_stop = ev_stat_stop; |
|
|
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; |
292 | |
453 | |
293 | sv_setiv (sv, (IV)&evapi); |
454 | sv_setiv (sv, (IV)&evapi); |
294 | SvREADONLY_on (sv); |
455 | SvREADONLY_on (sv); |
295 | } |
456 | } |
296 | |
457 | #ifndef _WIN32 |
297 | pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child); |
458 | pthread_atfork (0, 0, ev_default_fork); |
|
|
459 | #endif |
298 | } |
460 | } |
|
|
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 () |
299 | |
493 | |
300 | NV ev_now () |
494 | NV ev_now () |
301 | CODE: |
495 | C_ARGS: evapi.default_loop |
302 | RETVAL = ev_now; |
|
|
303 | OUTPUT: |
|
|
304 | RETVAL |
|
|
305 | |
496 | |
306 | int ev_method () |
497 | void ev_now_update () |
307 | CODE: |
498 | C_ARGS: evapi.default_loop |
308 | RETVAL = ev_method; |
|
|
309 | OUTPUT: |
|
|
310 | RETVAL |
|
|
311 | |
499 | |
312 | NV ev_time () |
500 | unsigned int ev_backend () |
|
|
501 | C_ARGS: evapi.default_loop |
313 | |
502 | |
314 | void ev_init (int flags = 0) |
503 | unsigned int ev_loop_count () |
|
|
504 | C_ARGS: evapi.default_loop |
|
|
505 | |
|
|
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 |
315 | |
511 | |
316 | void ev_loop (int flags = 0) |
512 | void ev_loop (int flags = 0) |
|
|
513 | C_ARGS: evapi.default_loop, flags |
317 | |
514 | |
318 | void ev_loop_done (int value = 1) |
515 | void ev_unloop (int how = EVUNLOOP_ONE) |
319 | CODE: |
516 | C_ARGS: evapi.default_loop, how |
320 | ev_loop_done = value; |
|
|
321 | |
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 | } |
|
|
529 | |
322 | struct ev_io *io (SV *fh, int events, SV *cb) |
530 | ev_io *io (SV *fh, int events, SV *cb) |
323 | ALIAS: |
531 | ALIAS: |
324 | io_ns = 1 |
532 | io_ns = 1 |
325 | CODE: |
533 | CODE: |
326 | { |
534 | { |
327 | int fd = sv_fileno (fh); |
535 | int fd = sv_fileno (fh); |
328 | CHECK_FD (fh, fd); |
536 | CHECK_FD (fh, fd); |
329 | |
537 | |
330 | RETVAL = e_new (sizeof (struct ev_io), cb); |
538 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
331 | RETVAL->fh = newSVsv (fh); |
539 | RETVAL->fh = newSVsv (fh); |
332 | ev_io_set (RETVAL, fd, events); |
540 | ev_io_set (RETVAL, fd, events); |
333 | if (!ix) ev_io_start (RETVAL); |
541 | if (!ix) START (io, RETVAL); |
334 | } |
542 | } |
335 | OUTPUT: |
543 | OUTPUT: |
336 | RETVAL |
544 | RETVAL |
337 | |
545 | |
338 | struct ev_timer *timer (NV after, NV repeat, SV *cb) |
546 | ev_timer *timer (NV after, NV repeat, SV *cb) |
339 | ALIAS: |
547 | ALIAS: |
340 | timer_ns = 1 |
548 | timer_ns = 1 |
341 | INIT: |
549 | INIT: |
342 | CHECK_REPEAT (repeat); |
550 | CHECK_REPEAT (repeat); |
343 | CODE: |
551 | CODE: |
344 | RETVAL = e_new (sizeof (struct ev_timer), cb); |
552 | RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv); |
345 | ev_timer_set (RETVAL, after, repeat); |
553 | ev_timer_set (RETVAL, after, repeat); |
346 | if (!ix) ev_timer_start (RETVAL); |
554 | if (!ix) START (timer, RETVAL); |
347 | OUTPUT: |
555 | OUTPUT: |
348 | RETVAL |
556 | RETVAL |
349 | |
557 | |
350 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
558 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
351 | ALIAS: |
559 | ALIAS: |
352 | periodic_ns = 1 |
560 | periodic_ns = 1 |
353 | INIT: |
561 | INIT: |
354 | CHECK_REPEAT (interval); |
562 | CHECK_REPEAT (interval); |
355 | CODE: |
563 | CODE: |
356 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
564 | { |
357 | ev_periodic_set (RETVAL, at, interval); |
565 | ev_periodic *w; |
358 | if (!ix) ev_periodic_start (RETVAL); |
566 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
|
|
567 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
|
|
568 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
|
|
569 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
|
|
570 | if (!ix) START (periodic, w); |
|
|
571 | } |
359 | OUTPUT: |
572 | OUTPUT: |
360 | RETVAL |
573 | RETVAL |
361 | |
574 | |
362 | struct ev_signal *signal (Signal signum, SV *cb) |
575 | ev_signal *signal (SV *signal, SV *cb) |
363 | ALIAS: |
576 | ALIAS: |
364 | signal_ns = 1 |
577 | signal_ns = 1 |
365 | CODE: |
578 | CODE: |
|
|
579 | { |
|
|
580 | Signal signum = sv_signum (signal); |
|
|
581 | CHECK_SIG (signal, signum); |
|
|
582 | |
366 | RETVAL = e_new (sizeof (struct ev_signal), cb); |
583 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
367 | ev_signal_set (RETVAL, signum); |
584 | ev_signal_set (RETVAL, signum); |
368 | if (!ix) ev_signal_start (RETVAL); |
585 | if (!ix) START (signal, RETVAL); |
|
|
586 | } |
369 | OUTPUT: |
587 | OUTPUT: |
370 | RETVAL |
588 | RETVAL |
371 | |
589 | |
372 | struct ev_idle *idle (SV *cb) |
590 | ev_idle *idle (SV *cb) |
373 | ALIAS: |
591 | ALIAS: |
374 | idle_ns = 1 |
592 | idle_ns = 1 |
375 | CODE: |
593 | CODE: |
376 | RETVAL = e_new (sizeof (struct ev_idle), cb); |
594 | RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv); |
377 | ev_idle_set (RETVAL); |
595 | ev_idle_set (RETVAL); |
378 | if (!ix) ev_idle_start (RETVAL); |
596 | if (!ix) START (idle, RETVAL); |
379 | OUTPUT: |
597 | OUTPUT: |
380 | RETVAL |
598 | RETVAL |
381 | |
599 | |
382 | struct ev_prepare *prepare (SV *cb) |
600 | ev_prepare *prepare (SV *cb) |
383 | ALIAS: |
601 | ALIAS: |
384 | prepare_ns = 1 |
602 | prepare_ns = 1 |
385 | CODE: |
603 | CODE: |
386 | RETVAL = e_new (sizeof (struct ev_prepare), cb); |
604 | RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv); |
387 | ev_prepare_set (RETVAL); |
605 | ev_prepare_set (RETVAL); |
388 | if (!ix) ev_prepare_start (RETVAL); |
606 | if (!ix) START (prepare, RETVAL); |
389 | OUTPUT: |
607 | OUTPUT: |
390 | RETVAL |
608 | RETVAL |
391 | |
609 | |
392 | struct ev_check *check (SV *cb) |
610 | ev_check *check (SV *cb) |
393 | ALIAS: |
611 | ALIAS: |
394 | check_ns = 1 |
612 | check_ns = 1 |
395 | CODE: |
613 | CODE: |
396 | RETVAL = e_new (sizeof (struct ev_check), cb); |
614 | RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv); |
397 | ev_check_set (RETVAL); |
615 | ev_check_set (RETVAL); |
398 | if (!ix) ev_check_start (RETVAL); |
616 | if (!ix) START (check, RETVAL); |
399 | OUTPUT: |
617 | OUTPUT: |
400 | RETVAL |
618 | RETVAL |
401 | |
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 | |
402 | struct ev_child *child (int pid, SV *cb) |
630 | ev_child *child (int pid, int trace, SV *cb) |
403 | ALIAS: |
631 | ALIAS: |
404 | check_ns = 1 |
632 | child_ns = 1 |
405 | CODE: |
633 | CODE: |
406 | RETVAL = e_new (sizeof (struct ev_check), cb); |
634 | RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); |
407 | ev_child_set (RETVAL, pid); |
635 | ev_child_set (RETVAL, pid, trace); |
408 | if (!ix) ev_child_start (RETVAL); |
636 | if (!ix) START (child, RETVAL); |
409 | OUTPUT: |
637 | OUTPUT: |
410 | RETVAL |
638 | RETVAL |
411 | |
639 | |
|
|
640 | ev_stat *stat (SV *path, NV interval, SV *cb) |
|
|
641 | ALIAS: |
|
|
642 | stat_ns = 1 |
|
|
643 | CODE: |
|
|
644 | RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv); |
|
|
645 | RETVAL->fh = newSVsv (path); |
|
|
646 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
|
|
647 | if (!ix) START (stat, RETVAL); |
|
|
648 | OUTPUT: |
|
|
649 | RETVAL |
|
|
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 | |
|
|
677 | void once (SV *fh, int events, SV *timeout, SV *cb) |
|
|
678 | CODE: |
|
|
679 | ev_once ( |
|
|
680 | evapi.default_loop, |
|
|
681 | sv_fileno (fh), events, |
|
|
682 | SvOK (timeout) ? SvNV (timeout) : -1., |
|
|
683 | e_once_cb, |
|
|
684 | newSVsv (cb) |
|
|
685 | ); |
412 | |
686 | |
413 | PROTOTYPES: DISABLE |
687 | PROTOTYPES: DISABLE |
414 | |
688 | |
415 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
689 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
416 | |
690 | |
417 | int ev_is_active (struct ev_watcher *w) |
691 | int ev_is_active (ev_watcher *w) |
418 | |
692 | |
|
|
693 | int ev_is_pending (ev_watcher *w) |
|
|
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 | |
|
|
704 | int keepalive (ev_watcher *w, int new_value = 0) |
|
|
705 | CODE: |
|
|
706 | { |
|
|
707 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
|
|
708 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
|
|
709 | |
|
|
710 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
|
|
711 | { |
|
|
712 | REF (w); |
|
|
713 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
|
|
714 | UNREF (w); |
|
|
715 | } |
|
|
716 | } |
|
|
717 | OUTPUT: |
|
|
718 | RETVAL |
|
|
719 | |
419 | SV *cb (struct ev_watcher *w, SV *new_cb = 0) |
720 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
420 | CODE: |
721 | CODE: |
421 | { |
722 | { |
422 | RETVAL = newSVsv (w->cb_sv); |
|
|
423 | |
|
|
424 | if (items > 1) |
723 | if (items > 1) |
425 | 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); |
426 | } |
731 | } |
427 | OUTPUT: |
732 | OUTPUT: |
428 | RETVAL |
733 | RETVAL |
429 | |
734 | |
430 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
735 | SV *data (ev_watcher *w, SV *new_data = 0) |
431 | CODE: |
736 | CODE: |
432 | w->cb (w, revents); |
737 | { |
|
|
738 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
433 | |
739 | |
|
|
740 | if (items > 1) |
|
|
741 | { |
|
|
742 | SvREFCNT_dec (w->data); |
|
|
743 | w->data = newSVsv (new_data); |
|
|
744 | } |
|
|
745 | } |
|
|
746 | OUTPUT: |
|
|
747 | RETVAL |
|
|
748 | |
|
|
749 | SV *loop (ev_watcher *w) |
|
|
750 | CODE: |
|
|
751 | RETVAL = newRV_inc (w->loop); |
|
|
752 | OUTPUT: |
|
|
753 | RETVAL |
|
|
754 | |
|
|
755 | int priority (ev_watcher *w, int new_priority = 0) |
|
|
756 | CODE: |
|
|
757 | { |
|
|
758 | RETVAL = w->priority; |
|
|
759 | |
|
|
760 | if (items > 1) |
|
|
761 | { |
|
|
762 | int active = ev_is_active (w); |
|
|
763 | |
|
|
764 | if (active) |
|
|
765 | { |
|
|
766 | /* grrr. */ |
|
|
767 | PUSHMARK (SP); |
|
|
768 | XPUSHs (ST (0)); |
|
|
769 | PUTBACK; |
|
|
770 | call_method ("stop", G_DISCARD | G_VOID); |
|
|
771 | } |
|
|
772 | |
|
|
773 | ev_set_priority (w, new_priority); |
|
|
774 | |
|
|
775 | if (active) |
|
|
776 | { |
|
|
777 | PUSHMARK (SP); |
|
|
778 | XPUSHs (ST (0)); |
|
|
779 | PUTBACK; |
|
|
780 | call_method ("start", G_DISCARD | G_VOID); |
|
|
781 | } |
|
|
782 | } |
|
|
783 | } |
|
|
784 | OUTPUT: |
|
|
785 | RETVAL |
|
|
786 | |
434 | MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ |
787 | MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_ |
435 | |
788 | |
436 | void ev_io_start (struct ev_io *w) |
789 | void ev_io_start (ev_io *w) |
|
|
790 | CODE: |
|
|
791 | START (io, w); |
437 | |
792 | |
438 | void ev_io_stop (struct ev_io *w) |
793 | void ev_io_stop (ev_io *w) |
|
|
794 | CODE: |
|
|
795 | STOP (io, w); |
439 | |
796 | |
440 | void DESTROY (struct ev_io *w) |
797 | void DESTROY (ev_io *w) |
441 | CODE: |
798 | CODE: |
|
|
799 | STOP (io, w); |
442 | ev_io_stop (w); |
800 | e_destroy (w); |
443 | |
801 | |
444 | void set (struct ev_io *w, SV *fh, int events) |
802 | void set (ev_io *w, SV *fh, int events) |
445 | CODE: |
803 | CODE: |
446 | { |
804 | { |
447 | int active = w->active; |
|
|
448 | int fd = sv_fileno (fh); |
805 | int fd = sv_fileno (fh); |
449 | CHECK_FD (fh, fd); |
806 | CHECK_FD (fh, fd); |
450 | |
807 | |
451 | if (active) ev_io_stop (w); |
|
|
452 | |
|
|
453 | sv_setsv (w->fh, fh); |
808 | sv_setsv (w->fh, fh); |
454 | ev_io_set (w, fd, events); |
809 | RESET (io, w, (w, fd, events)); |
455 | |
|
|
456 | if (active) ev_io_start (w); |
|
|
457 | } |
810 | } |
458 | |
811 | |
459 | SV *fh (struct ev_io *w, SV *new_fh = 0) |
812 | SV *fh (ev_io *w, SV *new_fh = 0) |
460 | CODE: |
813 | CODE: |
461 | { |
814 | { |
462 | RETVAL = newSVsv (w->fh); |
|
|
463 | |
|
|
464 | if (items > 1) |
815 | if (items > 1) |
465 | { |
816 | { |
466 | int active = w->active; |
817 | int fd = sv_fileno (new_fh); |
467 | if (active) ev_io_stop (w); |
818 | CHECK_FD (new_fh, fd); |
468 | |
819 | |
469 | sv_setsv (w->fh, new_fh); |
820 | RETVAL = w->fh; |
470 | ev_io_set (w, sv_fileno (w->fh), w->events); |
821 | w->fh = newSVsv (new_fh); |
471 | |
822 | |
472 | if (active) ev_io_start (w); |
823 | RESET (io, w, (w, fd, w->events)); |
473 | } |
824 | } |
|
|
825 | else |
|
|
826 | RETVAL = newSVsv (w->fh); |
474 | } |
827 | } |
475 | OUTPUT: |
828 | OUTPUT: |
476 | RETVAL |
829 | RETVAL |
477 | |
830 | |
478 | short events (struct ev_io *w, short new_events = EV_UNDEF) |
831 | int events (ev_io *w, int new_events = EV_UNDEF) |
479 | CODE: |
832 | CODE: |
480 | { |
833 | { |
481 | RETVAL = w->events; |
834 | RETVAL = w->events; |
|
|
835 | |
|
|
836 | if (items > 1) |
|
|
837 | RESET (io, w, (w, w->fd, new_events)); |
|
|
838 | } |
|
|
839 | OUTPUT: |
|
|
840 | RETVAL |
|
|
841 | |
|
|
842 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
|
|
843 | |
|
|
844 | void ev_signal_start (ev_signal *w) |
|
|
845 | CODE: |
|
|
846 | START (signal, w); |
|
|
847 | |
|
|
848 | void ev_signal_stop (ev_signal *w) |
|
|
849 | CODE: |
|
|
850 | STOP (signal, w); |
|
|
851 | |
|
|
852 | void DESTROY (ev_signal *w) |
|
|
853 | CODE: |
|
|
854 | STOP (signal, w); |
|
|
855 | e_destroy (w); |
|
|
856 | |
|
|
857 | void set (ev_signal *w, SV *signal) |
|
|
858 | CODE: |
|
|
859 | { |
|
|
860 | Signal signum = sv_signum (signal); |
|
|
861 | CHECK_SIG (signal, signum); |
|
|
862 | |
|
|
863 | RESET (signal, w, (w, signum)); |
|
|
864 | } |
|
|
865 | |
|
|
866 | int signal (ev_signal *w, SV *new_signal = 0) |
|
|
867 | CODE: |
|
|
868 | { |
|
|
869 | RETVAL = w->signum; |
482 | |
870 | |
483 | if (items > 1) |
871 | if (items > 1) |
484 | { |
872 | { |
485 | int active = w->active; |
873 | Signal signum = sv_signum (new_signal); |
486 | if (active) ev_io_stop (w); |
874 | CHECK_SIG (new_signal, signum); |
487 | |
875 | |
488 | ev_io_set (w, w->fd, new_events); |
876 | RESET (signal, w, (w, signum)); |
489 | |
|
|
490 | if (active) ev_io_start (w); |
|
|
491 | } |
877 | } |
492 | } |
878 | } |
493 | OUTPUT: |
879 | OUTPUT: |
494 | RETVAL |
880 | RETVAL |
495 | |
881 | |
496 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
|
|
497 | |
|
|
498 | void ev_signal_start (struct ev_signal *w) |
|
|
499 | |
|
|
500 | void ev_signal_stop (struct ev_signal *w) |
|
|
501 | |
|
|
502 | void DESTROY (struct ev_signal *w) |
|
|
503 | CODE: |
|
|
504 | ev_signal_stop (w); |
|
|
505 | |
|
|
506 | void set (struct ev_signal *w, SV *signal = 0) |
|
|
507 | CODE: |
|
|
508 | { |
|
|
509 | Signal signum = sv_signum (signal); /* may croak here */ |
|
|
510 | int active = w->active; |
|
|
511 | |
|
|
512 | if (active) ev_signal_stop (w); |
|
|
513 | ev_signal_set (w, signum); |
|
|
514 | if (active) ev_signal_start (w); |
|
|
515 | } |
|
|
516 | |
|
|
517 | MODULE = EV PACKAGE = EV::Time |
|
|
518 | |
|
|
519 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
882 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
520 | |
883 | |
521 | void ev_timer_start (struct ev_timer *w) |
884 | void ev_timer_start (ev_timer *w) |
522 | INIT: |
885 | INIT: |
523 | CHECK_REPEAT (w->repeat); |
886 | CHECK_REPEAT (w->repeat); |
|
|
887 | CODE: |
|
|
888 | START (timer, w); |
524 | |
889 | |
525 | void ev_timer_stop (struct ev_timer *w) |
890 | void ev_timer_stop (ev_timer *w) |
|
|
891 | CODE: |
|
|
892 | STOP (timer, w); |
526 | |
893 | |
527 | void ev_timer_again (struct ev_timer *w) |
894 | void ev_timer_again (ev_timer *w) |
528 | INIT: |
895 | INIT: |
529 | CHECK_REPEAT (w->repeat); |
896 | CHECK_REPEAT (w->repeat); |
|
|
897 | CODE: |
|
|
898 | REF (w); |
|
|
899 | ev_timer_again (e_loop (w), w); |
|
|
900 | UNREF (w); |
530 | |
901 | |
531 | void DESTROY (struct ev_timer *w) |
902 | void DESTROY (ev_timer *w) |
532 | CODE: |
903 | CODE: |
|
|
904 | STOP (timer, w); |
533 | ev_timer_stop (w); |
905 | e_destroy (w); |
534 | |
906 | |
535 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
907 | void set (ev_timer *w, NV after, NV repeat = 0.) |
536 | INIT: |
908 | INIT: |
537 | CHECK_REPEAT (repeat); |
909 | CHECK_REPEAT (repeat); |
538 | CODE: |
910 | CODE: |
539 | { |
|
|
540 | int active = w->active; |
|
|
541 | if (active) ev_timer_stop (w); |
|
|
542 | ev_timer_set (w, after, repeat); |
911 | RESET (timer, w, (w, after, repeat)); |
543 | if (active) ev_timer_start (w); |
|
|
544 | } |
|
|
545 | |
912 | |
546 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
913 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
547 | |
914 | |
548 | void ev_periodic_start (struct ev_periodic *w) |
915 | void ev_periodic_start (ev_periodic *w) |
549 | INIT: |
916 | INIT: |
550 | CHECK_REPEAT (w->interval); |
917 | CHECK_REPEAT (w->interval); |
|
|
918 | CODE: |
|
|
919 | START (periodic, w); |
551 | |
920 | |
552 | void ev_periodic_stop (struct ev_periodic *w) |
921 | void ev_periodic_stop (ev_periodic *w) |
|
|
922 | CODE: |
|
|
923 | STOP (periodic, w); |
553 | |
924 | |
|
|
925 | void ev_periodic_again (ev_periodic *w) |
|
|
926 | CODE: |
|
|
927 | REF (w); |
|
|
928 | ev_periodic_again (e_loop (w), w); |
|
|
929 | UNREF (w); |
|
|
930 | |
554 | void DESTROY (struct ev_periodic *w) |
931 | void DESTROY (ev_periodic *w) |
555 | CODE: |
932 | CODE: |
556 | ev_periodic_stop (w); |
933 | STOP (periodic, w); |
|
|
934 | e_destroy (w); |
557 | |
935 | |
558 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
936 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
559 | INIT: |
937 | INIT: |
560 | CHECK_REPEAT (interval); |
938 | CHECK_REPEAT (interval); |
561 | CODE: |
939 | CODE: |
562 | { |
940 | { |
563 | int active = w->active; |
941 | SvREFCNT_dec (w->fh); |
564 | if (active) ev_periodic_stop (w); |
942 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
565 | ev_periodic_set (w, at, interval); |
943 | |
566 | if (active) ev_periodic_start (w); |
944 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
567 | } |
945 | } |
|
|
946 | |
|
|
947 | NV at (ev_periodic *w) |
|
|
948 | CODE: |
|
|
949 | RETVAL = ev_periodic_at (w); |
|
|
950 | OUTPUT: |
|
|
951 | RETVAL |
568 | |
952 | |
569 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
953 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
570 | |
954 | |
571 | void ev_idle_start (struct ev_idle *w) |
955 | void ev_idle_start (ev_idle *w) |
|
|
956 | CODE: |
|
|
957 | START (idle, w); |
572 | |
958 | |
573 | void ev_idle_stop (struct ev_idle *w) |
959 | void ev_idle_stop (ev_idle *w) |
|
|
960 | CODE: |
|
|
961 | STOP (idle, w); |
574 | |
962 | |
575 | void DESTROY (struct ev_idle *w) |
963 | void DESTROY (ev_idle *w) |
576 | CODE: |
964 | CODE: |
|
|
965 | STOP (idle, w); |
577 | ev_idle_stop (w); |
966 | e_destroy (w); |
578 | |
967 | |
579 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ |
968 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_ |
580 | |
969 | |
581 | void ev_prepare_start (struct ev_prepare *w) |
970 | void ev_prepare_start (ev_prepare *w) |
|
|
971 | CODE: |
|
|
972 | START (prepare, w); |
582 | |
973 | |
583 | void ev_prepare_stop (struct ev_prepare *w) |
974 | void ev_prepare_stop (ev_prepare *w) |
|
|
975 | CODE: |
|
|
976 | STOP (prepare, w); |
584 | |
977 | |
585 | void DESTROY (struct ev_prepare *w) |
978 | void DESTROY (ev_prepare *w) |
586 | CODE: |
979 | CODE: |
587 | ev_prepare_stop (w); |
980 | STOP (prepare, w); |
|
|
981 | e_destroy (w); |
588 | |
982 | |
589 | MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ |
983 | MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ |
590 | |
984 | |
591 | void ev_check_start (struct ev_check *w) |
985 | void ev_check_start (ev_check *w) |
|
|
986 | CODE: |
|
|
987 | START (check, w); |
592 | |
988 | |
593 | void ev_check_stop (struct ev_check *w) |
989 | void ev_check_stop (ev_check *w) |
|
|
990 | CODE: |
|
|
991 | STOP (check, w); |
594 | |
992 | |
595 | void DESTROY (struct ev_check *w) |
993 | void DESTROY (ev_check *w) |
596 | CODE: |
994 | CODE: |
|
|
995 | STOP (check, w); |
597 | ev_check_stop (w); |
996 | e_destroy (w); |
|
|
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); |
598 | |
1012 | |
599 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
1013 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
600 | |
1014 | |
601 | void ev_child_start (struct ev_child *w) |
1015 | void ev_child_start (ev_child *w) |
|
|
1016 | CODE: |
|
|
1017 | START (child, w); |
602 | |
1018 | |
603 | void ev_child_stop (struct ev_child *w) |
1019 | void ev_child_stop (ev_child *w) |
|
|
1020 | CODE: |
|
|
1021 | STOP (child, w); |
604 | |
1022 | |
605 | void DESTROY (struct ev_child *w) |
1023 | void DESTROY (ev_child *w) |
|
|
1024 | CODE: |
|
|
1025 | STOP (child, w); |
|
|
1026 | e_destroy (w); |
|
|
1027 | |
|
|
1028 | void set (ev_child *w, int pid, int trace) |
|
|
1029 | CODE: |
|
|
1030 | RESET (child, w, (w, pid, trace)); |
|
|
1031 | |
|
|
1032 | int pid (ev_child *w) |
|
|
1033 | ALIAS: |
|
|
1034 | rpid = 1 |
|
|
1035 | rstatus = 2 |
|
|
1036 | CODE: |
|
|
1037 | RETVAL = ix == 0 ? w->pid |
|
|
1038 | : ix == 1 ? w->rpid |
|
|
1039 | : w->rstatus; |
|
|
1040 | OUTPUT: |
|
|
1041 | RETVAL |
|
|
1042 | |
|
|
1043 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
|
|
1044 | |
|
|
1045 | void ev_stat_start (ev_stat *w) |
|
|
1046 | CODE: |
|
|
1047 | START (stat, w); |
|
|
1048 | |
|
|
1049 | void ev_stat_stop (ev_stat *w) |
|
|
1050 | CODE: |
|
|
1051 | STOP (stat, w); |
|
|
1052 | |
|
|
1053 | void DESTROY (ev_stat *w) |
|
|
1054 | CODE: |
|
|
1055 | STOP (stat, w); |
|
|
1056 | e_destroy (w); |
|
|
1057 | |
|
|
1058 | void set (ev_stat *w, SV *path, NV interval) |
|
|
1059 | CODE: |
|
|
1060 | { |
|
|
1061 | sv_setsv (w->fh, path); |
|
|
1062 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval)); |
|
|
1063 | } |
|
|
1064 | |
|
|
1065 | SV *path (ev_stat *w, SV *new_path = 0) |
|
|
1066 | CODE: |
|
|
1067 | { |
|
|
1068 | RETVAL = SvREFCNT_inc (w->fh); |
|
|
1069 | |
|
|
1070 | if (items > 1) |
|
|
1071 | { |
|
|
1072 | SvREFCNT_dec (w->fh); |
|
|
1073 | w->fh = newSVsv (new_path); |
|
|
1074 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval)); |
|
|
1075 | } |
|
|
1076 | } |
|
|
1077 | OUTPUT: |
|
|
1078 | RETVAL |
|
|
1079 | |
|
|
1080 | NV interval (ev_stat *w, NV new_interval = 0.) |
|
|
1081 | CODE: |
|
|
1082 | { |
|
|
1083 | RETVAL = w->interval; |
|
|
1084 | |
|
|
1085 | if (items > 1) |
|
|
1086 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
|
|
1087 | } |
|
|
1088 | OUTPUT: |
|
|
1089 | RETVAL |
|
|
1090 | |
|
|
1091 | void prev (ev_stat *w) |
|
|
1092 | ALIAS: |
|
|
1093 | stat = 1 |
|
|
1094 | attr = 2 |
606 | CODE: |
1095 | PPCODE: |
|
|
1096 | { |
|
|
1097 | ev_statdata *s = ix ? &w->attr : &w->prev; |
|
|
1098 | |
|
|
1099 | if (ix == 1) |
|
|
1100 | ev_stat_stat (e_loop (w), w); |
|
|
1101 | else if (!s->st_nlink) |
|
|
1102 | errno = ENOENT; |
|
|
1103 | |
|
|
1104 | PL_statcache.st_dev = s->st_nlink; |
|
|
1105 | PL_statcache.st_ino = s->st_ino; |
|
|
1106 | PL_statcache.st_mode = s->st_mode; |
|
|
1107 | PL_statcache.st_nlink = s->st_nlink; |
|
|
1108 | PL_statcache.st_uid = s->st_uid; |
|
|
1109 | PL_statcache.st_gid = s->st_gid; |
|
|
1110 | PL_statcache.st_rdev = s->st_rdev; |
|
|
1111 | PL_statcache.st_size = s->st_size; |
|
|
1112 | PL_statcache.st_atime = s->st_atime; |
|
|
1113 | PL_statcache.st_mtime = s->st_mtime; |
|
|
1114 | PL_statcache.st_ctime = s->st_ctime; |
|
|
1115 | |
|
|
1116 | if (GIMME_V == G_SCALAR) |
|
|
1117 | XPUSHs (boolSV (s->st_nlink)); |
|
|
1118 | else if (GIMME_V == G_ARRAY && s->st_nlink) |
|
|
1119 | { |
|
|
1120 | EXTEND (SP, 13); |
|
|
1121 | PUSHs (sv_2mortal (newSViv (s->st_dev))); |
|
|
1122 | PUSHs (sv_2mortal (newSViv (s->st_ino))); |
|
|
1123 | PUSHs (sv_2mortal (newSVuv (s->st_mode))); |
|
|
1124 | PUSHs (sv_2mortal (newSVuv (s->st_nlink))); |
|
|
1125 | PUSHs (sv_2mortal (newSViv (s->st_uid))); |
|
|
1126 | PUSHs (sv_2mortal (newSViv (s->st_gid))); |
|
|
1127 | PUSHs (sv_2mortal (newSViv (s->st_rdev))); |
|
|
1128 | PUSHs (sv_2mortal (newSVnv ((NV)s->st_size))); |
|
|
1129 | PUSHs (sv_2mortal (newSVnv (s->st_atime))); |
|
|
1130 | PUSHs (sv_2mortal (newSVnv (s->st_mtime))); |
|
|
1131 | PUSHs (sv_2mortal (newSVnv (s->st_ctime))); |
|
|
1132 | PUSHs (sv_2mortal (newSVuv (4096))); |
|
|
1133 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
|
|
1134 | } |
|
|
1135 | } |
|
|
1136 | |
|
|
1137 | MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_ |
|
|
1138 | |
|
|
1139 | void ev_embed_start (ev_embed *w) |
|
|
1140 | CODE: |
|
|
1141 | START (embed, w); |
|
|
1142 | |
|
|
1143 | void ev_embed_stop (ev_embed *w) |
|
|
1144 | CODE: |
|
|
1145 | STOP (embed, w); |
|
|
1146 | |
|
|
1147 | void DESTROY (ev_embed *w) |
|
|
1148 | CODE: |
|
|
1149 | STOP (embed, w); |
607 | ev_child_stop (w); |
1150 | e_destroy (w); |
608 | |
1151 | |
609 | void set (struct ev_child *w, int pid) |
1152 | void set (ev_embed *w, struct ev_loop *loop) |
610 | CODE: |
1153 | CODE: |
611 | { |
1154 | { |
612 | int active = w->active; |
1155 | sv_setsv (w->fh, ST (1)); |
613 | if (active) ev_child_stop (w); |
1156 | RESET (embed, w, (w, loop)); |
614 | ev_child_set (w, pid); |
|
|
615 | if (active) ev_child_start (w); |
|
|
616 | } |
1157 | } |
617 | |
1158 | |
618 | int status (struct ev_child *w) |
1159 | SV *other (ev_embed *w) |
619 | CODE: |
1160 | CODE: |
620 | RETVAL = w->status; |
1161 | RETVAL = newSVsv (w->fh); |
621 | OUTPUT: |
1162 | OUTPUT: |
622 | RETVAL |
1163 | RETVAL |
|
|
1164 | |
|
|
1165 | void ev_embed_sweep (ev_embed *w) |
|
|
1166 | C_ARGS: e_loop (w), w |
|
|
1167 | |
|
|
1168 | MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_ |
|
|
1169 | |
|
|
1170 | void ev_async_start (ev_async *w) |
|
|
1171 | CODE: |
|
|
1172 | START (async, w); |
|
|
1173 | |
|
|
1174 | void ev_async_stop (ev_async *w) |
|
|
1175 | CODE: |
|
|
1176 | STOP (async, w); |
|
|
1177 | |
|
|
1178 | void DESTROY (ev_async *w) |
|
|
1179 | CODE: |
|
|
1180 | STOP (async, w); |
|
|
1181 | e_destroy (w); |
|
|
1182 | |
|
|
1183 | void ev_async_send (ev_async *w) |
|
|
1184 | C_ARGS: e_loop (w), w |
|
|
1185 | |
|
|
1186 | SV *ev_async_async_pending (ev_async *w) |
|
|
1187 | CODE: |
|
|
1188 | RETVAL = boolSV (ev_async_pending (w)); |
|
|
1189 | OUTPUT: |
|
|
1190 | RETVAL |
|
|
1191 | |
|
|
1192 | MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ |
|
|
1193 | |
|
|
1194 | SV *new (SV *klass, unsigned int flags = 0) |
|
|
1195 | CODE: |
|
|
1196 | { |
|
|
1197 | struct ev_loop *loop = ev_loop_new (flags); |
|
|
1198 | |
|
|
1199 | if (!loop) |
|
|
1200 | XSRETURN_UNDEF; |
|
|
1201 | |
|
|
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) |
623 | |
1233 | |
624 | #if 0 |
1234 | #if 0 |
625 | |
1235 | |
626 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
1236 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
627 | |
1237 | CODE: |
628 | BOOT: |
|
|
629 | { |
1238 | { |
630 | HV *stash = gv_stashpv ("EV::DNS", 1); |
1239 | Signal signum = sv_signum (signal); |
|
|
1240 | CHECK_SIG (signal, signum); |
631 | |
1241 | |
632 | static const struct { |
1242 | ev_feed_signal_event (loop, signum); |
633 | const char *name; |
|
|
634 | IV iv; |
|
|
635 | } *civ, const_iv[] = { |
|
|
636 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
637 | const_iv (DNS_, ERR_NONE) |
|
|
638 | const_iv (DNS_, ERR_FORMAT) |
|
|
639 | const_iv (DNS_, ERR_SERVERFAILED) |
|
|
640 | const_iv (DNS_, ERR_NOTEXIST) |
|
|
641 | const_iv (DNS_, ERR_NOTIMPL) |
|
|
642 | const_iv (DNS_, ERR_REFUSED) |
|
|
643 | const_iv (DNS_, ERR_TRUNCATED) |
|
|
644 | const_iv (DNS_, ERR_UNKNOWN) |
|
|
645 | const_iv (DNS_, ERR_TIMEOUT) |
|
|
646 | const_iv (DNS_, ERR_SHUTDOWN) |
|
|
647 | const_iv (DNS_, IPv4_A) |
|
|
648 | const_iv (DNS_, PTR) |
|
|
649 | const_iv (DNS_, IPv6_AAAA) |
|
|
650 | const_iv (DNS_, QUERY_NO_SEARCH) |
|
|
651 | const_iv (DNS_, OPTION_SEARCH) |
|
|
652 | const_iv (DNS_, OPTION_NAMESERVERS) |
|
|
653 | const_iv (DNS_, OPTION_MISC) |
|
|
654 | const_iv (DNS_, OPTIONS_ALL) |
|
|
655 | const_iv (DNS_, NO_SEARCH) |
|
|
656 | }; |
|
|
657 | |
|
|
658 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
659 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
660 | } |
1243 | } |
661 | |
|
|
662 | int evdns_init () |
|
|
663 | |
|
|
664 | void evdns_shutdown (int fail_requests = 1) |
|
|
665 | |
|
|
666 | const char *evdns_err_to_string (int err) |
|
|
667 | |
|
|
668 | int evdns_nameserver_add (U32 address) |
|
|
669 | |
|
|
670 | int evdns_count_nameservers () |
|
|
671 | |
|
|
672 | int evdns_clear_nameservers_and_suspend () |
|
|
673 | |
|
|
674 | int evdns_resume () |
|
|
675 | |
|
|
676 | int evdns_nameserver_ip_add (char *ip_as_string) |
|
|
677 | |
|
|
678 | int evdns_resolve_ipv4 (const char *name, int flags, SV *cb) |
|
|
679 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
680 | |
|
|
681 | int evdns_resolve_ipv6 (const char *name, int flags, SV *cb) |
|
|
682 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
683 | |
|
|
684 | int evdns_resolve_reverse (SV *addr, int flags, SV *cb) |
|
|
685 | ALIAS: |
|
|
686 | evdns_resolve_reverse_ipv6 = 1 |
|
|
687 | CODE: |
|
|
688 | { |
|
|
689 | STRLEN len; |
|
|
690 | char *data = SvPVbyte (addr, len); |
|
|
691 | if (len != (ix ? 16 : 4)) |
|
|
692 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
|
|
693 | |
|
|
694 | RETVAL = ix |
|
|
695 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
|
|
696 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
|
|
697 | } |
|
|
698 | OUTPUT: |
|
|
699 | RETVAL |
|
|
700 | |
|
|
701 | int evdns_set_option (char *option, char *val, int flags) |
|
|
702 | |
|
|
703 | int evdns_resolv_conf_parse (int flags, const char *filename) |
|
|
704 | |
|
|
705 | #ifdef MS_WINDOWS |
|
|
706 | |
|
|
707 | int evdns_config_windows_nameservers () |
|
|
708 | |
1244 | |
709 | #endif |
1245 | #endif |
710 | |
1246 | |
711 | void evdns_search_clear () |
1247 | ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) |
712 | |
1248 | ALIAS: |
713 | void evdns_search_add (char *domain) |
1249 | io_ns = 1 |
714 | |
1250 | CODE: |
715 | void evdns_search_ndots_set (int ndots) |
|
|
716 | |
|
|
717 | |
|
|
718 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
|
|
719 | |
|
|
720 | BOOT: |
|
|
721 | { |
1251 | { |
722 | HV *stash = gv_stashpv ("EV::HTTP", 1); |
1252 | int fd = sv_fileno (fh); |
|
|
1253 | CHECK_FD (fh, fd); |
723 | |
1254 | |
724 | static const struct { |
1255 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
725 | const char *name; |
1256 | RETVAL->fh = newSVsv (fh); |
726 | IV iv; |
1257 | ev_io_set (RETVAL, fd, events); |
727 | } *civ, const_iv[] = { |
1258 | if (!ix) START (io, RETVAL); |
728 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
729 | const_iv (HTTP_, OK) |
|
|
730 | const_iv (HTTP_, NOCONTENT) |
|
|
731 | const_iv (HTTP_, MOVEPERM) |
|
|
732 | const_iv (HTTP_, MOVETEMP) |
|
|
733 | const_iv (HTTP_, NOTMODIFIED) |
|
|
734 | const_iv (HTTP_, BADREQUEST) |
|
|
735 | const_iv (HTTP_, NOTFOUND) |
|
|
736 | const_iv (HTTP_, SERVUNAVAIL) |
|
|
737 | const_iv (EVHTTP_, REQ_OWN_CONNECTION) |
|
|
738 | const_iv (EVHTTP_, PROXY_REQUEST) |
|
|
739 | const_iv (EVHTTP_, REQ_GET) |
|
|
740 | const_iv (EVHTTP_, REQ_POST) |
|
|
741 | const_iv (EVHTTP_, REQ_HEAD) |
|
|
742 | const_iv (EVHTTP_, REQUEST) |
|
|
743 | const_iv (EVHTTP_, RESPONSE) |
|
|
744 | }; |
|
|
745 | |
|
|
746 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
747 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
748 | } |
1259 | } |
|
|
1260 | OUTPUT: |
|
|
1261 | RETVAL |
749 | |
1262 | |
750 | MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_ |
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 |
751 | |
1274 | |
752 | #HttpRequest new (SV *klass, SV *cb) |
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 |
753 | |
1291 | |
754 | #void DESTROY (struct evhttp_request *req); |
1292 | #if 0 |
|
|
1293 | |
|
|
1294 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
|
|
1295 | ALIAS: |
|
|
1296 | signal_ns = 1 |
|
|
1297 | CODE: |
|
|
1298 | { |
|
|
1299 | Signal signum = sv_signum (signal); |
|
|
1300 | CHECK_SIG (signal, signum); |
|
|
1301 | |
|
|
1302 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
|
|
1303 | ev_signal_set (RETVAL, signum); |
|
|
1304 | if (!ix) START (signal, RETVAL); |
|
|
1305 | } |
|
|
1306 | OUTPUT: |
|
|
1307 | RETVAL |
755 | |
1308 | |
756 | #endif |
1309 | #endif |
757 | |
1310 | |
|
|
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 |
758 | |
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 |
759 | |
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 |
760 | |
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 |
761 | |
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 |
762 | |
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 |
763 | |
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,"); |
764 | |
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 | |