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

Comparing EV/EV.xs (file contents):
Revision 1.58 by root, Wed Nov 7 13:27:56 2007 UTC vs.
Revision 1.60 by root, Thu Nov 8 02:19:36 2007 UTC

116{ 116{
117 struct ev_watcher *w = (struct ev_watcher *)w_; 117 struct ev_watcher *w = (struct ev_watcher *)w_;
118 118
119 SvREFCNT_dec (w->fh ); w->fh = 0; 119 SvREFCNT_dec (w->fh ); w->fh = 0;
120 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 120 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
121 SvREFCNT_dec (w->data ); w->data = 0;
121} 122}
122 123
123static SV * 124static SV *
124e_bless (struct ev_watcher *w, HV *stash) 125e_bless (struct ev_watcher *w, HV *stash)
125{ 126{
177 PUSHMARK (SP); 178 PUSHMARK (SP);
178 PUTBACK; 179 PUTBACK;
179 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 180 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
180 SP = PL_stack_base + mark; PUTBACK; 181 SP = PL_stack_base + mark; PUTBACK;
181 } 182 }
183}
184
185static ev_tstamp
186e_periodic_cb (struct ev_periodic *w, ev_tstamp now)
187{
188 ev_tstamp retval;
189 int count;
190 dSP;
191
192 ENTER;
193 SAVETMPS;
194
195 PUSHMARK (SP);
196 EXTEND (SP, 2);
197 PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */
198 PUSHs (newSVnv (now));
199
200 PUTBACK;
201 count = call_sv (w->fh, G_SCALAR | G_EVAL);
202 SPAGAIN;
203
204 if (SvTRUE (ERRSV))
205 {
206 PUSHMARK (SP);
207 PUTBACK;
208 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
209 SPAGAIN;
210 }
211
212 if (count > 0)
213 {
214 retval = SvNV (TOPs);
215
216 if (retval < now)
217 retval = now;
218 }
219 else
220 retval = now;
221
222 FREETMPS;
223 LEAVE;
224
225 return retval;
182} 226}
183 227
184///////////////////////////////////////////////////////////////////////////// 228/////////////////////////////////////////////////////////////////////////////
185// DNS 229// DNS
186 230
375 ev_timer_set (RETVAL, after, repeat); 419 ev_timer_set (RETVAL, after, repeat);
376 if (!ix) ev_timer_start (RETVAL); 420 if (!ix) ev_timer_start (RETVAL);
377 OUTPUT: 421 OUTPUT:
378 RETVAL 422 RETVAL
379 423
380struct ev_periodic *periodic (NV at, NV interval, SV *cb) 424SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
381 ALIAS: 425 ALIAS:
382 periodic_ns = 1 426 periodic_ns = 1
383 INIT: 427 INIT:
384 CHECK_REPEAT (interval); 428 CHECK_REPEAT (interval);
385 CODE: 429 CODE:
430{
431 struct ev_periodic *w;
386 RETVAL = e_new (sizeof (struct ev_periodic), cb); 432 w = e_new (sizeof (struct ev_periodic), cb);
387 ev_periodic_set (RETVAL, at, interval); 433 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
434 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
435 RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic);
388 if (!ix) ev_periodic_start (RETVAL); 436 if (!ix) ev_periodic_start (w);
437}
389 OUTPUT: 438 OUTPUT:
390 RETVAL 439 RETVAL
391 440
392struct ev_signal *signal (Signal signum, SV *cb) 441struct ev_signal *signal (Signal signum, SV *cb)
393 ALIAS: 442 ALIAS:
451{ 500{
452 RETVAL = newSVsv (w->cb_sv); 501 RETVAL = newSVsv (w->cb_sv);
453 502
454 if (items > 1) 503 if (items > 1)
455 sv_setsv (w->cb_sv, new_cb); 504 sv_setsv (w->cb_sv, new_cb);
505}
506 OUTPUT:
507 RETVAL
508
509SV *data (struct ev_watcher *w, SV *new_data = 0)
510 CODE:
511{
512 RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
456} 513}
457 OUTPUT: 514 OUTPUT:
458 RETVAL 515 RETVAL
459 516
460void trigger (struct ev_watcher *w, int revents = EV_NONE) 517void trigger (struct ev_watcher *w, int revents = EV_NONE)
634 INIT: 691 INIT:
635 CHECK_REPEAT (w->interval); 692 CHECK_REPEAT (w->interval);
636 693
637void ev_periodic_stop (struct ev_periodic *w) 694void ev_periodic_stop (struct ev_periodic *w)
638 695
696void ev_periodic_again (struct ev_periodic *w)
697
639void DESTROY (struct ev_periodic *w) 698void DESTROY (struct ev_periodic *w)
640 CODE: 699 CODE:
641 ev_periodic_stop (w); 700 ev_periodic_stop (w);
642 e_destroy (w); 701 e_destroy (w);
643 702
644void set (struct ev_periodic *w, NV at, NV interval = 0.) 703void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
645 INIT: 704 INIT:
646 CHECK_REPEAT (interval); 705 CHECK_REPEAT (interval);
647 CODE: 706 CODE:
648{ 707{
649 int active = ev_is_active (w); 708 int active = ev_is_active (w);
650 if (active) ev_periodic_stop (w); 709 if (active) ev_periodic_stop (w);
651 710
711 SvREFCNT_dec (w->fh);
712 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
652 ev_periodic_set (w, at, interval); 713 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
653 714
654 if (active) ev_periodic_start (w); 715 if (active) ev_periodic_start (w);
655} 716}
656 717
657MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 718MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines