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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines