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

Comparing EV/EV.xs (file contents):
Revision 1.51 by root, Sun Nov 4 18:15:27 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
16/* due to bugs in OS X we have to use libev/ explicitly here */
10#include "ev.c" 17#include "libev/ev.c"
11#include "event.c" 18#include "event.c"
19
20#ifndef WIN32
12#define DNS_USE_GETTIMEOFDAY_FOR_ID 1 21#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
22#if !defined (WIN32) && !defined(__CYGWIN__)
13#define HAVE_STRUCT_IN6_ADDR 1 23# define HAVE_STRUCT_IN6_ADDR 1
24#endif
14#undef HAVE_STRTOK_R 25#undef HAVE_STRTOK_R
15#undef strtok_r 26#undef strtok_r
16#define strtok_r fake_strtok_r 27#define strtok_r fake_strtok_r
28#include "evdns.h"
17#include "evdns.c" 29#include "evdns.c"
30#endif
31
32#ifndef WIN32
33# include <pthread.h>
34#endif
18 35
19typedef int Signal; 36typedef int Signal;
20 37
21static struct EVAPI evapi; 38static struct EVAPI evapi;
22 39
84 SvPOK_only (self); 101 SvPOK_only (self);
85 SvCUR_set (self, size); 102 SvCUR_set (self, size);
86 103
87 w = (struct ev_watcher *)SvPVX (self); 104 w = (struct ev_watcher *)SvPVX (self);
88 105
89 ev_watcher_init (w, e_cb); 106 ev_init (w, e_cb);
90 107
108 w->data = 0;
91 w->fh = 0; 109 w->fh = 0;
92 w->cb_sv = newSVsv (cb_sv); 110 w->cb_sv = newSVsv (cb_sv);
93 w->self = self; 111 w->self = self;
94 112
95 return (void *)w; 113 return (void *)w;
96} 114}
97 115
98static void * 116static void
99e_destroy (void *w_) 117e_destroy (void *w_)
100{ 118{
101 struct ev_watcher *w = w_; 119 struct ev_watcher *w = (struct ev_watcher *)w_;
102 120
103 SvREFCNT_dec (w->fh ); w->fh = 0; 121 SvREFCNT_dec (w->fh ); w->fh = 0;
104 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;
105} 124}
106 125
107static SV * 126static SV *
108e_bless (struct ev_watcher *w, HV *stash) 127e_bless (struct ev_watcher *w, HV *stash)
109{ 128{
163 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);
164 SP = PL_stack_base + mark; PUTBACK; 183 SP = PL_stack_base + mark; PUTBACK;
165 } 184 }
166} 185}
167 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
168///////////////////////////////////////////////////////////////////////////// 230/////////////////////////////////////////////////////////////////////////////
169// DNS 231// DNS
170 232
233#ifndef WIN32
171static void 234static void
172dns_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)
173{ 236{
174 dSP; 237 dSP;
175 SV *cb = (SV *)arg; 238 SV *cb = (SV *)arg;
214 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);
215 } 278 }
216 279
217 LEAVE; 280 LEAVE;
218} 281}
282#endif
219 283
220#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 284#define CHECK_REPEAT(repeat) if (repeat < 0.) \
221 croak (# repeat " value must be >= 0"); 285 croak (# repeat " value must be >= 0");
222 286
223#define CHECK_FD(fh,fd) if ((fd) < 0) \ 287#define CHECK_FD(fh,fd) if ((fd) < 0) \
230 294
231PROTOTYPES: ENABLE 295PROTOTYPES: ENABLE
232 296
233BOOT: 297BOOT:
234{ 298{
235 int i;
236 HV *stash = gv_stashpv ("EV", 1); 299 HV *stash = gv_stashpv ("EV", 1);
237 300
238 static const struct { 301 static const struct {
239 const char *name; 302 const char *name;
240 IV iv; 303 IV iv;
313 evapi.child_stop = ev_child_stop; 376 evapi.child_stop = ev_child_stop;
314 377
315 sv_setiv (sv, (IV)&evapi); 378 sv_setiv (sv, (IV)&evapi);
316 SvREADONLY_on (sv); 379 SvREADONLY_on (sv);
317 } 380 }
318 381#ifndef WIN32
319 pthread_atfork (0, 0, ev_default_fork); 382 pthread_atfork (0, 0, ev_default_fork);
383#endif
320} 384}
321 385
322NV ev_now () 386NV ev_now ()
323 387
324int ev_method () 388int ev_method ()
357 ev_timer_set (RETVAL, after, repeat); 421 ev_timer_set (RETVAL, after, repeat);
358 if (!ix) ev_timer_start (RETVAL); 422 if (!ix) ev_timer_start (RETVAL);
359 OUTPUT: 423 OUTPUT:
360 RETVAL 424 RETVAL
361 425
362struct ev_periodic *periodic (NV at, NV interval, SV *cb) 426SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
363 ALIAS: 427 ALIAS:
364 periodic_ns = 1 428 periodic_ns = 1
365 INIT: 429 INIT:
366 CHECK_REPEAT (interval); 430 CHECK_REPEAT (interval);
367 CODE: 431 CODE:
432{
433 struct ev_periodic *w;
368 RETVAL = e_new (sizeof (struct ev_periodic), cb); 434 w = e_new (sizeof (struct ev_periodic), cb);
369 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);
370 if (!ix) ev_periodic_start (RETVAL); 438 if (!ix) ev_periodic_start (w);
439}
371 OUTPUT: 440 OUTPUT:
372 RETVAL 441 RETVAL
373 442
374struct ev_signal *signal (Signal signum, SV *cb) 443struct ev_signal *signal (Signal signum, SV *cb)
375 ALIAS: 444 ALIAS:
433{ 502{
434 RETVAL = newSVsv (w->cb_sv); 503 RETVAL = newSVsv (w->cb_sv);
435 504
436 if (items > 1) 505 if (items > 1)
437 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;
438} 515}
439 OUTPUT: 516 OUTPUT:
440 RETVAL 517 RETVAL
441 518
442void trigger (struct ev_watcher *w, int revents = EV_NONE) 519void trigger (struct ev_watcher *w, int revents = EV_NONE)
580 } 657 }
581} 658}
582 OUTPUT: 659 OUTPUT:
583 RETVAL 660 RETVAL
584 661
585MODULE = EV PACKAGE = EV::Time
586
587MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 662MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
588 663
589void ev_timer_start (struct ev_timer *w) 664void ev_timer_start (struct ev_timer *w)
590 INIT: 665 INIT:
591 CHECK_REPEAT (w->repeat); 666 CHECK_REPEAT (w->repeat);
618 INIT: 693 INIT:
619 CHECK_REPEAT (w->interval); 694 CHECK_REPEAT (w->interval);
620 695
621void ev_periodic_stop (struct ev_periodic *w) 696void ev_periodic_stop (struct ev_periodic *w)
622 697
698void ev_periodic_again (struct ev_periodic *w)
699
623void DESTROY (struct ev_periodic *w) 700void DESTROY (struct ev_periodic *w)
624 CODE: 701 CODE:
625 ev_periodic_stop (w); 702 ev_periodic_stop (w);
626 e_destroy (w); 703 e_destroy (w);
627 704
628void 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)
629 INIT: 706 INIT:
630 CHECK_REPEAT (interval); 707 CHECK_REPEAT (interval);
631 CODE: 708 CODE:
632{ 709{
633 int active = ev_is_active (w); 710 int active = ev_is_active (w);
634 if (active) ev_periodic_stop (w); 711 if (active) ev_periodic_stop (w);
635 712
713 SvREFCNT_dec (w->fh);
714 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
636 ev_periodic_set (w, at, interval); 715 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
637 716
638 if (active) ev_periodic_start (w); 717 if (active) ev_periodic_start (w);
639} 718}
640 719
641MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 720MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
717 rpid = 1 796 rpid = 1
718 CODE: 797 CODE:
719 RETVAL = ix ? w->rpid : w->rstatus; 798 RETVAL = ix ? w->rpid : w->rstatus;
720 OUTPUT: 799 OUTPUT:
721 RETVAL 800 RETVAL
801
802#ifndef WIN32
722 803
723MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 804MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
724 805
725BOOT: 806BOOT:
726{ 807{
851 932
852#void DESTROY (struct evhttp_request *req); 933#void DESTROY (struct evhttp_request *req);
853 934
854#endif 935#endif
855 936
937#endif
856 938
857 939
858 940
859 941
860 942

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines