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

Comparing EV/EV.xs (file contents):
Revision 1.49 by root, Sun Nov 4 16:43:53 2007 UTC vs.
Revision 1.61 by root, Thu Nov 8 17:24:00 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 "libev/ev.c" 17#include "libev/ev.c"
11#include "libev/event.h"
12#include "libev/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
18#include "libev/evdns.c" 28#include "evdns.c"
29#endif
30
31#ifndef WIN32
32# include <pthread.h>
33#endif
19 34
20typedef int Signal; 35typedef int Signal;
21 36
22static struct EVAPI evapi; 37static struct EVAPI evapi;
23 38
87 102
88 w = (struct ev_watcher *)SvPVX (self); 103 w = (struct ev_watcher *)SvPVX (self);
89 104
90 ev_watcher_init (w, e_cb); 105 ev_watcher_init (w, e_cb);
91 106
107 w->data = 0;
92 w->fh = 0; 108 w->fh = 0;
93 w->cb_sv = newSVsv (cb_sv); 109 w->cb_sv = newSVsv (cb_sv);
94 w->self = self; 110 w->self = self;
95 111
96 return (void *)w; 112 return (void *)w;
97} 113}
98 114
99static void * 115static void
100e_destroy (void *w_) 116e_destroy (void *w_)
101{ 117{
102 struct ev_watcher *w = w_; 118 struct ev_watcher *w = (struct ev_watcher *)w_;
103 119
104 SvREFCNT_dec (w->fh ); w->fh = 0; 120 SvREFCNT_dec (w->fh ); w->fh = 0;
105 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 121 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
122 SvREFCNT_dec (w->data ); w->data = 0;
106} 123}
107 124
108static SV * 125static SV *
109e_bless (struct ev_watcher *w, HV *stash) 126e_bless (struct ev_watcher *w, HV *stash)
110{ 127{
164 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 181 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
165 SP = PL_stack_base + mark; PUTBACK; 182 SP = PL_stack_base + mark; PUTBACK;
166 } 183 }
167} 184}
168 185
186static ev_tstamp
187e_periodic_cb (struct ev_periodic *w, ev_tstamp now)
188{
189 ev_tstamp retval;
190 int count;
191 dSP;
192
193 ENTER;
194 SAVETMPS;
195
196 PUSHMARK (SP);
197 EXTEND (SP, 2);
198 PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */
199 PUSHs (newSVnv (now));
200
201 PUTBACK;
202 count = call_sv (w->fh, G_SCALAR | G_EVAL);
203 SPAGAIN;
204
205 if (SvTRUE (ERRSV))
206 {
207 PUSHMARK (SP);
208 PUTBACK;
209 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
210 SPAGAIN;
211 }
212
213 if (count > 0)
214 {
215 retval = SvNV (TOPs);
216
217 if (retval < now)
218 retval = now;
219 }
220 else
221 retval = now;
222
223 FREETMPS;
224 LEAVE;
225
226 return retval;
227}
228
169///////////////////////////////////////////////////////////////////////////// 229/////////////////////////////////////////////////////////////////////////////
170// DNS 230// DNS
171 231
232#ifndef WIN32
172static void 233static void
173dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 234dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
174{ 235{
175 dSP; 236 dSP;
176 SV *cb = (SV *)arg; 237 SV *cb = (SV *)arg;
215 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 276 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
216 } 277 }
217 278
218 LEAVE; 279 LEAVE;
219} 280}
281#endif
220 282
221#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 283#define CHECK_REPEAT(repeat) if (repeat < 0.) \
222 croak (# repeat " value must be >= 0"); 284 croak (# repeat " value must be >= 0");
223 285
224#define CHECK_FD(fh,fd) if ((fd) < 0) \ 286#define CHECK_FD(fh,fd) if ((fd) < 0) \
231 293
232PROTOTYPES: ENABLE 294PROTOTYPES: ENABLE
233 295
234BOOT: 296BOOT:
235{ 297{
236 int i;
237 HV *stash = gv_stashpv ("EV", 1); 298 HV *stash = gv_stashpv ("EV", 1);
238 299
239 static const struct { 300 static const struct {
240 const char *name; 301 const char *name;
241 IV iv; 302 IV iv;
314 evapi.child_stop = ev_child_stop; 375 evapi.child_stop = ev_child_stop;
315 376
316 sv_setiv (sv, (IV)&evapi); 377 sv_setiv (sv, (IV)&evapi);
317 SvREADONLY_on (sv); 378 SvREADONLY_on (sv);
318 } 379 }
319 380#ifndef WIN32
320 pthread_atfork (0, 0, ev_default_fork); 381 pthread_atfork (0, 0, ev_default_fork);
382#endif
321} 383}
322 384
323NV ev_now () 385NV ev_now ()
324 386
325int ev_method () 387int ev_method ()
326 388
327NV ev_time () 389NV ev_time ()
328 390
329int ev_init (int methods = EVMETHOD_AUTO) 391int ev_default_loop (int methods = EVMETHOD_AUTO)
330 392
331void ev_loop (int flags = 0) 393void ev_loop (int flags = 0)
332 394
333void ev_unloop (int how = 1) 395void ev_unloop (int how = 1)
334 396
358 ev_timer_set (RETVAL, after, repeat); 420 ev_timer_set (RETVAL, after, repeat);
359 if (!ix) ev_timer_start (RETVAL); 421 if (!ix) ev_timer_start (RETVAL);
360 OUTPUT: 422 OUTPUT:
361 RETVAL 423 RETVAL
362 424
363struct ev_periodic *periodic (NV at, NV interval, SV *cb) 425SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
364 ALIAS: 426 ALIAS:
365 periodic_ns = 1 427 periodic_ns = 1
366 INIT: 428 INIT:
367 CHECK_REPEAT (interval); 429 CHECK_REPEAT (interval);
368 CODE: 430 CODE:
431{
432 struct ev_periodic *w;
369 RETVAL = e_new (sizeof (struct ev_periodic), cb); 433 w = e_new (sizeof (struct ev_periodic), cb);
370 ev_periodic_set (RETVAL, at, interval); 434 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
435 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
436 RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic);
371 if (!ix) ev_periodic_start (RETVAL); 437 if (!ix) ev_periodic_start (w);
438}
372 OUTPUT: 439 OUTPUT:
373 RETVAL 440 RETVAL
374 441
375struct ev_signal *signal (Signal signum, SV *cb) 442struct ev_signal *signal (Signal signum, SV *cb)
376 ALIAS: 443 ALIAS:
434{ 501{
435 RETVAL = newSVsv (w->cb_sv); 502 RETVAL = newSVsv (w->cb_sv);
436 503
437 if (items > 1) 504 if (items > 1)
438 sv_setsv (w->cb_sv, new_cb); 505 sv_setsv (w->cb_sv, new_cb);
506}
507 OUTPUT:
508 RETVAL
509
510SV *data (struct ev_watcher *w, SV *new_data = 0)
511 CODE:
512{
513 RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
439} 514}
440 OUTPUT: 515 OUTPUT:
441 RETVAL 516 RETVAL
442 517
443void trigger (struct ev_watcher *w, int revents = EV_NONE) 518void trigger (struct ev_watcher *w, int revents = EV_NONE)
581 } 656 }
582} 657}
583 OUTPUT: 658 OUTPUT:
584 RETVAL 659 RETVAL
585 660
586MODULE = EV PACKAGE = EV::Time
587
588MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 661MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
589 662
590void ev_timer_start (struct ev_timer *w) 663void ev_timer_start (struct ev_timer *w)
591 INIT: 664 INIT:
592 CHECK_REPEAT (w->repeat); 665 CHECK_REPEAT (w->repeat);
619 INIT: 692 INIT:
620 CHECK_REPEAT (w->interval); 693 CHECK_REPEAT (w->interval);
621 694
622void ev_periodic_stop (struct ev_periodic *w) 695void ev_periodic_stop (struct ev_periodic *w)
623 696
697void ev_periodic_again (struct ev_periodic *w)
698
624void DESTROY (struct ev_periodic *w) 699void DESTROY (struct ev_periodic *w)
625 CODE: 700 CODE:
626 ev_periodic_stop (w); 701 ev_periodic_stop (w);
627 e_destroy (w); 702 e_destroy (w);
628 703
629void set (struct ev_periodic *w, NV at, NV interval = 0.) 704void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
630 INIT: 705 INIT:
631 CHECK_REPEAT (interval); 706 CHECK_REPEAT (interval);
632 CODE: 707 CODE:
633{ 708{
634 int active = ev_is_active (w); 709 int active = ev_is_active (w);
635 if (active) ev_periodic_stop (w); 710 if (active) ev_periodic_stop (w);
636 711
712 SvREFCNT_dec (w->fh);
713 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
637 ev_periodic_set (w, at, interval); 714 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
638 715
639 if (active) ev_periodic_start (w); 716 if (active) ev_periodic_start (w);
640} 717}
641 718
642MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 719MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
718 rpid = 1 795 rpid = 1
719 CODE: 796 CODE:
720 RETVAL = ix ? w->rpid : w->rstatus; 797 RETVAL = ix ? w->rpid : w->rstatus;
721 OUTPUT: 798 OUTPUT:
722 RETVAL 799 RETVAL
800
801#ifndef WIN32
723 802
724MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 803MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
725 804
726BOOT: 805BOOT:
727{ 806{
852 931
853#void DESTROY (struct evhttp_request *req); 932#void DESTROY (struct evhttp_request *req);
854 933
855#endif 934#endif
856 935
936#endif
857 937
858 938
859 939
860 940
861 941

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines