… | |
… | |
47 | #define e_fh(w) ((ev_watcher *)(w))->fh |
47 | #define e_fh(w) ((ev_watcher *)(w))->fh |
48 | #define e_data(w) ((ev_watcher *)(w))->data |
48 | #define e_data(w) ((ev_watcher *)(w))->data |
49 | |
49 | |
50 | #define WFLAG_KEEPALIVE 1 |
50 | #define WFLAG_KEEPALIVE 1 |
51 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
51 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
52 | #define WFLAG_NOARGS 4 /* do not pass anything to the callback */ |
|
|
53 | |
52 | |
54 | #define UNREF(w) \ |
53 | #define UNREF(w) \ |
55 | if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ |
54 | if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ |
56 | && ev_is_active (w)) \ |
55 | && ev_is_active (w)) \ |
57 | { \ |
56 | { \ |
… | |
… | |
200 | /* libev might have stopped the watcher */ |
199 | /* libev might have stopped the watcher */ |
201 | if (expect_false (w->e_flags & WFLAG_UNREFED) |
200 | if (expect_false (w->e_flags & WFLAG_UNREFED) |
202 | && !ev_is_active (w)) |
201 | && !ev_is_active (w)) |
203 | REF (w); |
202 | REF (w); |
204 | |
203 | |
205 | PUSHMARK (SP); |
204 | if (expect_true (sv_self_cache)) |
206 | |
|
|
207 | if (!expect_true (e_flags (w) & WFLAG_NOARGS)) |
|
|
208 | { |
205 | { |
209 | if (expect_true (sv_self_cache)) |
|
|
210 | { |
|
|
211 | sv_self = sv_self_cache; sv_self_cache = 0; |
206 | sv_self = sv_self_cache; sv_self_cache = 0; |
212 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
207 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
213 | } |
|
|
214 | else |
|
|
215 | { |
|
|
216 | sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ |
|
|
217 | SvREADONLY_on (sv_self); |
|
|
218 | } |
|
|
219 | |
|
|
220 | if (expect_true (sv_events_cache)) |
|
|
221 | { |
|
|
222 | sv_events = sv_events_cache; sv_events_cache = 0; |
|
|
223 | SvIV_set (sv_events, revents); |
|
|
224 | SvIOK_only (sv_events); |
|
|
225 | } |
|
|
226 | else |
|
|
227 | { |
|
|
228 | sv_events = newSViv (revents); |
|
|
229 | SvREADONLY_on (sv_events); |
|
|
230 | } |
|
|
231 | |
|
|
232 | EXTEND (SP, 2); |
|
|
233 | PUSHs (sv_self); |
|
|
234 | PUSHs (sv_events); |
|
|
235 | |
|
|
236 | PUTBACK; |
|
|
237 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
|
|
238 | |
|
|
239 | if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
|
|
240 | SvREFCNT_dec (sv_self); |
|
|
241 | else |
|
|
242 | { |
|
|
243 | SvREFCNT_dec (SvRV (sv_self)); |
|
|
244 | SvRV_set (sv_self, &PL_sv_undef); |
|
|
245 | sv_self_cache = sv_self; |
|
|
246 | } |
|
|
247 | |
|
|
248 | if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
|
|
249 | SvREFCNT_dec (sv_events); |
|
|
250 | else |
|
|
251 | sv_events_cache = sv_events; |
|
|
252 | } |
208 | } |
253 | else |
209 | else |
254 | { |
210 | { |
255 | PUTBACK; |
211 | sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ |
256 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
212 | SvREADONLY_on (sv_self); |
257 | } |
213 | } |
|
|
214 | |
|
|
215 | if (expect_true (sv_events_cache)) |
|
|
216 | { |
|
|
217 | sv_events = sv_events_cache; sv_events_cache = 0; |
|
|
218 | SvIV_set (sv_events, revents); |
|
|
219 | SvIOK_only (sv_events); |
|
|
220 | } |
|
|
221 | else |
|
|
222 | { |
|
|
223 | sv_events = newSViv (revents); |
|
|
224 | SvREADONLY_on (sv_events); |
|
|
225 | } |
|
|
226 | |
|
|
227 | PUSHMARK (SP); |
|
|
228 | EXTEND (SP, 2); |
|
|
229 | PUSHs (sv_self); |
|
|
230 | PUSHs (sv_events); |
|
|
231 | |
|
|
232 | PUTBACK; |
|
|
233 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
|
|
234 | |
|
|
235 | if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
|
|
236 | SvREFCNT_dec (sv_self); |
|
|
237 | else |
|
|
238 | { |
|
|
239 | SvREFCNT_dec (SvRV (sv_self)); |
|
|
240 | SvRV_set (sv_self, &PL_sv_undef); |
|
|
241 | sv_self_cache = sv_self; |
|
|
242 | } |
|
|
243 | |
|
|
244 | if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
|
|
245 | SvREFCNT_dec (sv_events); |
|
|
246 | else |
|
|
247 | sv_events_cache = sv_events; |
258 | |
248 | |
259 | if (expect_false (SvTRUE (ERRSV))) |
249 | if (expect_false (SvTRUE (ERRSV))) |
260 | { |
250 | { |
261 | SPAGAIN; |
251 | SPAGAIN; |
262 | PUSHMARK (SP); |
252 | PUSHMARK (SP); |
… | |
… | |
666 | _ae_io = 2 |
656 | _ae_io = 2 |
667 | CODE: |
657 | CODE: |
668 | { |
658 | { |
669 | int fd = s_fileno (fh, events & EV_WRITE); |
659 | int fd = s_fileno (fh, events & EV_WRITE); |
670 | CHECK_FD (fh, fd); |
660 | CHECK_FD (fh, fd); |
|
|
661 | |
|
|
662 | if (ix == 2) |
|
|
663 | { |
|
|
664 | ix = 0; |
|
|
665 | events = events ? EV_WRITE : EV_READ; |
|
|
666 | } |
|
|
667 | |
671 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
668 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
672 | e_fh (RETVAL) = newSVsv (fh); |
669 | e_fh (RETVAL) = newSVsv (fh); |
673 | |
|
|
674 | if (ix == 2) |
|
|
675 | { |
|
|
676 | events = events ? EV_WRITE : EV_READ; |
|
|
677 | e_flags (RETVAL) |= WFLAG_NOARGS; |
|
|
678 | } |
|
|
679 | |
|
|
680 | ev_io_set (RETVAL, fd, events); |
670 | ev_io_set (RETVAL, fd, events); |
681 | if (ix != 1) START (io, RETVAL); |
671 | if (!ix) START (io, RETVAL); |
682 | } |
672 | } |
683 | OUTPUT: |
673 | OUTPUT: |
684 | RETVAL |
674 | RETVAL |
685 | |
675 | |
686 | ev_timer *timer (NV after, NV repeat, SV *cb) |
676 | ev_timer *timer (NV after, NV repeat, SV *cb) |