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

Comparing EV/EV.xs (file contents):
Revision 1.54 by root, Tue Nov 6 12:31:20 2007 UTC vs.
Revision 1.62 by root, Fri Nov 9 19:33:51 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
31
32#ifndef WIN32
33# include <pthread.h>
34#endif
21 35
22typedef int Signal; 36typedef int Signal;
23 37
24static struct EVAPI evapi; 38static struct EVAPI evapi;
25 39
89 103
90 w = (struct ev_watcher *)SvPVX (self); 104 w = (struct ev_watcher *)SvPVX (self);
91 105
92 ev_watcher_init (w, e_cb); 106 ev_watcher_init (w, e_cb);
93 107
108 w->data = 0;
94 w->fh = 0; 109 w->fh = 0;
95 w->cb_sv = newSVsv (cb_sv); 110 w->cb_sv = newSVsv (cb_sv);
96 w->self = self; 111 w->self = self;
97 112
98 return (void *)w; 113 return (void *)w;
99} 114}
100 115
101static void * 116static void
102e_destroy (void *w_) 117e_destroy (void *w_)
103{ 118{
104 struct ev_watcher *w = w_; 119 struct ev_watcher *w = (struct ev_watcher *)w_;
105 120
106 SvREFCNT_dec (w->fh ); w->fh = 0; 121 SvREFCNT_dec (w->fh ); w->fh = 0;
107 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;
108} 124}
109 125
110static SV * 126static SV *
111e_bless (struct ev_watcher *w, HV *stash) 127e_bless (struct ev_watcher *w, HV *stash)
112{ 128{
166 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);
167 SP = PL_stack_base + mark; PUTBACK; 183 SP = PL_stack_base + mark; PUTBACK;
168 } 184 }
169} 185}
170 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
171///////////////////////////////////////////////////////////////////////////// 230/////////////////////////////////////////////////////////////////////////////
172// DNS 231// DNS
173 232
233#ifndef WIN32
174static void 234static void
175dns_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)
176{ 236{
177 dSP; 237 dSP;
178 SV *cb = (SV *)arg; 238 SV *cb = (SV *)arg;
217 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);
218 } 278 }
219 279
220 LEAVE; 280 LEAVE;
221} 281}
282#endif
222 283
223#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 284#define CHECK_REPEAT(repeat) if (repeat < 0.) \
224 croak (# repeat " value must be >= 0"); 285 croak (# repeat " value must be >= 0");
225 286
226#define CHECK_FD(fh,fd) if ((fd) < 0) \ 287#define CHECK_FD(fh,fd) if ((fd) < 0) \
233 294
234PROTOTYPES: ENABLE 295PROTOTYPES: ENABLE
235 296
236BOOT: 297BOOT:
237{ 298{
238 int i;
239 HV *stash = gv_stashpv ("EV", 1); 299 HV *stash = gv_stashpv ("EV", 1);
240 300
241 static const struct { 301 static const struct {
242 const char *name; 302 const char *name;
243 IV iv; 303 IV iv;
316 evapi.child_stop = ev_child_stop; 376 evapi.child_stop = ev_child_stop;
317 377
318 sv_setiv (sv, (IV)&evapi); 378 sv_setiv (sv, (IV)&evapi);
319 SvREADONLY_on (sv); 379 SvREADONLY_on (sv);
320 } 380 }
321 381#ifndef WIN32
322 pthread_atfork (0, 0, ev_default_fork); 382 pthread_atfork (0, 0, ev_default_fork);
383#endif
323} 384}
324 385
325NV ev_now () 386NV ev_now ()
326 387
327int ev_method () 388int ev_method ()
360 ev_timer_set (RETVAL, after, repeat); 421 ev_timer_set (RETVAL, after, repeat);
361 if (!ix) ev_timer_start (RETVAL); 422 if (!ix) ev_timer_start (RETVAL);
362 OUTPUT: 423 OUTPUT:
363 RETVAL 424 RETVAL
364 425
365struct ev_periodic *periodic (NV at, NV interval, SV *cb) 426SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
366 ALIAS: 427 ALIAS:
367 periodic_ns = 1 428 periodic_ns = 1
368 INIT: 429 INIT:
369 CHECK_REPEAT (interval); 430 CHECK_REPEAT (interval);
370 CODE: 431 CODE:
432{
433 struct ev_periodic *w;
371 RETVAL = e_new (sizeof (struct ev_periodic), cb); 434 w = e_new (sizeof (struct ev_periodic), cb);
372 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);
373 if (!ix) ev_periodic_start (RETVAL); 438 if (!ix) ev_periodic_start (w);
439}
374 OUTPUT: 440 OUTPUT:
375 RETVAL 441 RETVAL
376 442
377struct ev_signal *signal (Signal signum, SV *cb) 443struct ev_signal *signal (Signal signum, SV *cb)
378 ALIAS: 444 ALIAS:
436{ 502{
437 RETVAL = newSVsv (w->cb_sv); 503 RETVAL = newSVsv (w->cb_sv);
438 504
439 if (items > 1) 505 if (items > 1)
440 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;
441} 515}
442 OUTPUT: 516 OUTPUT:
443 RETVAL 517 RETVAL
444 518
445void trigger (struct ev_watcher *w, int revents = EV_NONE) 519void trigger (struct ev_watcher *w, int revents = EV_NONE)
619 INIT: 693 INIT:
620 CHECK_REPEAT (w->interval); 694 CHECK_REPEAT (w->interval);
621 695
622void ev_periodic_stop (struct ev_periodic *w) 696void ev_periodic_stop (struct ev_periodic *w)
623 697
698void ev_periodic_again (struct ev_periodic *w)
699
624void DESTROY (struct ev_periodic *w) 700void DESTROY (struct ev_periodic *w)
625 CODE: 701 CODE:
626 ev_periodic_stop (w); 702 ev_periodic_stop (w);
627 e_destroy (w); 703 e_destroy (w);
628 704
629void 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)
630 INIT: 706 INIT:
631 CHECK_REPEAT (interval); 707 CHECK_REPEAT (interval);
632 CODE: 708 CODE:
633{ 709{
634 int active = ev_is_active (w); 710 int active = ev_is_active (w);
635 if (active) ev_periodic_stop (w); 711 if (active) ev_periodic_stop (w);
636 712
713 SvREFCNT_dec (w->fh);
714 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
637 ev_periodic_set (w, at, interval); 715 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
638 716
639 if (active) ev_periodic_start (w); 717 if (active) ev_periodic_start (w);
640} 718}
641 719
642MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 720MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
718 rpid = 1 796 rpid = 1
719 CODE: 797 CODE:
720 RETVAL = ix ? w->rpid : w->rstatus; 798 RETVAL = ix ? w->rpid : w->rstatus;
721 OUTPUT: 799 OUTPUT:
722 RETVAL 800 RETVAL
801
802#ifndef WIN32
723 803
724MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 804MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
725 805
726BOOT: 806BOOT:
727{ 807{
852 932
853#void DESTROY (struct evhttp_request *req); 933#void DESTROY (struct evhttp_request *req);
854 934
855#endif 935#endif
856 936
937#endif
857 938
858 939
859 940
860 941
861 942

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines