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.62 by root, Fri Nov 9 19:33:51 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines