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

Comparing EV/EV.xs (file contents):
Revision 1.47 by root, Sat Nov 3 21:58:51 2007 UTC vs.
Revision 1.63 by root, Sat Nov 10 03:19:21 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines