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