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.62 by root, Fri Nov 9 19:33:51 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
21# define HAVE_STRUCT_IN6_ADDR 1 23# define HAVE_STRUCT_IN6_ADDR 1
22#endif 24#endif
23#undef HAVE_STRTOK_R 25#undef HAVE_STRTOK_R
24#undef strtok_r 26#undef strtok_r
25#define strtok_r fake_strtok_r 27#define strtok_r fake_strtok_r
28#include "evdns.h"
26#include "evdns.c" 29#include "evdns.c"
27#endif 30#endif
28 31
29#ifndef WIN32 32#ifndef WIN32
30# include <pthread.h> 33# include <pthread.h>
100 103
101 w = (struct ev_watcher *)SvPVX (self); 104 w = (struct ev_watcher *)SvPVX (self);
102 105
103 ev_watcher_init (w, e_cb); 106 ev_watcher_init (w, e_cb);
104 107
108 w->data = 0;
105 w->fh = 0; 109 w->fh = 0;
106 w->cb_sv = newSVsv (cb_sv); 110 w->cb_sv = newSVsv (cb_sv);
107 w->self = self; 111 w->self = self;
108 112
109 return (void *)w; 113 return (void *)w;
114{ 118{
115 struct ev_watcher *w = (struct ev_watcher *)w_; 119 struct ev_watcher *w = (struct ev_watcher *)w_;
116 120
117 SvREFCNT_dec (w->fh ); w->fh = 0; 121 SvREFCNT_dec (w->fh ); w->fh = 0;
118 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;
119} 124}
120 125
121static SV * 126static SV *
122e_bless (struct ev_watcher *w, HV *stash) 127e_bless (struct ev_watcher *w, HV *stash)
123{ 128{
175 PUSHMARK (SP); 180 PUSHMARK (SP);
176 PUTBACK; 181 PUTBACK;
177 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);
178 SP = PL_stack_base + mark; PUTBACK; 183 SP = PL_stack_base + mark; PUTBACK;
179 } 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;
180} 228}
181 229
182///////////////////////////////////////////////////////////////////////////// 230/////////////////////////////////////////////////////////////////////////////
183// DNS 231// DNS
184 232
373 ev_timer_set (RETVAL, after, repeat); 421 ev_timer_set (RETVAL, after, repeat);
374 if (!ix) ev_timer_start (RETVAL); 422 if (!ix) ev_timer_start (RETVAL);
375 OUTPUT: 423 OUTPUT:
376 RETVAL 424 RETVAL
377 425
378struct ev_periodic *periodic (NV at, NV interval, SV *cb) 426SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
379 ALIAS: 427 ALIAS:
380 periodic_ns = 1 428 periodic_ns = 1
381 INIT: 429 INIT:
382 CHECK_REPEAT (interval); 430 CHECK_REPEAT (interval);
383 CODE: 431 CODE:
432{
433 struct ev_periodic *w;
384 RETVAL = e_new (sizeof (struct ev_periodic), cb); 434 w = e_new (sizeof (struct ev_periodic), cb);
385 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);
386 if (!ix) ev_periodic_start (RETVAL); 438 if (!ix) ev_periodic_start (w);
439}
387 OUTPUT: 440 OUTPUT:
388 RETVAL 441 RETVAL
389 442
390struct ev_signal *signal (Signal signum, SV *cb) 443struct ev_signal *signal (Signal signum, SV *cb)
391 ALIAS: 444 ALIAS:
449{ 502{
450 RETVAL = newSVsv (w->cb_sv); 503 RETVAL = newSVsv (w->cb_sv);
451 504
452 if (items > 1) 505 if (items > 1)
453 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;
454} 515}
455 OUTPUT: 516 OUTPUT:
456 RETVAL 517 RETVAL
457 518
458void trigger (struct ev_watcher *w, int revents = EV_NONE) 519void trigger (struct ev_watcher *w, int revents = EV_NONE)
632 INIT: 693 INIT:
633 CHECK_REPEAT (w->interval); 694 CHECK_REPEAT (w->interval);
634 695
635void ev_periodic_stop (struct ev_periodic *w) 696void ev_periodic_stop (struct ev_periodic *w)
636 697
698void ev_periodic_again (struct ev_periodic *w)
699
637void DESTROY (struct ev_periodic *w) 700void DESTROY (struct ev_periodic *w)
638 CODE: 701 CODE:
639 ev_periodic_stop (w); 702 ev_periodic_stop (w);
640 e_destroy (w); 703 e_destroy (w);
641 704
642void 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)
643 INIT: 706 INIT:
644 CHECK_REPEAT (interval); 707 CHECK_REPEAT (interval);
645 CODE: 708 CODE:
646{ 709{
647 int active = ev_is_active (w); 710 int active = ev_is_active (w);
648 if (active) ev_periodic_stop (w); 711 if (active) ev_periodic_stop (w);
649 712
713 SvREFCNT_dec (w->fh);
714 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
650 ev_periodic_set (w, at, interval); 715 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
651 716
652 if (active) ev_periodic_start (w); 717 if (active) ev_periodic_start (w);
653} 718}
654 719
655MODULE = 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