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 0 |
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" |
|
|
12 | |
|
|
13 | #include "libev/ev.c" |
15 | |
14 | |
16 | typedef int Signal; |
15 | typedef int Signal; |
17 | |
16 | |
18 | static struct EVAPI evapi; |
17 | static struct EVAPI evapi; |
19 | |
18 | |
… | |
… | |
38 | for (signum = 1; signum < SIG_SIZE; ++signum) |
37 | for (signum = 1; signum < SIG_SIZE; ++signum) |
39 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
38 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
40 | return signum; |
39 | return signum; |
41 | |
40 | |
42 | return -1; |
41 | 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 | } |
42 | } |
59 | |
43 | |
60 | ///////////////////////////////////////////////////////////////////////////// |
44 | ///////////////////////////////////////////////////////////////////////////// |
61 | // Event |
45 | // Event |
62 | |
46 | |
… | |
… | |
209 | |
193 | |
210 | LEAVE; |
194 | LEAVE; |
211 | } |
195 | } |
212 | #endif |
196 | #endif |
213 | |
197 | |
|
|
198 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
|
|
199 | croak (# repeat " value must be >= 0"); |
|
|
200 | |
214 | ///////////////////////////////////////////////////////////////////////////// |
201 | ///////////////////////////////////////////////////////////////////////////// |
215 | // XS interface functions |
202 | // XS interface functions |
216 | |
203 | |
217 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
204 | MODULE = EV PACKAGE = EV PREFIX = ev_ |
|
|
205 | |
|
|
206 | PROTOTYPES: ENABLE |
218 | |
207 | |
219 | BOOT: |
208 | BOOT: |
220 | { |
209 | { |
221 | int i; |
210 | int i; |
222 | HV *stash = gv_stashpv ("EV", 1); |
211 | HV *stash = gv_stashpv ("EV", 1); |
… | |
… | |
224 | static const struct { |
213 | static const struct { |
225 | const char *name; |
214 | const char *name; |
226 | IV iv; |
215 | IV iv; |
227 | } *civ, const_iv[] = { |
216 | } *civ, const_iv[] = { |
228 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
217 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
218 | const_iv (EV_, UNDEF) |
229 | const_iv (EV_, NONE) |
219 | const_iv (EV_, NONE) |
230 | const_iv (EV_, TIMEOUT) |
220 | const_iv (EV_, TIMEOUT) |
231 | const_iv (EV_, READ) |
221 | const_iv (EV_, READ) |
232 | const_iv (EV_, WRITE) |
222 | const_iv (EV_, WRITE) |
233 | const_iv (EV_, SIGNAL) |
223 | const_iv (EV_, SIGNAL) |
234 | const_iv (EV_, IDLE) |
224 | const_iv (EV_, IDLE) |
235 | const_iv (EV_, CHECK) |
225 | const_iv (EV_, CHECK) |
|
|
226 | const_iv (EV_, ERROR) |
236 | |
227 | |
237 | const_iv (EV, LOOP_ONESHOT) |
228 | const_iv (EV, LOOP_ONESHOT) |
238 | const_iv (EV, LOOP_NONBLOCK) |
229 | const_iv (EV, LOOP_NONBLOCK) |
239 | |
230 | |
240 | const_iv (EV, METHOD_NONE) |
231 | const_iv (EV, METHOD_NONE) |
… | |
… | |
259 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
250 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
260 | |
251 | |
261 | /* the poor man's shared library emulator */ |
252 | /* the poor man's shared library emulator */ |
262 | evapi.ver = EV_API_VERSION; |
253 | evapi.ver = EV_API_VERSION; |
263 | evapi.rev = EV_API_REVISION; |
254 | evapi.rev = EV_API_REVISION; |
264 | evapi.once = api_once; |
|
|
265 | evapi.sv_fileno = sv_fileno; |
255 | evapi.sv_fileno = sv_fileno; |
266 | evapi.sv_signum = sv_signum; |
256 | evapi.sv_signum = sv_signum; |
267 | evapi.now = &ev_now; |
257 | evapi.now = &ev_now; |
268 | evapi.method = &ev_method; |
258 | evapi.method = &ev_method; |
269 | evapi.loop_done = &ev_loop_done; |
259 | evapi.loop_done = &ev_loop_done; |
270 | evapi.time = ev_time; |
260 | evapi.time = ev_time; |
271 | evapi.loop = ev_loop; |
261 | evapi.loop = ev_loop; |
|
|
262 | evapi.once = ev_once; |
272 | evapi.io_start = evio_start; |
263 | evapi.io_start = evio_start; |
273 | evapi.io_stop = evio_stop; |
264 | evapi.io_stop = evio_stop; |
274 | evapi.timer_start = evtimer_start; |
265 | evapi.timer_start = evtimer_start; |
275 | evapi.timer_stop = evtimer_stop; |
266 | evapi.timer_stop = evtimer_stop; |
|
|
267 | evapi.timer_again = evtimer_again; |
276 | evapi.periodic_start = evperiodic_start; |
268 | evapi.periodic_start = evperiodic_start; |
277 | evapi.periodic_stop = evperiodic_stop; |
269 | evapi.periodic_stop = evperiodic_stop; |
278 | evapi.signal_start = evsignal_start; |
270 | evapi.signal_start = evsignal_start; |
279 | evapi.signal_stop = evsignal_stop; |
271 | evapi.signal_stop = evsignal_stop; |
280 | evapi.idle_start = evidle_start; |
272 | evapi.idle_start = evidle_start; |
… | |
… | |
321 | RETVAL |
313 | RETVAL |
322 | |
314 | |
323 | struct ev_timer *timer (NV after, NV repeat, SV *cb) |
315 | struct ev_timer *timer (NV after, NV repeat, SV *cb) |
324 | ALIAS: |
316 | ALIAS: |
325 | timer_ns = 1 |
317 | timer_ns = 1 |
|
|
318 | INIT: |
|
|
319 | CHECK_REPEAT (repeat); |
326 | CODE: |
320 | CODE: |
327 | RETVAL = e_new (sizeof (struct ev_timer), cb); |
321 | RETVAL = e_new (sizeof (struct ev_timer), cb); |
328 | evtimer_set (RETVAL, after, repeat); |
322 | evtimer_set (RETVAL, after, repeat); |
329 | if (!ix) evtimer_start (RETVAL); |
323 | if (!ix) evtimer_start (RETVAL); |
330 | OUTPUT: |
324 | OUTPUT: |
331 | RETVAL |
325 | RETVAL |
332 | |
326 | |
333 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
327 | struct ev_periodic *periodic (NV at, NV interval, SV *cb) |
334 | ALIAS: |
328 | ALIAS: |
335 | periodic_ns = 1 |
329 | periodic_ns = 1 |
|
|
330 | INIT: |
|
|
331 | CHECK_REPEAT (interval); |
336 | CODE: |
332 | CODE: |
337 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
333 | RETVAL = e_new (sizeof (struct ev_periodic), cb); |
338 | evperiodic_set (RETVAL, at, interval); |
334 | evperiodic_set (RETVAL, at, interval); |
339 | if (!ix) evperiodic_start (RETVAL); |
335 | if (!ix) evperiodic_start (RETVAL); |
340 | OUTPUT: |
336 | OUTPUT: |
… | |
… | |
463 | MODULE = EV PACKAGE = EV::Time |
459 | MODULE = EV PACKAGE = EV::Time |
464 | |
460 | |
465 | MODULE = EV PACKAGE = EV::Timer PREFIX = evtimer_ |
461 | MODULE = EV PACKAGE = EV::Timer PREFIX = evtimer_ |
466 | |
462 | |
467 | void evtimer_start (struct ev_timer *w) |
463 | void evtimer_start (struct ev_timer *w) |
|
|
464 | INIT: |
|
|
465 | CHECK_REPEAT (w->repeat); |
468 | |
466 | |
469 | void evtimer_stop (struct ev_timer *w) |
467 | void evtimer_stop (struct ev_timer *w) |
470 | |
468 | |
|
|
469 | void evtimer_again (struct ev_timer *w) |
|
|
470 | INIT: |
|
|
471 | CHECK_REPEAT (w->repeat); |
|
|
472 | |
471 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
473 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
|
|
474 | INIT: |
|
|
475 | CHECK_REPEAT (repeat); |
472 | CODE: |
476 | CODE: |
473 | { |
477 | { |
474 | int active = w->active; |
478 | int active = w->active; |
475 | if (active) evtimer_stop (w); |
479 | if (active) evtimer_stop (w); |
476 | evtimer_set (w, after, repeat); |
480 | evtimer_set (w, after, repeat); |
… | |
… | |
478 | } |
482 | } |
479 | |
483 | |
480 | MODULE = EV PACKAGE = EV::Periodic PREFIX = evperiodic_ |
484 | MODULE = EV PACKAGE = EV::Periodic PREFIX = evperiodic_ |
481 | |
485 | |
482 | void evperiodic_start (struct ev_periodic *w) |
486 | void evperiodic_start (struct ev_periodic *w) |
|
|
487 | INIT: |
|
|
488 | CHECK_REPEAT (w->interval); |
483 | |
489 | |
484 | void evperiodic_stop (struct ev_periodic *w) |
490 | void evperiodic_stop (struct ev_periodic *w) |
485 | |
491 | |
486 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
492 | void set (struct ev_periodic *w, NV at, NV interval = 0.) |
|
|
493 | INIT: |
|
|
494 | CHECK_REPEAT (interval); |
487 | CODE: |
495 | CODE: |
488 | { |
496 | { |
489 | int active = w->active; |
497 | int active = w->active; |
490 | if (active) evperiodic_stop (w); |
498 | if (active) evperiodic_stop (w); |
491 | evperiodic_set (w, at, interval); |
499 | evperiodic_set (w, at, interval); |