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

Comparing EV/EV.xs (file contents):
Revision 1.55 by root, Tue Nov 6 12:36:25 2007 UTC vs.
Revision 1.60 by root, Thu Nov 8 02:19:36 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
20#include "evdns.c" 28#include "evdns.c"
29#endif
21 30
22#ifndef WIN32 31#ifndef WIN32
23# include <pthread.h> 32# include <pthread.h>
24#endif 33#endif
25 34
100 w->self = self; 109 w->self = self;
101 110
102 return (void *)w; 111 return (void *)w;
103} 112}
104 113
105static void * 114static void
106e_destroy (void *w_) 115e_destroy (void *w_)
107{ 116{
108 struct ev_watcher *w = w_; 117 struct ev_watcher *w = (struct ev_watcher *)w_;
109 118
110 SvREFCNT_dec (w->fh ); w->fh = 0; 119 SvREFCNT_dec (w->fh ); w->fh = 0;
111 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 120 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
121 SvREFCNT_dec (w->data ); w->data = 0;
112} 122}
113 123
114static SV * 124static SV *
115e_bless (struct ev_watcher *w, HV *stash) 125e_bless (struct ev_watcher *w, HV *stash)
116{ 126{
170 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 180 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
171 SP = PL_stack_base + mark; PUTBACK; 181 SP = PL_stack_base + mark; PUTBACK;
172 } 182 }
173} 183}
174 184
185static ev_tstamp
186e_periodic_cb (struct ev_periodic *w, ev_tstamp now)
187{
188 ev_tstamp retval;
189 int count;
190 dSP;
191
192 ENTER;
193 SAVETMPS;
194
195 PUSHMARK (SP);
196 EXTEND (SP, 2);
197 PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */
198 PUSHs (newSVnv (now));
199
200 PUTBACK;
201 count = call_sv (w->fh, G_SCALAR | G_EVAL);
202 SPAGAIN;
203
204 if (SvTRUE (ERRSV))
205 {
206 PUSHMARK (SP);
207 PUTBACK;
208 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
209 SPAGAIN;
210 }
211
212 if (count > 0)
213 {
214 retval = SvNV (TOPs);
215
216 if (retval < now)
217 retval = now;
218 }
219 else
220 retval = now;
221
222 FREETMPS;
223 LEAVE;
224
225 return retval;
226}
227
175///////////////////////////////////////////////////////////////////////////// 228/////////////////////////////////////////////////////////////////////////////
176// DNS 229// DNS
177 230
231#ifndef WIN32
178static void 232static void
179dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 233dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
180{ 234{
181 dSP; 235 dSP;
182 SV *cb = (SV *)arg; 236 SV *cb = (SV *)arg;
221 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 275 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
222 } 276 }
223 277
224 LEAVE; 278 LEAVE;
225} 279}
280#endif
226 281
227#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 282#define CHECK_REPEAT(repeat) if (repeat < 0.) \
228 croak (# repeat " value must be >= 0"); 283 croak (# repeat " value must be >= 0");
229 284
230#define CHECK_FD(fh,fd) if ((fd) < 0) \ 285#define CHECK_FD(fh,fd) if ((fd) < 0) \
237 292
238PROTOTYPES: ENABLE 293PROTOTYPES: ENABLE
239 294
240BOOT: 295BOOT:
241{ 296{
242 int i;
243 HV *stash = gv_stashpv ("EV", 1); 297 HV *stash = gv_stashpv ("EV", 1);
244 298
245 static const struct { 299 static const struct {
246 const char *name; 300 const char *name;
247 IV iv; 301 IV iv;
320 evapi.child_stop = ev_child_stop; 374 evapi.child_stop = ev_child_stop;
321 375
322 sv_setiv (sv, (IV)&evapi); 376 sv_setiv (sv, (IV)&evapi);
323 SvREADONLY_on (sv); 377 SvREADONLY_on (sv);
324 } 378 }
325
326 #ifndef WIN32 379#ifndef WIN32
327 pthread_atfork (0, 0, ev_default_fork); 380 pthread_atfork (0, 0, ev_default_fork);
328 #endif 381#endif
329} 382}
330 383
331NV ev_now () 384NV ev_now ()
332 385
333int ev_method () 386int ev_method ()
366 ev_timer_set (RETVAL, after, repeat); 419 ev_timer_set (RETVAL, after, repeat);
367 if (!ix) ev_timer_start (RETVAL); 420 if (!ix) ev_timer_start (RETVAL);
368 OUTPUT: 421 OUTPUT:
369 RETVAL 422 RETVAL
370 423
371struct ev_periodic *periodic (NV at, NV interval, SV *cb) 424SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
372 ALIAS: 425 ALIAS:
373 periodic_ns = 1 426 periodic_ns = 1
374 INIT: 427 INIT:
375 CHECK_REPEAT (interval); 428 CHECK_REPEAT (interval);
376 CODE: 429 CODE:
430{
431 struct ev_periodic *w;
377 RETVAL = e_new (sizeof (struct ev_periodic), cb); 432 w = e_new (sizeof (struct ev_periodic), cb);
378 ev_periodic_set (RETVAL, at, interval); 433 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
434 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
435 RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic);
379 if (!ix) ev_periodic_start (RETVAL); 436 if (!ix) ev_periodic_start (w);
437}
380 OUTPUT: 438 OUTPUT:
381 RETVAL 439 RETVAL
382 440
383struct ev_signal *signal (Signal signum, SV *cb) 441struct ev_signal *signal (Signal signum, SV *cb)
384 ALIAS: 442 ALIAS:
442{ 500{
443 RETVAL = newSVsv (w->cb_sv); 501 RETVAL = newSVsv (w->cb_sv);
444 502
445 if (items > 1) 503 if (items > 1)
446 sv_setsv (w->cb_sv, new_cb); 504 sv_setsv (w->cb_sv, new_cb);
505}
506 OUTPUT:
507 RETVAL
508
509SV *data (struct ev_watcher *w, SV *new_data = 0)
510 CODE:
511{
512 RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
447} 513}
448 OUTPUT: 514 OUTPUT:
449 RETVAL 515 RETVAL
450 516
451void trigger (struct ev_watcher *w, int revents = EV_NONE) 517void trigger (struct ev_watcher *w, int revents = EV_NONE)
625 INIT: 691 INIT:
626 CHECK_REPEAT (w->interval); 692 CHECK_REPEAT (w->interval);
627 693
628void ev_periodic_stop (struct ev_periodic *w) 694void ev_periodic_stop (struct ev_periodic *w)
629 695
696void ev_periodic_again (struct ev_periodic *w)
697
630void DESTROY (struct ev_periodic *w) 698void DESTROY (struct ev_periodic *w)
631 CODE: 699 CODE:
632 ev_periodic_stop (w); 700 ev_periodic_stop (w);
633 e_destroy (w); 701 e_destroy (w);
634 702
635void set (struct ev_periodic *w, NV at, NV interval = 0.) 703void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
636 INIT: 704 INIT:
637 CHECK_REPEAT (interval); 705 CHECK_REPEAT (interval);
638 CODE: 706 CODE:
639{ 707{
640 int active = ev_is_active (w); 708 int active = ev_is_active (w);
641 if (active) ev_periodic_stop (w); 709 if (active) ev_periodic_stop (w);
642 710
711 SvREFCNT_dec (w->fh);
712 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
643 ev_periodic_set (w, at, interval); 713 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
644 714
645 if (active) ev_periodic_start (w); 715 if (active) ev_periodic_start (w);
646} 716}
647 717
648MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 718MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
724 rpid = 1 794 rpid = 1
725 CODE: 795 CODE:
726 RETVAL = ix ? w->rpid : w->rstatus; 796 RETVAL = ix ? w->rpid : w->rstatus;
727 OUTPUT: 797 OUTPUT:
728 RETVAL 798 RETVAL
799
800#ifndef WIN32
729 801
730MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 802MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
731 803
732BOOT: 804BOOT:
733{ 805{
858 930
859#void DESTROY (struct evhttp_request *req); 931#void DESTROY (struct evhttp_request *req);
860 932
861#endif 933#endif
862 934
935#endif
863 936
864 937
865 938
866 939
867 940

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines