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

Comparing EV/EV.xs (file contents):
Revision 1.55 by root, Tue Nov 6 12:36:25 2007 UTC vs.
Revision 1.63 by root, Sat Nov 10 03:19:21 2007 UTC

5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define EV_PROTOTYPES 1 7#define EV_PROTOTYPES 1
8#include "EV/EVAPI.h" 8#include "EV/EVAPI.h"
9 9
10/* fix perl api breakage */
11#undef signal
12#undef sigaction
13
14#define EV_SELECT_USE_WIN32_HANDLES 0
15#define EV_SELECT_USE_FD_SET 0
10/* 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 */
11#include "libev/ev.c" 17#include "libev/ev.c"
12#include "event.c" 18#include "event.c"
19
20#ifndef WIN32
13#define DNS_USE_GETTIMEOFDAY_FOR_ID 1 21#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
14#if !defined (WIN32) && !defined(__CYGWIN__) 22#if !defined (WIN32) && !defined(__CYGWIN__)
15# define HAVE_STRUCT_IN6_ADDR 1 23# define HAVE_STRUCT_IN6_ADDR 1
16#endif 24#endif
17#undef HAVE_STRTOK_R 25#undef HAVE_STRTOK_R
18#undef strtok_r 26#undef strtok_r
19#define strtok_r fake_strtok_r 27#define strtok_r fake_strtok_r
28#include "evdns.h"
20#include "evdns.c" 29#include "evdns.c"
30#endif
21 31
22#ifndef WIN32 32#ifndef WIN32
23# include <pthread.h> 33# include <pthread.h>
24#endif 34#endif
25 35
91 SvPOK_only (self); 101 SvPOK_only (self);
92 SvCUR_set (self, size); 102 SvCUR_set (self, size);
93 103
94 w = (struct ev_watcher *)SvPVX (self); 104 w = (struct ev_watcher *)SvPVX (self);
95 105
96 ev_watcher_init (w, e_cb); 106 ev_init (w, e_cb);
97 107
108 w->data = 0;
98 w->fh = 0; 109 w->fh = 0;
99 w->cb_sv = newSVsv (cb_sv); 110 w->cb_sv = newSVsv (cb_sv);
100 w->self = self; 111 w->self = self;
101 112
102 return (void *)w; 113 return (void *)w;
103} 114}
104 115
105static void * 116static void
106e_destroy (void *w_) 117e_destroy (void *w_)
107{ 118{
108 struct ev_watcher *w = w_; 119 struct ev_watcher *w = (struct ev_watcher *)w_;
109 120
110 SvREFCNT_dec (w->fh ); w->fh = 0; 121 SvREFCNT_dec (w->fh ); w->fh = 0;
111 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;
112} 124}
113 125
114static SV * 126static SV *
115e_bless (struct ev_watcher *w, HV *stash) 127e_bless (struct ev_watcher *w, HV *stash)
116{ 128{
170 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);
171 SP = PL_stack_base + mark; PUTBACK; 183 SP = PL_stack_base + mark; PUTBACK;
172 } 184 }
173} 185}
174 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;
228}
229
175///////////////////////////////////////////////////////////////////////////// 230/////////////////////////////////////////////////////////////////////////////
176// DNS 231// DNS
177 232
233#ifndef WIN32
178static void 234static void
179dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 235dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
180{ 236{
181 dSP; 237 dSP;
182 SV *cb = (SV *)arg; 238 SV *cb = (SV *)arg;
221 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 277 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
222 } 278 }
223 279
224 LEAVE; 280 LEAVE;
225} 281}
282#endif
226 283
227#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 284#define CHECK_REPEAT(repeat) if (repeat < 0.) \
228 croak (# repeat " value must be >= 0"); 285 croak (# repeat " value must be >= 0");
229 286
230#define CHECK_FD(fh,fd) if ((fd) < 0) \ 287#define CHECK_FD(fh,fd) if ((fd) < 0) \
237 294
238PROTOTYPES: ENABLE 295PROTOTYPES: ENABLE
239 296
240BOOT: 297BOOT:
241{ 298{
242 int i;
243 HV *stash = gv_stashpv ("EV", 1); 299 HV *stash = gv_stashpv ("EV", 1);
244 300
245 static const struct { 301 static const struct {
246 const char *name; 302 const char *name;
247 IV iv; 303 IV iv;
320 evapi.child_stop = ev_child_stop; 376 evapi.child_stop = ev_child_stop;
321 377
322 sv_setiv (sv, (IV)&evapi); 378 sv_setiv (sv, (IV)&evapi);
323 SvREADONLY_on (sv); 379 SvREADONLY_on (sv);
324 } 380 }
325
326 #ifndef WIN32 381#ifndef WIN32
327 pthread_atfork (0, 0, ev_default_fork); 382 pthread_atfork (0, 0, ev_default_fork);
328 #endif 383#endif
329} 384}
330 385
331NV ev_now () 386NV ev_now ()
332 387
333int ev_method () 388int ev_method ()
366 ev_timer_set (RETVAL, after, repeat); 421 ev_timer_set (RETVAL, after, repeat);
367 if (!ix) ev_timer_start (RETVAL); 422 if (!ix) ev_timer_start (RETVAL);
368 OUTPUT: 423 OUTPUT:
369 RETVAL 424 RETVAL
370 425
371struct ev_periodic *periodic (NV at, NV interval, SV *cb) 426SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
372 ALIAS: 427 ALIAS:
373 periodic_ns = 1 428 periodic_ns = 1
374 INIT: 429 INIT:
375 CHECK_REPEAT (interval); 430 CHECK_REPEAT (interval);
376 CODE: 431 CODE:
432{
433 struct ev_periodic *w;
377 RETVAL = e_new (sizeof (struct ev_periodic), cb); 434 w = e_new (sizeof (struct ev_periodic), cb);
378 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);
379 if (!ix) ev_periodic_start (RETVAL); 438 if (!ix) ev_periodic_start (w);
439}
380 OUTPUT: 440 OUTPUT:
381 RETVAL 441 RETVAL
382 442
383struct ev_signal *signal (Signal signum, SV *cb) 443struct ev_signal *signal (Signal signum, SV *cb)
384 ALIAS: 444 ALIAS:
442{ 502{
443 RETVAL = newSVsv (w->cb_sv); 503 RETVAL = newSVsv (w->cb_sv);
444 504
445 if (items > 1) 505 if (items > 1)
446 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;
447} 515}
448 OUTPUT: 516 OUTPUT:
449 RETVAL 517 RETVAL
450 518
451void trigger (struct ev_watcher *w, int revents = EV_NONE) 519void trigger (struct ev_watcher *w, int revents = EV_NONE)
625 INIT: 693 INIT:
626 CHECK_REPEAT (w->interval); 694 CHECK_REPEAT (w->interval);
627 695
628void ev_periodic_stop (struct ev_periodic *w) 696void ev_periodic_stop (struct ev_periodic *w)
629 697
698void ev_periodic_again (struct ev_periodic *w)
699
630void DESTROY (struct ev_periodic *w) 700void DESTROY (struct ev_periodic *w)
631 CODE: 701 CODE:
632 ev_periodic_stop (w); 702 ev_periodic_stop (w);
633 e_destroy (w); 703 e_destroy (w);
634 704
635void 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)
636 INIT: 706 INIT:
637 CHECK_REPEAT (interval); 707 CHECK_REPEAT (interval);
638 CODE: 708 CODE:
639{ 709{
640 int active = ev_is_active (w); 710 int active = ev_is_active (w);
641 if (active) ev_periodic_stop (w); 711 if (active) ev_periodic_stop (w);
642 712
713 SvREFCNT_dec (w->fh);
714 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
643 ev_periodic_set (w, at, interval); 715 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
644 716
645 if (active) ev_periodic_start (w); 717 if (active) ev_periodic_start (w);
646} 718}
647 719
648MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 720MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
724 rpid = 1 796 rpid = 1
725 CODE: 797 CODE:
726 RETVAL = ix ? w->rpid : w->rstatus; 798 RETVAL = ix ? w->rpid : w->rstatus;
727 OUTPUT: 799 OUTPUT:
728 RETVAL 800 RETVAL
801
802#ifndef WIN32
729 803
730MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 804MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
731 805
732BOOT: 806BOOT:
733{ 807{
858 932
859#void DESTROY (struct evhttp_request *req); 933#void DESTROY (struct evhttp_request *req);
860 934
861#endif 935#endif
862 936
937#endif
863 938
864 939
865 940
866 941
867 942

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines