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.61 by root, Thu Nov 8 17:24:00 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines