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 <netinet/in.h>*/ |
|
|
6 | |
|
|
7 | /* fix perl api breakage */ |
5 | /* fix perl api breakage */ |
8 | #undef signal |
6 | #undef signal |
9 | #undef sigaction |
7 | #undef sigaction |
10 | |
8 | |
|
|
9 | #include "schmorp.h" |
|
|
10 | |
|
|
11 | /* old API compatibility */ |
|
|
12 | static int |
|
|
13 | sv_fileno (SV *fh) |
|
|
14 | { |
|
|
15 | return s_fileno (fh, 0); |
|
|
16 | } |
|
|
17 | |
|
|
18 | #define EV_STANDALONE 1 |
11 | #define EV_PROTOTYPES 1 |
19 | #define EV_PROTOTYPES 1 |
12 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
20 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
13 | #define EV_H <ev.h> |
21 | #define EV_H <ev.h> |
|
|
22 | #define EV_CONFIG_H error |
14 | #include "EV/EVAPI.h" |
23 | #include "EV/EVAPI.h" |
15 | |
24 | |
16 | #define EV_SELECT_IS_WINSOCKET 0 |
25 | #define EV_SELECT_IS_WINSOCKET 0 |
17 | #ifdef _WIN32 |
26 | #ifdef _WIN32 |
18 | # define EV_SELECT_USE_FD_SET 0 |
27 | # define EV_SELECT_USE_FD_SET 0 |
… | |
… | |
24 | |
33 | |
25 | #ifndef _WIN32 |
34 | #ifndef _WIN32 |
26 | # include <pthread.h> |
35 | # include <pthread.h> |
27 | #endif |
36 | #endif |
28 | |
37 | |
29 | /* 5.10.0 */ |
|
|
30 | #ifndef SvREFCNT_inc_NN |
|
|
31 | # define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) |
|
|
32 | #endif |
|
|
33 | |
|
|
34 | /* 5.6.x */ |
|
|
35 | #ifndef SvRV_set |
|
|
36 | # define SvRV_set(a,b) SvRV ((a)) = (b) |
|
|
37 | #endif |
|
|
38 | |
|
|
39 | #if __GNUC__ >= 3 |
|
|
40 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
41 | #else |
|
|
42 | # define expect(expr,value) (expr) |
|
|
43 | #endif |
|
|
44 | |
|
|
45 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
46 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
47 | |
|
|
48 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
38 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
49 | |
39 | |
50 | #define WFLAG_KEEPALIVE 1 |
40 | #define WFLAG_KEEPALIVE 1 |
51 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
41 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
52 | |
42 | |
… | |
… | |
76 | REF (w); \ |
66 | REF (w); \ |
77 | ev_ ## type ## _stop (e_loop (w), w); \ |
67 | ev_ ## type ## _stop (e_loop (w), w); \ |
78 | } while (0) |
68 | } while (0) |
79 | |
69 | |
80 | #define RESET(type,w,seta) \ |
70 | #define RESET(type,w,seta) \ |
81 | do { \ |
71 | do { \ |
82 | int active = ev_is_active (w); \ |
72 | int active = ev_is_active (w); \ |
83 | if (active) STOP (type, w); \ |
73 | if (active) STOP (type, w); \ |
84 | ev_ ## type ## _set seta; \ |
74 | ev_ ## type ## _set seta; \ |
85 | if (active) START (type, w); \ |
75 | if (active) START (type, w); \ |
86 | } while (0) |
76 | } while (0) |
87 | |
77 | |
88 | typedef int Signal; |
78 | typedef int Signal; |
|
|
79 | |
|
|
80 | /* horrible... */ |
|
|
81 | #define CHECK_SIGNAL_CAN_START(w) \ |
|
|
82 | do { \ |
|
|
83 | /* dive into the internals of libev to avoid aborting in libev */ \ |
|
|
84 | if (signals [(w)->signum - 1].loop \ |
|
|
85 | && signals [(w)->signum - 1].loop != e_loop (w)) \ |
|
|
86 | croak ("unable to start signal watcher, signal %d already registered in another loop", w->signum); \ |
|
|
87 | } while (0) |
|
|
88 | |
|
|
89 | #define START_SIGNAL(w) \ |
|
|
90 | do { \ |
|
|
91 | CHECK_SIGNAL_CAN_START (w); \ |
|
|
92 | START (signal, w); \ |
|
|
93 | } while (0) \ |
|
|
94 | |
|
|
95 | #define RESET_SIGNAL(w,seta) \ |
|
|
96 | do { \ |
|
|
97 | int active = ev_is_active (w); \ |
|
|
98 | if (active) STOP (signal, w); \ |
|
|
99 | ev_ ## signal ## _set seta; \ |
|
|
100 | if (active) START_SIGNAL (w); \ |
|
|
101 | } while (0) |
89 | |
102 | |
90 | static SV *default_loop_sv; |
103 | static SV *default_loop_sv; |
91 | |
104 | |
92 | static struct EVAPI evapi; |
105 | static struct EVAPI evapi; |
93 | |
106 | |
… | |
… | |
105 | *stash_check, |
118 | *stash_check, |
106 | *stash_embed, |
119 | *stash_embed, |
107 | *stash_fork, |
120 | *stash_fork, |
108 | *stash_async; |
121 | *stash_async; |
109 | |
122 | |
110 | #ifndef SIG_SIZE |
|
|
111 | /* kudos to Slaven Rezic for the idea */ |
|
|
112 | static char sig_size [] = { SIG_NUM }; |
|
|
113 | # define SIG_SIZE (sizeof (sig_size) + 1) |
|
|
114 | #endif |
|
|
115 | |
|
|
116 | static Signal |
|
|
117 | sv_signum (SV *sig) |
|
|
118 | { |
|
|
119 | Signal signum; |
|
|
120 | |
|
|
121 | SvGETMAGIC (sig); |
|
|
122 | |
|
|
123 | for (signum = 1; signum < SIG_SIZE; ++signum) |
|
|
124 | if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) |
|
|
125 | return signum; |
|
|
126 | |
|
|
127 | signum = SvIV (sig); |
|
|
128 | |
|
|
129 | if (signum > 0 && signum < SIG_SIZE) |
|
|
130 | return signum; |
|
|
131 | |
|
|
132 | return -1; |
|
|
133 | } |
|
|
134 | |
|
|
135 | ///////////////////////////////////////////////////////////////////////////// |
123 | ///////////////////////////////////////////////////////////////////////////// |
136 | // Event |
124 | // Event |
137 | |
125 | |
138 | static void e_cb (EV_P_ ev_watcher *w, int revents); |
126 | static void e_cb (EV_P_ ev_watcher *w, int revents); |
139 | |
127 | |
140 | static int |
|
|
141 | sv_fileno (SV *fh) |
|
|
142 | { |
|
|
143 | SvGETMAGIC (fh); |
|
|
144 | |
|
|
145 | if (SvROK (fh)) |
|
|
146 | fh = SvRV (fh); |
|
|
147 | |
|
|
148 | if (SvTYPE (fh) == SVt_PVGV) |
|
|
149 | return PerlIO_fileno (IoIFP (sv_2io (fh))); |
|
|
150 | |
|
|
151 | if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL)) |
|
|
152 | return SvIV (fh); |
|
|
153 | |
|
|
154 | return -1; |
|
|
155 | } |
|
|
156 | |
|
|
157 | static SV * |
|
|
158 | e_get_cv (SV *cb_sv) |
|
|
159 | { |
|
|
160 | HV *st; |
|
|
161 | GV *gvp; |
|
|
162 | CV *cv = sv_2cv (cb_sv, &st, &gvp, 0); |
|
|
163 | |
|
|
164 | if (!cv) |
|
|
165 | croak ("EV watcher callback must be a CODE reference"); |
|
|
166 | |
|
|
167 | return (SV *)cv; |
|
|
168 | } |
|
|
169 | |
|
|
170 | static void * |
128 | static void * |
171 | e_new (int size, SV *cb_sv, SV *loop) |
129 | e_new (int size, SV *cb_sv, SV *loop) |
172 | { |
130 | { |
173 | SV *cv = cb_sv ? e_get_cv (cb_sv) : 0; |
131 | SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0; |
174 | ev_watcher *w; |
132 | ev_watcher *w; |
175 | SV *self = NEWSV (0, size); |
133 | SV *self = NEWSV (0, size); |
176 | SvPOK_only (self); |
134 | SvPOK_only (self); |
177 | SvCUR_set (self, size); |
135 | SvCUR_set (self, size); |
178 | |
136 | |
… | |
… | |
399 | const_iv (EV_, MINPRI) |
357 | const_iv (EV_, MINPRI) |
400 | const_iv (EV_, MAXPRI) |
358 | const_iv (EV_, MAXPRI) |
401 | |
359 | |
402 | const_iv (EV_, UNDEF) |
360 | const_iv (EV_, UNDEF) |
403 | const_iv (EV_, NONE) |
361 | const_iv (EV_, NONE) |
404 | const_iv (EV_, TIMEOUT) |
|
|
405 | const_iv (EV_, READ) |
362 | const_iv (EV_, READ) |
406 | const_iv (EV_, WRITE) |
363 | const_iv (EV_, WRITE) |
|
|
364 | const_iv (EV_, IO) |
|
|
365 | const_iv (EV_, TIMEOUT) /* deprecated */ |
|
|
366 | const_iv (EV_, TIMER) |
|
|
367 | const_iv (EV_, PERIODIC) |
407 | const_iv (EV_, SIGNAL) |
368 | const_iv (EV_, SIGNAL) |
|
|
369 | const_iv (EV_, CHILD) |
|
|
370 | const_iv (EV_, STAT) |
408 | const_iv (EV_, IDLE) |
371 | const_iv (EV_, IDLE) |
|
|
372 | const_iv (EV_, PREPARE) |
409 | const_iv (EV_, CHECK) |
373 | const_iv (EV_, CHECK) |
|
|
374 | const_iv (EV_, EMBED) |
|
|
375 | const_iv (EV_, FORK) |
|
|
376 | const_iv (EV_, ASYNC) |
|
|
377 | const_iv (EV_, CUSTOM) |
410 | const_iv (EV_, ERROR) |
378 | const_iv (EV_, ERROR) |
411 | |
379 | |
|
|
380 | const_iv (EV, LOOP_NONBLOCK) |
412 | const_iv (EV, LOOP_ONESHOT) |
381 | const_iv (EV, LOOP_ONESHOT) |
|
|
382 | |
413 | const_iv (EV, LOOP_NONBLOCK) |
383 | const_iv (EV, UNLOOP_CANCEL) |
414 | const_iv (EV, UNLOOP_ONE) |
384 | const_iv (EV, UNLOOP_ONE) |
415 | const_iv (EV, UNLOOP_ALL) |
385 | const_iv (EV, UNLOOP_ALL) |
416 | |
386 | |
417 | const_iv (EV, BACKEND_SELECT) |
387 | const_iv (EV, BACKEND_SELECT) |
418 | const_iv (EV, BACKEND_POLL) |
388 | const_iv (EV, BACKEND_POLL) |
419 | const_iv (EV, BACKEND_EPOLL) |
389 | const_iv (EV, BACKEND_EPOLL) |
420 | const_iv (EV, BACKEND_KQUEUE) |
390 | const_iv (EV, BACKEND_KQUEUE) |
421 | const_iv (EV, BACKEND_DEVPOLL) |
391 | const_iv (EV, BACKEND_DEVPOLL) |
422 | const_iv (EV, BACKEND_PORT) |
392 | const_iv (EV, BACKEND_PORT) |
|
|
393 | const_iv (EV, BACKEND_ALL) |
423 | const_iv (EV, FLAG_AUTO) |
394 | const_iv (EV, FLAG_AUTO) |
|
|
395 | const_iv (EV, FLAG_FORKCHECK) |
|
|
396 | const_iv (EV, FLAG_SIGNALFD) |
424 | const_iv (EV, FLAG_NOENV) |
397 | const_iv (EV, FLAG_NOENV) |
|
|
398 | const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */ |
425 | const_iv (EV, FLAG_FORKCHECK) |
399 | const_iv (EV, FLAG_NOINOTIFY) |
|
|
400 | |
|
|
401 | const_iv (EV_, VERSION_MAJOR) |
|
|
402 | const_iv (EV_, VERSION_MINOR) |
426 | }; |
403 | }; |
427 | |
404 | |
428 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
405 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
429 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
406 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
430 | |
407 | |
… | |
… | |
449 | |
426 | |
450 | /* the poor man's shared library emulator */ |
427 | /* the poor man's shared library emulator */ |
451 | evapi.ver = EV_API_VERSION; |
428 | evapi.ver = EV_API_VERSION; |
452 | evapi.rev = EV_API_REVISION; |
429 | evapi.rev = EV_API_REVISION; |
453 | evapi.sv_fileno = sv_fileno; |
430 | evapi.sv_fileno = sv_fileno; |
454 | evapi.sv_signum = sv_signum; |
431 | evapi.sv_signum = s_signum; |
455 | evapi.supported_backends = ev_supported_backends (); |
432 | evapi.supported_backends = ev_supported_backends (); |
456 | evapi.recommended_backends = ev_recommended_backends (); |
433 | evapi.recommended_backends = ev_recommended_backends (); |
457 | evapi.embeddable_backends = ev_embeddable_backends (); |
434 | evapi.embeddable_backends = ev_embeddable_backends (); |
458 | evapi.time_ = ev_time; |
435 | evapi.time_ = ev_time; |
459 | evapi.sleep_ = ev_sleep; |
436 | evapi.sleep_ = ev_sleep; |
460 | evapi.loop_new = ev_loop_new; |
437 | evapi.loop_new = ev_loop_new; |
461 | evapi.loop_destroy = ev_loop_destroy; |
438 | evapi.loop_destroy = ev_loop_destroy; |
462 | evapi.loop_fork = ev_loop_fork; |
439 | evapi.loop_fork = ev_loop_fork; |
463 | evapi.loop_count = ev_loop_count; |
440 | evapi.iteration = ev_iteration; |
|
|
441 | evapi.depth = ev_depth; |
|
|
442 | evapi.set_userdata = ev_set_userdata; |
|
|
443 | evapi.userdata = ev_userdata; |
464 | evapi.now = ev_now; |
444 | evapi.now = ev_now; |
465 | evapi.now_update = ev_now_update; |
445 | evapi.now_update = ev_now_update; |
|
|
446 | evapi.suspend = ev_suspend; |
|
|
447 | evapi.resume = ev_resume; |
466 | evapi.backend = ev_backend; |
448 | evapi.backend = ev_backend; |
467 | evapi.unloop = ev_unloop; |
449 | evapi.unloop = ev_unloop; |
|
|
450 | evapi.invoke_pending = ev_invoke_pending; |
|
|
451 | evapi.pending_count = ev_pending_count; |
|
|
452 | evapi.verify = ev_verify; |
|
|
453 | evapi.set_loop_release_cb = ev_set_loop_release_cb; |
|
|
454 | evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; |
468 | evapi.ref = ev_ref; |
455 | evapi.ref = ev_ref; |
469 | evapi.unref = ev_unref; |
456 | evapi.unref = ev_unref; |
470 | evapi.loop = ev_loop; |
457 | evapi.loop = ev_loop; |
471 | evapi.once = ev_once; |
458 | evapi.once = ev_once; |
472 | evapi.io_start = ev_io_start; |
459 | evapi.io_start = ev_io_start; |
473 | evapi.io_stop = ev_io_stop; |
460 | evapi.io_stop = ev_io_stop; |
474 | evapi.timer_start = ev_timer_start; |
461 | evapi.timer_start = ev_timer_start; |
475 | evapi.timer_stop = ev_timer_stop; |
462 | evapi.timer_stop = ev_timer_stop; |
476 | evapi.timer_again = ev_timer_again; |
463 | evapi.timer_again = ev_timer_again; |
|
|
464 | evapi.timer_remaining = ev_timer_remaining; |
477 | evapi.periodic_start = ev_periodic_start; |
465 | evapi.periodic_start = ev_periodic_start; |
478 | evapi.periodic_stop = ev_periodic_stop; |
466 | evapi.periodic_stop = ev_periodic_stop; |
479 | evapi.signal_start = ev_signal_start; |
467 | evapi.signal_start = ev_signal_start; |
480 | evapi.signal_stop = ev_signal_stop; |
468 | evapi.signal_stop = ev_signal_stop; |
481 | evapi.idle_start = ev_idle_start; |
469 | evapi.idle_start = ev_idle_start; |
… | |
… | |
546 | C_ARGS: evapi.default_loop |
534 | C_ARGS: evapi.default_loop |
547 | |
535 | |
548 | void ev_now_update () |
536 | void ev_now_update () |
549 | C_ARGS: evapi.default_loop |
537 | C_ARGS: evapi.default_loop |
550 | |
538 | |
|
|
539 | void ev_suspend () |
|
|
540 | C_ARGS: evapi.default_loop |
|
|
541 | |
|
|
542 | void ev_resume () |
|
|
543 | C_ARGS: evapi.default_loop |
|
|
544 | |
551 | unsigned int ev_backend () |
545 | unsigned int ev_backend () |
552 | C_ARGS: evapi.default_loop |
546 | C_ARGS: evapi.default_loop |
553 | |
547 | |
|
|
548 | void ev_verify () |
|
|
549 | C_ARGS: evapi.default_loop |
|
|
550 | |
|
|
551 | unsigned int ev_iteration () |
|
|
552 | C_ARGS: evapi.default_loop |
|
|
553 | |
554 | unsigned int ev_loop_count () |
554 | unsigned int ev_depth () |
555 | C_ARGS: evapi.default_loop |
555 | C_ARGS: evapi.default_loop |
556 | |
556 | |
557 | void ev_set_io_collect_interval (NV interval) |
557 | void ev_set_io_collect_interval (NV interval) |
558 | C_ARGS: evapi.default_loop, interval |
558 | C_ARGS: evapi.default_loop, interval |
559 | |
559 | |
… | |
… | |
570 | C_ARGS: evapi.default_loop, fd, revents |
570 | C_ARGS: evapi.default_loop, fd, revents |
571 | |
571 | |
572 | void ev_feed_signal_event (SV *signal) |
572 | void ev_feed_signal_event (SV *signal) |
573 | CODE: |
573 | CODE: |
574 | { |
574 | { |
575 | Signal signum = sv_signum (signal); |
575 | Signal signum = s_signum (signal); |
576 | CHECK_SIG (signal, signum); |
576 | CHECK_SIG (signal, signum); |
577 | |
577 | |
578 | ev_feed_signal_event (evapi.default_loop, signum); |
578 | ev_feed_signal_event (evapi.default_loop, signum); |
579 | } |
579 | } |
580 | |
580 | |
|
|
581 | unsigned int ev_pending_count () |
|
|
582 | C_ARGS: evapi.default_loop |
|
|
583 | |
|
|
584 | void ev_invoke_pending () |
|
|
585 | C_ARGS: evapi.default_loop |
|
|
586 | |
581 | ev_io *io (SV *fh, int events, SV *cb) |
587 | ev_io *io (SV *fh, int events, SV *cb) |
582 | ALIAS: |
588 | ALIAS: |
583 | io_ns = 1 |
589 | io_ns = 1 |
|
|
590 | _ae_io = 2 |
584 | CODE: |
591 | CODE: |
585 | { |
592 | { |
586 | int fd = sv_fileno (fh); |
593 | int fd = s_fileno (fh, events & EV_WRITE); |
587 | CHECK_FD (fh, fd); |
594 | CHECK_FD (fh, fd); |
|
|
595 | |
|
|
596 | if (ix == 2) |
|
|
597 | { |
|
|
598 | ix = 0; |
|
|
599 | events = events ? EV_WRITE : EV_READ; |
|
|
600 | } |
588 | |
601 | |
589 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
602 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
590 | RETVAL->fh = newSVsv (fh); |
603 | RETVAL->fh = newSVsv (fh); |
591 | ev_io_set (RETVAL, fd, events); |
604 | ev_io_set (RETVAL, fd, events); |
592 | if (!ix) START (io, RETVAL); |
605 | if (!ix) START (io, RETVAL); |
… | |
… | |
626 | ev_signal *signal (SV *signal, SV *cb) |
639 | ev_signal *signal (SV *signal, SV *cb) |
627 | ALIAS: |
640 | ALIAS: |
628 | signal_ns = 1 |
641 | signal_ns = 1 |
629 | CODE: |
642 | CODE: |
630 | { |
643 | { |
631 | Signal signum = sv_signum (signal); |
644 | Signal signum = s_signum (signal); |
632 | CHECK_SIG (signal, signum); |
645 | CHECK_SIG (signal, signum); |
633 | |
646 | |
634 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
647 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
635 | ev_signal_set (RETVAL, signum); |
648 | ev_signal_set (RETVAL, signum); |
636 | if (!ix) START (signal, RETVAL); |
649 | if (!ix) START_SIGNAL (RETVAL); |
637 | } |
650 | } |
638 | OUTPUT: |
651 | OUTPUT: |
639 | RETVAL |
652 | RETVAL |
640 | |
653 | |
641 | ev_idle *idle (SV *cb) |
654 | ev_idle *idle (SV *cb) |
… | |
… | |
727 | |
740 | |
728 | void once (SV *fh, int events, SV *timeout, SV *cb) |
741 | void once (SV *fh, int events, SV *timeout, SV *cb) |
729 | CODE: |
742 | CODE: |
730 | ev_once ( |
743 | ev_once ( |
731 | evapi.default_loop, |
744 | evapi.default_loop, |
732 | sv_fileno (fh), events, |
745 | s_fileno (fh, events & EV_WRITE), events, |
733 | SvOK (timeout) ? SvNV (timeout) : -1., |
746 | SvOK (timeout) ? SvNV (timeout) : -1., |
734 | e_once_cb, |
747 | e_once_cb, |
735 | newSVsv (cb) |
748 | newSVsv (cb) |
736 | ); |
749 | ); |
737 | |
750 | |
… | |
… | |
771 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
784 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
772 | CODE: |
785 | CODE: |
773 | { |
786 | { |
774 | if (items > 1) |
787 | if (items > 1) |
775 | { |
788 | { |
776 | new_cb = e_get_cv (new_cb); |
789 | new_cb = s_get_cv_croak (new_cb); |
777 | RETVAL = newRV_noinc (w->cb_sv); |
790 | RETVAL = newRV_noinc (w->cb_sv); |
778 | w->cb_sv = SvREFCNT_inc (new_cb); |
791 | w->cb_sv = SvREFCNT_inc (new_cb); |
779 | } |
792 | } |
780 | else |
793 | else |
781 | RETVAL = newRV_inc (w->cb_sv); |
794 | RETVAL = newRV_inc (w->cb_sv); |
… | |
… | |
851 | e_destroy (w); |
864 | e_destroy (w); |
852 | |
865 | |
853 | void set (ev_io *w, SV *fh, int events) |
866 | void set (ev_io *w, SV *fh, int events) |
854 | CODE: |
867 | CODE: |
855 | { |
868 | { |
856 | int fd = sv_fileno (fh); |
869 | int fd = s_fileno (fh, events & EV_WRITE); |
857 | CHECK_FD (fh, fd); |
870 | CHECK_FD (fh, fd); |
858 | |
871 | |
859 | sv_setsv (w->fh, fh); |
872 | sv_setsv (w->fh, fh); |
860 | RESET (io, w, (w, fd, events)); |
873 | RESET (io, w, (w, fd, events)); |
861 | } |
874 | } |
… | |
… | |
863 | SV *fh (ev_io *w, SV *new_fh = 0) |
876 | SV *fh (ev_io *w, SV *new_fh = 0) |
864 | CODE: |
877 | CODE: |
865 | { |
878 | { |
866 | if (items > 1) |
879 | if (items > 1) |
867 | { |
880 | { |
868 | int fd = sv_fileno (new_fh); |
881 | int fd = s_fileno (new_fh, w->events & EV_WRITE); |
869 | CHECK_FD (new_fh, fd); |
882 | CHECK_FD (new_fh, fd); |
870 | |
883 | |
871 | RETVAL = w->fh; |
884 | RETVAL = w->fh; |
872 | w->fh = newSVsv (new_fh); |
885 | w->fh = newSVsv (new_fh); |
873 | |
886 | |
… | |
… | |
892 | |
905 | |
893 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
906 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
894 | |
907 | |
895 | void ev_signal_start (ev_signal *w) |
908 | void ev_signal_start (ev_signal *w) |
896 | CODE: |
909 | CODE: |
897 | START (signal, w); |
910 | START_SIGNAL (w); |
898 | |
911 | |
899 | void ev_signal_stop (ev_signal *w) |
912 | void ev_signal_stop (ev_signal *w) |
900 | CODE: |
913 | CODE: |
901 | STOP (signal, w); |
914 | STOP (signal, w); |
902 | |
915 | |
… | |
… | |
906 | e_destroy (w); |
919 | e_destroy (w); |
907 | |
920 | |
908 | void set (ev_signal *w, SV *signal) |
921 | void set (ev_signal *w, SV *signal) |
909 | CODE: |
922 | CODE: |
910 | { |
923 | { |
911 | Signal signum = sv_signum (signal); |
924 | Signal signum = s_signum (signal); |
912 | CHECK_SIG (signal, signum); |
925 | CHECK_SIG (signal, signum); |
913 | |
926 | |
914 | RESET (signal, w, (w, signum)); |
927 | RESET_SIGNAL (w, (w, signum)); |
915 | } |
928 | } |
916 | |
929 | |
917 | int signal (ev_signal *w, SV *new_signal = 0) |
930 | int signal (ev_signal *w, SV *new_signal = 0) |
918 | CODE: |
931 | CODE: |
919 | { |
932 | { |
920 | RETVAL = w->signum; |
933 | RETVAL = w->signum; |
921 | |
934 | |
922 | if (items > 1) |
935 | if (items > 1) |
923 | { |
936 | { |
924 | Signal signum = sv_signum (new_signal); |
937 | Signal signum = s_signum (new_signal); |
925 | CHECK_SIG (new_signal, signum); |
938 | CHECK_SIG (new_signal, signum); |
926 | |
939 | |
927 | RESET (signal, w, (w, signum)); |
940 | RESET_SIGNAL (w, (w, signum)); |
928 | } |
941 | } |
929 | } |
942 | } |
930 | OUTPUT: |
943 | OUTPUT: |
931 | RETVAL |
944 | RETVAL |
932 | |
945 | |
… | |
… | |
946 | INIT: |
959 | INIT: |
947 | CHECK_REPEAT (w->repeat); |
960 | CHECK_REPEAT (w->repeat); |
948 | CODE: |
961 | CODE: |
949 | ev_timer_again (e_loop (w), w); |
962 | ev_timer_again (e_loop (w), w); |
950 | UNREF (w); |
963 | UNREF (w); |
|
|
964 | |
|
|
965 | NV ev_timer_remaining (ev_timer *w) |
|
|
966 | C_ARGS: e_loop (w), w |
951 | |
967 | |
952 | void DESTROY (ev_timer *w) |
968 | void DESTROY (ev_timer *w) |
953 | CODE: |
969 | CODE: |
954 | STOP (timer, w); |
970 | STOP (timer, w); |
955 | e_destroy (w); |
971 | e_destroy (w); |
… | |
… | |
1258 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1274 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1259 | ev_loop_destroy (loop); |
1275 | ev_loop_destroy (loop); |
1260 | |
1276 | |
1261 | void ev_loop_fork (struct ev_loop *loop) |
1277 | void ev_loop_fork (struct ev_loop *loop) |
1262 | |
1278 | |
1263 | void ev_loop_verify (struct ev_loop *loop) |
1279 | void ev_verify (struct ev_loop *loop) |
1264 | |
1280 | |
1265 | NV ev_now (struct ev_loop *loop) |
1281 | NV ev_now (struct ev_loop *loop) |
1266 | |
1282 | |
1267 | void ev_now_update (struct ev_loop *loop) |
1283 | void ev_now_update (struct ev_loop *loop) |
1268 | |
1284 | |
|
|
1285 | void ev_suspend (struct ev_loop *loop) |
|
|
1286 | |
|
|
1287 | void ev_resume (struct ev_loop *loop) |
|
|
1288 | |
1269 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1289 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1270 | |
1290 | |
1271 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1291 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1272 | |
1292 | |
1273 | unsigned int ev_backend (struct ev_loop *loop) |
1293 | unsigned int ev_backend (struct ev_loop *loop) |
1274 | |
1294 | |
1275 | unsigned int ev_loop_count (struct ev_loop *loop) |
1295 | unsigned int ev_iteration (struct ev_loop *loop) |
|
|
1296 | |
|
|
1297 | unsigned int ev_depth (struct ev_loop *loop) |
1276 | |
1298 | |
1277 | void ev_loop (struct ev_loop *loop, int flags = 0) |
1299 | void ev_loop (struct ev_loop *loop, int flags = 0) |
1278 | |
1300 | |
1279 | void ev_unloop (struct ev_loop *loop, int how = 1) |
1301 | void ev_unloop (struct ev_loop *loop, int how = 1) |
1280 | |
1302 | |
1281 | void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) |
1303 | void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) |
1282 | |
1304 | |
|
|
1305 | unsigned int ev_pending_count (struct ev_loop *loop) |
|
|
1306 | |
|
|
1307 | void ev_invoke_pending (struct ev_loop *loop) |
|
|
1308 | |
1283 | #if 0 |
1309 | #if 0 |
1284 | |
1310 | |
1285 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1311 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1286 | CODE: |
1312 | CODE: |
1287 | { |
1313 | { |
1288 | Signal signum = sv_signum (signal); |
1314 | Signal signum = s_signum (signal); |
1289 | CHECK_SIG (signal, signum); |
1315 | CHECK_SIG (signal, signum); |
1290 | |
1316 | |
1291 | ev_feed_signal_event (loop, signum); |
1317 | ev_feed_signal_event (loop, signum); |
1292 | } |
1318 | } |
1293 | |
1319 | |
… | |
… | |
1296 | ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) |
1322 | ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) |
1297 | ALIAS: |
1323 | ALIAS: |
1298 | io_ns = 1 |
1324 | io_ns = 1 |
1299 | CODE: |
1325 | CODE: |
1300 | { |
1326 | { |
1301 | int fd = sv_fileno (fh); |
1327 | int fd = s_fileno (fh, events & EV_WRITE); |
1302 | CHECK_FD (fh, fd); |
1328 | CHECK_FD (fh, fd); |
1303 | |
1329 | |
1304 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
1330 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
1305 | RETVAL->fh = newSVsv (fh); |
1331 | RETVAL->fh = newSVsv (fh); |
1306 | ev_io_set (RETVAL, fd, events); |
1332 | ev_io_set (RETVAL, fd, events); |
… | |
… | |
1336 | if (!ix) START (periodic, w); |
1362 | if (!ix) START (periodic, w); |
1337 | } |
1363 | } |
1338 | OUTPUT: |
1364 | OUTPUT: |
1339 | RETVAL |
1365 | RETVAL |
1340 | |
1366 | |
1341 | #if 0 |
|
|
1342 | |
|
|
1343 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1367 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1344 | ALIAS: |
1368 | ALIAS: |
1345 | signal_ns = 1 |
1369 | signal_ns = 1 |
1346 | CODE: |
1370 | CODE: |
1347 | { |
1371 | { |
1348 | Signal signum = sv_signum (signal); |
1372 | Signal signum = s_signum (signal); |
1349 | CHECK_SIG (signal, signum); |
1373 | CHECK_SIG (signal, signum); |
1350 | |
1374 | |
1351 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1375 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1352 | ev_signal_set (RETVAL, signum); |
1376 | ev_signal_set (RETVAL, signum); |
1353 | if (!ix) START (signal, RETVAL); |
1377 | if (!ix) START_SIGNAL (RETVAL); |
1354 | } |
1378 | } |
1355 | OUTPUT: |
1379 | OUTPUT: |
1356 | RETVAL |
1380 | RETVAL |
1357 | |
|
|
1358 | #endif |
|
|
1359 | |
1381 | |
1360 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
1382 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
1361 | ALIAS: |
1383 | ALIAS: |
1362 | idle_ns = 1 |
1384 | idle_ns = 1 |
1363 | CODE: |
1385 | CODE: |
… | |
… | |
1446 | |
1468 | |
1447 | void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) |
1469 | void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) |
1448 | CODE: |
1470 | CODE: |
1449 | ev_once ( |
1471 | ev_once ( |
1450 | loop, |
1472 | loop, |
1451 | sv_fileno (fh), events, |
1473 | s_fileno (fh, events & EV_WRITE), events, |
1452 | SvOK (timeout) ? SvNV (timeout) : -1., |
1474 | SvOK (timeout) ? SvNV (timeout) : -1., |
1453 | e_once_cb, |
1475 | e_once_cb, |
1454 | newSVsv (cb) |
1476 | newSVsv (cb) |
1455 | ); |
1477 | ); |
1456 | |
1478 | |