ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
(Generate patch)

Comparing EV/EV.xs (file contents):
Revision 1.66 by root, Mon Nov 12 08:00:03 2007 UTC vs.
Revision 1.77 by root, Fri Nov 23 16:37:37 2007 UTC

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
147static SV *sv_events_cache;
148
147static void 149static void
148e_cb (struct ev_watcher *w, int revents) 150e_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 {
167 PUSHs (sv_self); 168 PUSHs (sv_self);
168 PUSHs (sv_events); 169 PUSHs (sv_events);
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 SP = PL_stack_base + mark; PUTBACK;
173 173
174 SvREFCNT_dec (sv_self); 174 SvREFCNT_dec (sv_self);
175 SvREFCNT_dec (sv_status);
176 175
177 if (sv_events_cache) 176 if (sv_events_cache)
178 SvREFCNT_dec (sv_events); 177 SvREFCNT_dec (sv_events);
179 else 178 else
180 sv_events_cache = sv_events; 179 sv_events_cache = sv_events;
182 if (SvTRUE (ERRSV)) 181 if (SvTRUE (ERRSV))
183 { 182 {
184 PUSHMARK (SP); 183 PUSHMARK (SP);
185 PUTBACK; 184 PUTBACK;
186 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 185 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
187 SP = PL_stack_base + mark; PUTBACK;
188 } 186 }
187
188 SP = PL_stack_base + mark;
189 PUTBACK;
190}
191
192static void
193e_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);
214
215 if (sv_events_cache)
216 SvREFCNT_dec (sv_events);
217 else
218 sv_events_cache = sv_events;
219
220 if (SvTRUE (ERRSV))
221 {
222 PUSHMARK (SP);
223 PUTBACK;
224 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
225 }
226
227 SP = PL_stack_base + mark;
228 PUTBACK;
189} 229}
190 230
191static ev_tstamp 231static ev_tstamp
192e_periodic_cb (struct ev_periodic *w, ev_tstamp now) 232e_periodic_cb (struct ev_periodic *w, ev_tstamp now)
193{ 233{
320 const_iv (EV_, CHECK) 360 const_iv (EV_, CHECK)
321 const_iv (EV_, ERROR) 361 const_iv (EV_, ERROR)
322 362
323 const_iv (EV, LOOP_ONESHOT) 363 const_iv (EV, LOOP_ONESHOT)
324 const_iv (EV, LOOP_NONBLOCK) 364 const_iv (EV, LOOP_NONBLOCK)
365 const_iv (EV, UNLOOP_ONE)
366 const_iv (EV, UNLOOP_ALL)
325 367
326 const_iv (EV, METHOD_SELECT) 368 const_iv (EV, BACKEND_SELECT)
327 const_iv (EV, METHOD_POLL) 369 const_iv (EV, BACKEND_POLL)
328 const_iv (EV, METHOD_EPOLL) 370 const_iv (EV, BACKEND_EPOLL)
329 const_iv (EV, METHOD_KQUEUE) 371 const_iv (EV, BACKEND_KQUEUE)
330 const_iv (EV, METHOD_DEVPOLL) 372 const_iv (EV, BACKEND_DEVPOLL)
331 const_iv (EV, METHOD_PORT) 373 const_iv (EV, BACKEND_PORT)
332 const_iv (EV, FLAG_AUTO) 374 const_iv (EV, FLAG_AUTO)
333 const_iv (EV, FLAG_NOENV) 375 const_iv (EV, FLAG_NOENV)
334 }; 376 };
335 377
336 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 378 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
354 evapi.ver = EV_API_VERSION; 396 evapi.ver = EV_API_VERSION;
355 evapi.rev = EV_API_REVISION; 397 evapi.rev = EV_API_REVISION;
356 evapi.sv_fileno = sv_fileno; 398 evapi.sv_fileno = sv_fileno;
357 evapi.sv_signum = sv_signum; 399 evapi.sv_signum = sv_signum;
358 evapi.now = ev_now; 400 evapi.now = ev_now;
359 evapi.method = ev_method; 401 evapi.backend = ev_backend;
360 evapi.unloop = ev_unloop; 402 evapi.unloop = ev_unloop;
361 evapi.time = ev_time; 403 evapi.time = ev_time;
362 evapi.loop = ev_loop; 404 evapi.loop = ev_loop;
363 evapi.once = ev_once; 405 evapi.once = ev_once;
364 evapi.io_start = ev_io_start; 406 evapi.io_start = ev_io_start;
376 evapi.prepare_stop = ev_prepare_stop; 418 evapi.prepare_stop = ev_prepare_stop;
377 evapi.check_start = ev_check_start; 419 evapi.check_start = ev_check_start;
378 evapi.check_stop = ev_check_stop; 420 evapi.check_stop = ev_check_stop;
379 evapi.child_start = ev_child_start; 421 evapi.child_start = ev_child_start;
380 evapi.child_stop = ev_child_stop; 422 evapi.child_stop = ev_child_stop;
423 evapi.ref = ev_ref;
424 evapi.unref = ev_unref;
381 425
382 sv_setiv (sv, (IV)&evapi); 426 sv_setiv (sv, (IV)&evapi);
383 SvREADONLY_on (sv); 427 SvREADONLY_on (sv);
384 } 428 }
385#ifndef _WIN32 429#ifndef _WIN32
387#endif 431#endif
388} 432}
389 433
390NV ev_now () 434NV ev_now ()
391 435
392int ev_method () 436unsigned int ev_backend ()
393 437
394NV ev_time () 438NV ev_time ()
395 439
396int ev_default_loop (int methods = EVFLAG_AUTO) 440unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
397 441
398void ev_loop (int flags = 0) 442void ev_loop (int flags = 0)
399 443
400void ev_unloop (int how = 1) 444void ev_unloop (int how = 1)
401 445
484 OUTPUT: 528 OUTPUT:
485 RETVAL 529 RETVAL
486 530
487struct ev_child *child (int pid, SV *cb) 531struct ev_child *child (int pid, SV *cb)
488 ALIAS: 532 ALIAS:
489 check_ns = 1 533 child_ns = 1
490 CODE: 534 CODE:
491 RETVAL = e_new (sizeof (struct ev_child), cb); 535 RETVAL = e_new (sizeof (struct ev_child), cb);
492 ev_child_set (RETVAL, pid); 536 ev_child_set (RETVAL, pid);
493 if (!ix) ev_child_start (RETVAL); 537 if (!ix) ev_child_start (RETVAL);
494 OUTPUT: 538 OUTPUT:
495 RETVAL 539 RETVAL
496 540
541void once (SV *fh, int events, SV *timeout, SV *cb)
542 CODE:
543 ev_once (
544 sv_fileno (fh), events,
545 SvOK (timeout) ? SvNV (timeout) : -1.,
546 e_once_cb,
547 newSVsv (cb)
548 );
497 549
498PROTOTYPES: DISABLE 550PROTOTYPES: DISABLE
499 551
500MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 552MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
501 553

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines