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

Comparing EV/EV.xs (file contents):
Revision 1.43 by root, Fri Nov 2 22:18:49 2007 UTC vs.
Revision 1.57 by root, Tue Nov 6 17:20:42 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/* due to bugs in OS X we have to use libev/ explicitly here */
10#include "libev/ev.c" 15#include "libev/ev.c"
11#include "libev/event.h"
12#include "libev/event.c" 16#include "event.c"
17
18#ifndef WIN32
19#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
20#if !defined (WIN32) && !defined(__CYGWIN__)
21# define HAVE_STRUCT_IN6_ADDR 1
22#endif
23#undef HAVE_STRTOK_R
24#undef strtok_r
25#define strtok_r fake_strtok_r
13#include "libev/evdns.c" 26#include "evdns.c"
27#endif
28
29#ifndef WIN32
30# include <pthread.h>
31#endif
14 32
15typedef int Signal; 33typedef int Signal;
16 34
17static struct EVAPI evapi; 35static struct EVAPI evapi;
18 36
89 w->self = self; 107 w->self = self;
90 108
91 return (void *)w; 109 return (void *)w;
92} 110}
93 111
94static void * 112static void
95e_destroy (void *w_) 113e_destroy (void *w_)
96{ 114{
97 struct ev_watcher *w = w_; 115 struct ev_watcher *w = (struct ev_watcher *)w_;
98 116
99 SvREFCNT_dec (w->fh ); w->fh = 0; 117 SvREFCNT_dec (w->fh ); w->fh = 0;
100 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 118 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
101} 119}
102 120
138 PUSHMARK (SP); 156 PUSHMARK (SP);
139 EXTEND (SP, 2); 157 EXTEND (SP, 2);
140 PUSHs (sv_self); 158 PUSHs (sv_self);
141 PUSHs (sv_events); 159 PUSHs (sv_events);
142 160
143 if (revents & EV_CHILD)
144 XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status));
145
146 PUTBACK; 161 PUTBACK;
147 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 162 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
148 SP = PL_stack_base + mark; PUTBACK; 163 SP = PL_stack_base + mark; PUTBACK;
149 164
150 SvREFCNT_dec (sv_self); 165 SvREFCNT_dec (sv_self);
165} 180}
166 181
167///////////////////////////////////////////////////////////////////////////// 182/////////////////////////////////////////////////////////////////////////////
168// DNS 183// DNS
169 184
185#ifndef WIN32
170static void 186static void
171dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 187dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
172{ 188{
173 dSP; 189 dSP;
174 SV *cb = (SV *)arg; 190 SV *cb = (SV *)arg;
213 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 229 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
214 } 230 }
215 231
216 LEAVE; 232 LEAVE;
217} 233}
234#endif
218 235
219#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 236#define CHECK_REPEAT(repeat) if (repeat < 0.) \
220 croak (# repeat " value must be >= 0"); 237 croak (# repeat " value must be >= 0");
221 238
222#define CHECK_FD(fh,fd) if ((fd) < 0) \ 239#define CHECK_FD(fh,fd) if ((fd) < 0) \
229 246
230PROTOTYPES: ENABLE 247PROTOTYPES: ENABLE
231 248
232BOOT: 249BOOT:
233{ 250{
234 int i;
235 HV *stash = gv_stashpv ("EV", 1); 251 HV *stash = gv_stashpv ("EV", 1);
236 252
237 static const struct { 253 static const struct {
238 const char *name; 254 const char *name;
239 IV iv; 255 IV iv;
285 /* the poor man's shared library emulator */ 301 /* the poor man's shared library emulator */
286 evapi.ver = EV_API_VERSION; 302 evapi.ver = EV_API_VERSION;
287 evapi.rev = EV_API_REVISION; 303 evapi.rev = EV_API_REVISION;
288 evapi.sv_fileno = sv_fileno; 304 evapi.sv_fileno = sv_fileno;
289 evapi.sv_signum = sv_signum; 305 evapi.sv_signum = sv_signum;
290 evapi.now = &ev_now; 306 evapi.now = ev_now;
291 evapi.method = &ev_method; 307 evapi.method = ev_method;
292 evapi.loop_done = &ev_loop_done; 308 evapi.unloop = ev_unloop;
293 evapi.time = ev_time; 309 evapi.time = ev_time;
294 evapi.loop = ev_loop; 310 evapi.loop = ev_loop;
295 evapi.once = ev_once; 311 evapi.once = ev_once;
296 evapi.io_start = ev_io_start; 312 evapi.io_start = ev_io_start;
297 evapi.io_stop = ev_io_stop; 313 evapi.io_stop = ev_io_stop;
312 evapi.child_stop = ev_child_stop; 328 evapi.child_stop = ev_child_stop;
313 329
314 sv_setiv (sv, (IV)&evapi); 330 sv_setiv (sv, (IV)&evapi);
315 SvREADONLY_on (sv); 331 SvREADONLY_on (sv);
316 } 332 }
317 333#ifndef WIN32
318 pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child); 334 pthread_atfork (0, 0, ev_default_fork);
335#endif
319} 336}
320 337
321NV ev_now () 338NV ev_now ()
322 CODE:
323 RETVAL = ev_now;
324 OUTPUT:
325 RETVAL
326 339
327int ev_method () 340int ev_method ()
328 CODE:
329 RETVAL = ev_method;
330 OUTPUT:
331 RETVAL
332 341
333NV ev_time () 342NV ev_time ()
334 343
335void ev_init (int methods = EVMETHOD_AUTO) 344int ev_default_loop (int methods = EVMETHOD_AUTO)
336 345
337void ev_loop (int flags = 0) 346void ev_loop (int flags = 0)
338 347
339void ev_loop_done (int value = 1) 348void ev_unloop (int how = 1)
340 CODE:
341 ev_loop_done = value;
342 349
343struct ev_io *io (SV *fh, int events, SV *cb) 350struct ev_io *io (SV *fh, int events, SV *cb)
344 ALIAS: 351 ALIAS:
345 io_ns = 1 352 io_ns = 1
346 CODE: 353 CODE:
422 429
423struct ev_child *child (int pid, SV *cb) 430struct ev_child *child (int pid, SV *cb)
424 ALIAS: 431 ALIAS:
425 check_ns = 1 432 check_ns = 1
426 CODE: 433 CODE:
427 RETVAL = e_new (sizeof (struct ev_check), cb); 434 RETVAL = e_new (sizeof (struct ev_child), cb);
428 ev_child_set (RETVAL, pid); 435 ev_child_set (RETVAL, pid);
429 if (!ix) ev_child_start (RETVAL); 436 if (!ix) ev_child_start (RETVAL);
430 OUTPUT: 437 OUTPUT:
431 RETVAL 438 RETVAL
432 439
589 } 596 }
590} 597}
591 OUTPUT: 598 OUTPUT:
592 RETVAL 599 RETVAL
593 600
594MODULE = EV PACKAGE = EV::Time
595
596MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 601MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
597 602
598void ev_timer_start (struct ev_timer *w) 603void ev_timer_start (struct ev_timer *w)
599 INIT: 604 INIT:
600 CHECK_REPEAT (w->repeat); 605 CHECK_REPEAT (w->repeat);
719} 724}
720 OUTPUT: 725 OUTPUT:
721 RETVAL 726 RETVAL
722 727
723 728
724int status (struct ev_child *w) 729int rstatus (struct ev_child *w)
730 ALIAS:
731 rpid = 1
725 CODE: 732 CODE:
726 RETVAL = w->status; 733 RETVAL = ix ? w->rpid : w->rstatus;
727 OUTPUT: 734 OUTPUT:
728 RETVAL 735 RETVAL
736
737#ifndef WIN32
729 738
730MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 739MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
731 740
732BOOT: 741BOOT:
733{ 742{
858 867
859#void DESTROY (struct evhttp_request *req); 868#void DESTROY (struct evhttp_request *req);
860 869
861#endif 870#endif
862 871
872#endif
863 873
864 874
865 875
866 876
867 877

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines