… | |
… | |
89 | fh = SvRV (fh); |
89 | fh = SvRV (fh); |
90 | |
90 | |
91 | if (SvTYPE (fh) == SVt_PVGV) |
91 | if (SvTYPE (fh) == SVt_PVGV) |
92 | return PerlIO_fileno (IoIFP (sv_2io (fh))); |
92 | return PerlIO_fileno (IoIFP (sv_2io (fh))); |
93 | |
93 | |
94 | if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff)) |
94 | if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL)) |
95 | return SvIV (fh); |
95 | return SvIV (fh); |
96 | |
96 | |
97 | return -1; |
97 | return -1; |
98 | } |
98 | } |
99 | |
99 | |
… | |
… | |
142 | } |
142 | } |
143 | |
143 | |
144 | return rv; |
144 | return rv; |
145 | } |
145 | } |
146 | |
146 | |
|
|
147 | static SV *sv_events_cache; |
|
|
148 | |
147 | static void |
149 | static void |
148 | e_cb (struct ev_watcher *w, int revents) |
150 | e_cb (struct ev_watcher *w, int revents) |
149 | { |
151 | { |
150 | dSP; |
152 | dSP; |
151 | I32 mark = SP - PL_stack_base; |
153 | I32 mark = SP - PL_stack_base; |
152 | SV *sv_self, *sv_events, *sv_status = 0; |
154 | SV *sv_self, *sv_events; |
153 | static SV *sv_events_cache; |
|
|
154 | |
155 | |
155 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
156 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
156 | |
157 | |
157 | if (sv_events_cache) |
158 | if (sv_events_cache) |
158 | { |
159 | { |
… | |
… | |
169 | |
170 | |
170 | PUTBACK; |
171 | PUTBACK; |
171 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
172 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
172 | |
173 | |
173 | SvREFCNT_dec (sv_self); |
174 | SvREFCNT_dec (sv_self); |
|
|
175 | |
|
|
176 | if (sv_events_cache) |
174 | SvREFCNT_dec (sv_status); |
177 | SvREFCNT_dec (sv_events); |
|
|
178 | else |
|
|
179 | sv_events_cache = sv_events; |
|
|
180 | |
|
|
181 | if (SvTRUE (ERRSV)) |
|
|
182 | { |
|
|
183 | PUSHMARK (SP); |
|
|
184 | PUTBACK; |
|
|
185 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
186 | } |
|
|
187 | |
|
|
188 | SP = PL_stack_base + mark; |
|
|
189 | PUTBACK; |
|
|
190 | } |
|
|
191 | |
|
|
192 | static void |
|
|
193 | e_once_cb (int revents, void *arg) |
|
|
194 | { |
|
|
195 | dSP; |
|
|
196 | I32 mark = SP - PL_stack_base; |
|
|
197 | SV *sv_events; |
|
|
198 | |
|
|
199 | if (sv_events_cache) |
|
|
200 | { |
|
|
201 | sv_events = sv_events_cache; sv_events_cache = 0; |
|
|
202 | SvIV_set (sv_events, revents); |
|
|
203 | } |
|
|
204 | else |
|
|
205 | sv_events = newSViv (revents); |
|
|
206 | |
|
|
207 | PUSHMARK (SP); |
|
|
208 | XPUSHs (sv_events); |
|
|
209 | |
|
|
210 | PUTBACK; |
|
|
211 | call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL); |
|
|
212 | |
|
|
213 | SvREFCNT_dec ((SV *)arg); |
175 | |
214 | |
176 | if (sv_events_cache) |
215 | if (sv_events_cache) |
177 | SvREFCNT_dec (sv_events); |
216 | SvREFCNT_dec (sv_events); |
178 | else |
217 | else |
179 | sv_events_cache = sv_events; |
218 | sv_events_cache = sv_events; |
… | |
… | |
495 | ev_child_set (RETVAL, pid); |
534 | ev_child_set (RETVAL, pid); |
496 | if (!ix) ev_child_start (RETVAL); |
535 | if (!ix) ev_child_start (RETVAL); |
497 | OUTPUT: |
536 | OUTPUT: |
498 | RETVAL |
537 | RETVAL |
499 | |
538 | |
|
|
539 | void once (SV *fh, int events, NV timeout, SV *cb) |
|
|
540 | CODE: |
|
|
541 | ev_once (sv_fileno (fh), events, timeout, e_once_cb, newSVsv (cb)); |
500 | |
542 | |
501 | PROTOTYPES: DISABLE |
543 | PROTOTYPES: DISABLE |
502 | |
544 | |
503 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
545 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
504 | |
546 | |