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 TIMEOUT_NONE HUGE_VAL |
|
|
8 | #define HAVE_EPOLL 1 |
9 | |
9 | |
10 | #define EV_COMMON \ |
10 | #define EV_PROTOTYPES 1 |
11 | SV *self; /* contains this struct */ \ |
|
|
12 | SV *cb_sv, *fh; |
|
|
13 | |
|
|
14 | #include "EV/EVAPI.h" |
11 | #include "EV/EVAPI.h" |
15 | |
12 | |
16 | #include "libev/ev.c" |
13 | #include "libev/ev.c" |
17 | |
14 | |
18 | typedef int Signal; |
15 | typedef int Signal; |
… | |
… | |
25 | *stash_time, |
22 | *stash_time, |
26 | *stash_timer, |
23 | *stash_timer, |
27 | *stash_periodic, |
24 | *stash_periodic, |
28 | *stash_signal, |
25 | *stash_signal, |
29 | *stash_idle, |
26 | *stash_idle, |
|
|
27 | *stash_prepare, |
30 | *stash_check; |
28 | *stash_check, |
|
|
29 | *stash_child; |
31 | |
30 | |
32 | static int |
31 | static int |
33 | sv_signum (SV *sig) |
32 | sv_signum (SV *sig) |
34 | { |
33 | { |
35 | int signum; |
34 | int signum; |
… | |
… | |
40 | for (signum = 1; signum < SIG_SIZE; ++signum) |
39 | for (signum = 1; signum < SIG_SIZE; ++signum) |
41 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
40 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
42 | return signum; |
41 | return signum; |
43 | |
42 | |
44 | return -1; |
43 | 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 | } |
44 | } |
61 | |
45 | |
62 | ///////////////////////////////////////////////////////////////////////////// |
46 | ///////////////////////////////////////////////////////////////////////////// |
63 | // Event |
47 | // Event |
64 | |
48 | |
… | |
… | |
219 | ///////////////////////////////////////////////////////////////////////////// |
203 | ///////////////////////////////////////////////////////////////////////////// |
220 | // XS interface functions |
204 | // XS interface functions |
221 | |
205 | |
222 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
206 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
223 | |
207 | |
|
|
208 | PROTOTYPES: ENABLE |
|
|
209 | |
224 | BOOT: |
210 | BOOT: |
225 | { |
211 | { |
226 | int i; |
212 | int i; |
227 | HV *stash = gv_stashpv ("EV", 1); |
213 | HV *stash = gv_stashpv ("EV", 1); |
228 | |
214 | |
229 | static const struct { |
215 | static const struct { |
230 | const char *name; |
216 | const char *name; |
231 | IV iv; |
217 | IV iv; |
232 | } *civ, const_iv[] = { |
218 | } *civ, const_iv[] = { |
233 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
219 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
220 | const_iv (EV_, UNDEF) |
234 | const_iv (EV_, NONE) |
221 | const_iv (EV_, NONE) |
235 | const_iv (EV_, TIMEOUT) |
222 | const_iv (EV_, TIMEOUT) |
236 | const_iv (EV_, READ) |
223 | const_iv (EV_, READ) |
237 | const_iv (EV_, WRITE) |
224 | const_iv (EV_, WRITE) |
238 | const_iv (EV_, SIGNAL) |
225 | const_iv (EV_, SIGNAL) |
239 | const_iv (EV_, IDLE) |
226 | const_iv (EV_, IDLE) |
240 | const_iv (EV_, CHECK) |
227 | const_iv (EV_, CHECK) |
|
|
228 | const_iv (EV_, ERROR) |
241 | |
229 | |
242 | const_iv (EV, LOOP_ONESHOT) |
230 | const_iv (EV, LOOP_ONESHOT) |
243 | const_iv (EV, LOOP_NONBLOCK) |
231 | const_iv (EV, LOOP_NONBLOCK) |
244 | |
232 | |
245 | const_iv (EV, METHOD_NONE) |
233 | const_iv (EV, METHOD_NONE) |
… | |
… | |
255 | stash_time = gv_stashpv ("EV::Time" , 1); |
243 | stash_time = gv_stashpv ("EV::Time" , 1); |
256 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
244 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
257 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
245 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
258 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
246 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
259 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
247 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
|
|
248 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
260 | stash_check = gv_stashpv ("EV::Check" , 1); |
249 | stash_check = gv_stashpv ("EV::Check" , 1); |
|
|
250 | stash_child = gv_stashpv ("EV::Child" , 1); |
261 | |
251 | |
262 | { |
252 | { |
263 | SV *sv = perl_get_sv ("EV::API", TRUE); |
253 | SV *sv = perl_get_sv ("EV::API", TRUE); |
264 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
254 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
265 | |
255 | |
266 | /* the poor man's shared library emulator */ |
256 | /* the poor man's shared library emulator */ |
267 | evapi.ver = EV_API_VERSION; |
257 | evapi.ver = EV_API_VERSION; |
268 | evapi.rev = EV_API_REVISION; |
258 | evapi.rev = EV_API_REVISION; |
269 | evapi.once = api_once; |
|
|
270 | evapi.sv_fileno = sv_fileno; |
259 | evapi.sv_fileno = sv_fileno; |
271 | evapi.sv_signum = sv_signum; |
260 | evapi.sv_signum = sv_signum; |
272 | evapi.now = &ev_now; |
261 | evapi.now = &ev_now; |
273 | evapi.method = &ev_method; |
262 | evapi.method = &ev_method; |
274 | evapi.loop_done = &ev_loop_done; |
263 | evapi.loop_done = &ev_loop_done; |
275 | evapi.time = ev_time; |
264 | evapi.time = ev_time; |
276 | evapi.loop = ev_loop; |
265 | evapi.loop = ev_loop; |
|
|
266 | evapi.once = ev_once; |
277 | evapi.io_start = evio_start; |
267 | evapi.io_start = evio_start; |
278 | evapi.io_stop = evio_stop; |
268 | evapi.io_stop = evio_stop; |
279 | evapi.timer_start = evtimer_start; |
269 | evapi.timer_start = evtimer_start; |
280 | evapi.timer_stop = evtimer_stop; |
270 | evapi.timer_stop = evtimer_stop; |
281 | evapi.timer_again = evtimer_again; |
271 | evapi.timer_again = evtimer_again; |
… | |
… | |
283 | evapi.periodic_stop = evperiodic_stop; |
273 | evapi.periodic_stop = evperiodic_stop; |
284 | evapi.signal_start = evsignal_start; |
274 | evapi.signal_start = evsignal_start; |
285 | evapi.signal_stop = evsignal_stop; |
275 | evapi.signal_stop = evsignal_stop; |
286 | evapi.idle_start = evidle_start; |
276 | evapi.idle_start = evidle_start; |
287 | evapi.idle_stop = evidle_stop; |
277 | evapi.idle_stop = evidle_stop; |
|
|
278 | evapi.prepare_start = evprepare_start; |
|
|
279 | evapi.prepare_stop = evprepare_stop; |
288 | evapi.check_start = evcheck_start; |
280 | evapi.check_start = evcheck_start; |
289 | evapi.check_stop = evcheck_stop; |
281 | evapi.check_stop = evcheck_stop; |
290 | |
282 | |
291 | sv_setiv (sv, (IV)&evapi); |
283 | sv_setiv (sv, (IV)&evapi); |
292 | SvREADONLY_on (sv); |
284 | SvREADONLY_on (sv); |
… | |
… | |
314 | void ev_loop_done (int value = 1) |
306 | void ev_loop_done (int value = 1) |
315 | CODE: |
307 | CODE: |
316 | ev_loop_done = value; |
308 | ev_loop_done = value; |
317 | |
309 | |
318 | struct ev_io *io (SV *fh, int events, SV *cb) |
310 | struct ev_io *io (SV *fh, int events, SV *cb) |
319 | PROTOTYPE: $$& |
|
|
320 | ALIAS: |
311 | ALIAS: |
321 | io_ns = 1 |
312 | io_ns = 1 |
322 | CODE: |
313 | CODE: |
323 | RETVAL = e_new (sizeof (struct ev_io), cb); |
314 | RETVAL = e_new (sizeof (struct ev_io), cb); |
324 | RETVAL->fh = newSVsv (fh); |
315 | RETVAL->fh = newSVsv (fh); |
… | |
… | |
326 | if (!ix) evio_start (RETVAL); |
317 | if (!ix) evio_start (RETVAL); |
327 | OUTPUT: |
318 | OUTPUT: |
328 | RETVAL |
319 | RETVAL |
329 | |
320 | |
330 | struct ev_timer *timer (NV after, NV repeat, SV *cb) |
321 | struct ev_timer *timer (NV after, NV repeat, SV *cb) |
331 | PROTOTYPE: $$& |
|
|
332 | ALIAS: |
322 | ALIAS: |
333 | timer_ns = 1 |
323 | timer_ns = 1 |
334 | INIT: |
324 | INIT: |
335 | CHECK_REPEAT (repeat); |
325 | CHECK_REPEAT (repeat); |
336 | CODE: |
326 | CODE: |
… | |
… | |
339 | if (!ix) evtimer_start (RETVAL); |
329 | if (!ix) evtimer_start (RETVAL); |
340 | OUTPUT: |
330 | OUTPUT: |
341 | RETVAL |
331 | RETVAL |
342 | |
332 | |
343 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
333 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
344 | PROTOTYPE: $$& |
|
|
345 | ALIAS: |
334 | ALIAS: |
346 | periodic_ns = 1 |
335 | periodic_ns = 1 |
347 | INIT: |
336 | INIT: |
348 | CHECK_REPEAT (interval); |
337 | CHECK_REPEAT (interval); |
349 | CODE: |
338 | CODE: |
… | |
… | |
352 | if (!ix) evperiodic_start (RETVAL); |
341 | if (!ix) evperiodic_start (RETVAL); |
353 | OUTPUT: |
342 | OUTPUT: |
354 | RETVAL |
343 | RETVAL |
355 | |
344 | |
356 | struct ev_signal *signal (Signal signum, SV *cb) |
345 | struct ev_signal *signal (Signal signum, SV *cb) |
357 | PROTOTYPE: $& |
|
|
358 | ALIAS: |
346 | ALIAS: |
359 | signal_ns = 1 |
347 | signal_ns = 1 |
360 | CODE: |
348 | CODE: |
361 | RETVAL = e_new (sizeof (struct ev_signal), cb); |
349 | RETVAL = e_new (sizeof (struct ev_signal), cb); |
362 | evsignal_set (RETVAL, signum); |
350 | evsignal_set (RETVAL, signum); |
363 | if (!ix) evsignal_start (RETVAL); |
351 | if (!ix) evsignal_start (RETVAL); |
364 | OUTPUT: |
352 | OUTPUT: |
365 | RETVAL |
353 | RETVAL |
366 | |
354 | |
367 | struct ev_idle *idle (SV *cb) |
355 | struct ev_idle *idle (SV *cb) |
368 | PROTOTYPE: & |
|
|
369 | ALIAS: |
356 | ALIAS: |
370 | idle_ns = 1 |
357 | idle_ns = 1 |
371 | CODE: |
358 | CODE: |
372 | RETVAL = e_new (sizeof (struct ev_idle), cb); |
359 | RETVAL = e_new (sizeof (struct ev_idle), cb); |
373 | evidle_set (RETVAL); |
360 | evidle_set (RETVAL); |
374 | if (!ix) evidle_start (RETVAL); |
361 | if (!ix) evidle_start (RETVAL); |
375 | OUTPUT: |
362 | OUTPUT: |
376 | RETVAL |
363 | RETVAL |
377 | |
364 | |
|
|
365 | struct ev_prepare *prepare (SV *cb) |
|
|
366 | ALIAS: |
|
|
367 | prepare_ns = 1 |
|
|
368 | CODE: |
|
|
369 | RETVAL = e_new (sizeof (struct ev_prepare), cb); |
|
|
370 | evprepare_set (RETVAL); |
|
|
371 | if (!ix) evprepare_start (RETVAL); |
|
|
372 | OUTPUT: |
|
|
373 | RETVAL |
|
|
374 | |
378 | struct ev_check *check (SV *cb) |
375 | struct ev_check *check (SV *cb) |
379 | PROTOTYPE: & |
|
|
380 | ALIAS: |
376 | ALIAS: |
381 | check_ns = 1 |
377 | check_ns = 1 |
382 | CODE: |
378 | CODE: |
383 | RETVAL = e_new (sizeof (struct ev_check), cb); |
379 | RETVAL = e_new (sizeof (struct ev_check), cb); |
384 | evcheck_set (RETVAL); |
380 | evcheck_set (RETVAL); |
385 | if (!ix) evcheck_start (RETVAL); |
381 | if (!ix) evcheck_start (RETVAL); |
|
|
382 | OUTPUT: |
|
|
383 | RETVAL |
|
|
384 | |
|
|
385 | struct ev_child *child (SV *cb, int pid) |
|
|
386 | ALIAS: |
|
|
387 | check_ns = 1 |
|
|
388 | CODE: |
|
|
389 | RETVAL = e_new (sizeof (struct ev_check), cb); |
|
|
390 | evchild (RETVAL, pid); |
|
|
391 | if (!ix) evchild_start (RETVAL); |
386 | OUTPUT: |
392 | OUTPUT: |
387 | RETVAL |
393 | RETVAL |
388 | |
394 | |
389 | |
395 | |
390 | PROTOTYPES: DISABLE |
396 | PROTOTYPES: DISABLE |
… | |
… | |
524 | |
530 | |
525 | void evidle_start (struct ev_idle *w) |
531 | void evidle_start (struct ev_idle *w) |
526 | |
532 | |
527 | void evidle_stop (struct ev_idle *w) |
533 | void evidle_stop (struct ev_idle *w) |
528 | |
534 | |
|
|
535 | MODULE = EV PACKAGE = EV::Prepare PREFIX = evcheck_ |
|
|
536 | |
|
|
537 | void evprepare_start (struct ev_prepare *w) |
|
|
538 | |
|
|
539 | void evprepare_stop (struct ev_prepare *w) |
|
|
540 | |
529 | MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ |
541 | MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ |
530 | |
542 | |
531 | void evcheck_start (struct ev_check *w) |
543 | void evcheck_start (struct ev_check *w) |
532 | |
544 | |
533 | void evcheck_stop (struct ev_check *w) |
545 | void evcheck_stop (struct ev_check *w) |
|
|
546 | |
|
|
547 | MODULE = EV PACKAGE = EV::Child PREFIX = evchild_ |
|
|
548 | |
|
|
549 | void evchild_start (struct ev_child *w) |
|
|
550 | |
|
|
551 | void evchild_stop (struct ev_child *w) |
|
|
552 | |
|
|
553 | void set (struct ev_child *w, int pid) |
|
|
554 | CODE: |
|
|
555 | { |
|
|
556 | int active = w->active; |
|
|
557 | if (active) evchild_stop (w); |
|
|
558 | evchild_set (w, pid); |
|
|
559 | if (active) evchild_start (w); |
|
|
560 | } |
534 | |
561 | |
535 | #if 0 |
562 | #if 0 |
536 | |
563 | |
537 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
564 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
538 | |
565 | |