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