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

Comparing EV/EV.xs (file contents):
Revision 1.57 by root, Tue Nov 6 17:20:42 2007 UTC vs.
Revision 1.60 by root, Thu Nov 8 02:19:36 2007 UTC

9 9
10/* fix perl api breakage */ 10/* fix perl api breakage */
11#undef signal 11#undef signal
12#undef sigaction 12#undef sigaction
13 13
14#define EV_SELECT_USE_WIN32_HANDLES 0
15#define EV_SELECT_USE_FD_SET 0
14/* due to bugs in OS X we have to use libev/ explicitly here */ 16/* due to bugs in OS X we have to use libev/ explicitly here */
15#include "libev/ev.c" 17#include "libev/ev.c"
16#include "event.c" 18#include "event.c"
17 19
18#ifndef WIN32 20#ifndef WIN32
114{ 116{
115 struct ev_watcher *w = (struct ev_watcher *)w_; 117 struct ev_watcher *w = (struct ev_watcher *)w_;
116 118
117 SvREFCNT_dec (w->fh ); w->fh = 0; 119 SvREFCNT_dec (w->fh ); w->fh = 0;
118 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;
119} 122}
120 123
121static SV * 124static SV *
122e_bless (struct ev_watcher *w, HV *stash) 125e_bless (struct ev_watcher *w, HV *stash)
123{ 126{
175 PUSHMARK (SP); 178 PUSHMARK (SP);
176 PUTBACK; 179 PUTBACK;
177 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);
178 SP = PL_stack_base + mark; PUTBACK; 181 SP = PL_stack_base + mark; PUTBACK;
179 } 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;
180} 226}
181 227
182///////////////////////////////////////////////////////////////////////////// 228/////////////////////////////////////////////////////////////////////////////
183// DNS 229// DNS
184 230
373 ev_timer_set (RETVAL, after, repeat); 419 ev_timer_set (RETVAL, after, repeat);
374 if (!ix) ev_timer_start (RETVAL); 420 if (!ix) ev_timer_start (RETVAL);
375 OUTPUT: 421 OUTPUT:
376 RETVAL 422 RETVAL
377 423
378struct ev_periodic *periodic (NV at, NV interval, SV *cb) 424SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
379 ALIAS: 425 ALIAS:
380 periodic_ns = 1 426 periodic_ns = 1
381 INIT: 427 INIT:
382 CHECK_REPEAT (interval); 428 CHECK_REPEAT (interval);
383 CODE: 429 CODE:
430{
431 struct ev_periodic *w;
384 RETVAL = e_new (sizeof (struct ev_periodic), cb); 432 w = e_new (sizeof (struct ev_periodic), cb);
385 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);
386 if (!ix) ev_periodic_start (RETVAL); 436 if (!ix) ev_periodic_start (w);
437}
387 OUTPUT: 438 OUTPUT:
388 RETVAL 439 RETVAL
389 440
390struct ev_signal *signal (Signal signum, SV *cb) 441struct ev_signal *signal (Signal signum, SV *cb)
391 ALIAS: 442 ALIAS:
449{ 500{
450 RETVAL = newSVsv (w->cb_sv); 501 RETVAL = newSVsv (w->cb_sv);
451 502
452 if (items > 1) 503 if (items > 1)
453 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;
454} 513}
455 OUTPUT: 514 OUTPUT:
456 RETVAL 515 RETVAL
457 516
458void trigger (struct ev_watcher *w, int revents = EV_NONE) 517void trigger (struct ev_watcher *w, int revents = EV_NONE)
632 INIT: 691 INIT:
633 CHECK_REPEAT (w->interval); 692 CHECK_REPEAT (w->interval);
634 693
635void ev_periodic_stop (struct ev_periodic *w) 694void ev_periodic_stop (struct ev_periodic *w)
636 695
696void ev_periodic_again (struct ev_periodic *w)
697
637void DESTROY (struct ev_periodic *w) 698void DESTROY (struct ev_periodic *w)
638 CODE: 699 CODE:
639 ev_periodic_stop (w); 700 ev_periodic_stop (w);
640 e_destroy (w); 701 e_destroy (w);
641 702
642void 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)
643 INIT: 704 INIT:
644 CHECK_REPEAT (interval); 705 CHECK_REPEAT (interval);
645 CODE: 706 CODE:
646{ 707{
647 int active = ev_is_active (w); 708 int active = ev_is_active (w);
648 if (active) ev_periodic_stop (w); 709 if (active) ev_periodic_stop (w);
649 710
711 SvREFCNT_dec (w->fh);
712 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
650 ev_periodic_set (w, at, interval); 713 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
651 714
652 if (active) ev_periodic_start (w); 715 if (active) ev_periodic_start (w);
653} 716}
654 717
655MODULE = 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