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

Comparing EV/EV.xs (file contents):
Revision 1.41 by root, Fri Nov 2 20:21:33 2007 UTC vs.
Revision 1.56 by root, Tue Nov 6 16:09:37 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
25 *stash_idle, 43 *stash_idle,
26 *stash_prepare, 44 *stash_prepare,
27 *stash_check, 45 *stash_check,
28 *stash_child; 46 *stash_child;
29 47
48#ifndef SIG_SIZE
49/* kudos to Slaven Rezic for the idea */
50static char sig_size [] = { SIG_NUM };
51# define SIG_SIZE (sizeof (sig_size) + 1)
52#endif
53
30static int 54static int
31sv_signum (SV *sig) 55sv_signum (SV *sig)
32{ 56{
33 int signum; 57 int signum;
34 58
83 w->self = self; 107 w->self = self;
84 108
85 return (void *)w; 109 return (void *)w;
86} 110}
87 111
88static void * 112static void
89e_destroy (void *w_) 113e_destroy (void *w_)
90{ 114{
91 struct ev_watcher *w = w_; 115 struct ev_watcher *w = w_;
92 116
93 SvREFCNT_dec (w->fh ); w->fh = 0; 117 SvREFCNT_dec (w->fh ); w->fh = 0;
132 PUSHMARK (SP); 156 PUSHMARK (SP);
133 EXTEND (SP, 2); 157 EXTEND (SP, 2);
134 PUSHs (sv_self); 158 PUSHs (sv_self);
135 PUSHs (sv_events); 159 PUSHs (sv_events);
136 160
137 if (revents & EV_CHILD)
138 XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status));
139
140 PUTBACK; 161 PUTBACK;
141 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 162 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
142 SP = PL_stack_base + mark; PUTBACK; 163 SP = PL_stack_base + mark; PUTBACK;
143 164
144 SvREFCNT_dec (sv_self); 165 SvREFCNT_dec (sv_self);
159} 180}
160 181
161///////////////////////////////////////////////////////////////////////////// 182/////////////////////////////////////////////////////////////////////////////
162// DNS 183// DNS
163 184
185#ifndef WIN32
164static void 186static void
165dns_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)
166{ 188{
167 dSP; 189 dSP;
168 SV *cb = (SV *)arg; 190 SV *cb = (SV *)arg;
207 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);
208 } 230 }
209 231
210 LEAVE; 232 LEAVE;
211} 233}
234#endif
212 235
213#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 236#define CHECK_REPEAT(repeat) if (repeat < 0.) \
214 croak (# repeat " value must be >= 0"); 237 croak (# repeat " value must be >= 0");
215 238
216#define CHECK_FD(fh,fd) if ((fd) < 0) \ 239#define CHECK_FD(fh,fd) if ((fd) < 0) \
223 246
224PROTOTYPES: ENABLE 247PROTOTYPES: ENABLE
225 248
226BOOT: 249BOOT:
227{ 250{
228 int i;
229 HV *stash = gv_stashpv ("EV", 1); 251 HV *stash = gv_stashpv ("EV", 1);
230 252
231 static const struct { 253 static const struct {
232 const char *name; 254 const char *name;
233 IV iv; 255 IV iv;
251 273
252 const_iv (EV, METHOD_AUTO) 274 const_iv (EV, METHOD_AUTO)
253 const_iv (EV, METHOD_SELECT) 275 const_iv (EV, METHOD_SELECT)
254 const_iv (EV, METHOD_POLL) 276 const_iv (EV, METHOD_POLL)
255 const_iv (EV, METHOD_EPOLL) 277 const_iv (EV, METHOD_EPOLL)
278 const_iv (EV, METHOD_KQUEUE)
279 const_iv (EV, METHOD_DEVPOLL)
280 const_iv (EV, METHOD_PORT)
256 const_iv (EV, METHOD_ANY) 281 const_iv (EV, METHOD_ANY)
257 }; 282 };
258 283
259 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 284 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
260 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 285 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
276 /* the poor man's shared library emulator */ 301 /* the poor man's shared library emulator */
277 evapi.ver = EV_API_VERSION; 302 evapi.ver = EV_API_VERSION;
278 evapi.rev = EV_API_REVISION; 303 evapi.rev = EV_API_REVISION;
279 evapi.sv_fileno = sv_fileno; 304 evapi.sv_fileno = sv_fileno;
280 evapi.sv_signum = sv_signum; 305 evapi.sv_signum = sv_signum;
281 evapi.now = &ev_now; 306 evapi.now = ev_now;
282 evapi.method = &ev_method; 307 evapi.method = ev_method;
283 evapi.loop_done = &ev_loop_done; 308 evapi.unloop = ev_unloop;
284 evapi.time = ev_time; 309 evapi.time = ev_time;
285 evapi.loop = ev_loop; 310 evapi.loop = ev_loop;
286 evapi.once = ev_once; 311 evapi.once = ev_once;
287 evapi.io_start = ev_io_start; 312 evapi.io_start = ev_io_start;
288 evapi.io_stop = ev_io_stop; 313 evapi.io_stop = ev_io_stop;
303 evapi.child_stop = ev_child_stop; 328 evapi.child_stop = ev_child_stop;
304 329
305 sv_setiv (sv, (IV)&evapi); 330 sv_setiv (sv, (IV)&evapi);
306 SvREADONLY_on (sv); 331 SvREADONLY_on (sv);
307 } 332 }
308 333#ifndef WIN32
309 pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child); 334 pthread_atfork (0, 0, ev_default_fork);
335#endif
310} 336}
311 337
312NV ev_now () 338NV ev_now ()
313 CODE:
314 RETVAL = ev_now;
315 OUTPUT:
316 RETVAL
317 339
318int ev_method () 340int ev_method ()
319 CODE:
320 RETVAL = ev_method;
321 OUTPUT:
322 RETVAL
323 341
324NV ev_time () 342NV ev_time ()
325 343
326void ev_init (int methods = EVMETHOD_AUTO) 344int ev_default_loop (int methods = EVMETHOD_AUTO)
327 345
328void ev_loop (int flags = 0) 346void ev_loop (int flags = 0)
329 347
330void ev_loop_done (int value = 1) 348void ev_unloop (int how = 1)
331 CODE:
332 ev_loop_done = value;
333 349
334struct ev_io *io (SV *fh, int events, SV *cb) 350struct ev_io *io (SV *fh, int events, SV *cb)
335 ALIAS: 351 ALIAS:
336 io_ns = 1 352 io_ns = 1
337 CODE: 353 CODE:
413 429
414struct ev_child *child (int pid, SV *cb) 430struct ev_child *child (int pid, SV *cb)
415 ALIAS: 431 ALIAS:
416 check_ns = 1 432 check_ns = 1
417 CODE: 433 CODE:
418 RETVAL = e_new (sizeof (struct ev_check), cb); 434 RETVAL = e_new (sizeof (struct ev_child), cb);
419 ev_child_set (RETVAL, pid); 435 ev_child_set (RETVAL, pid);
420 if (!ix) ev_child_start (RETVAL); 436 if (!ix) ev_child_start (RETVAL);
421 OUTPUT: 437 OUTPUT:
422 RETVAL 438 RETVAL
423 439
580 } 596 }
581} 597}
582 OUTPUT: 598 OUTPUT:
583 RETVAL 599 RETVAL
584 600
585MODULE = EV PACKAGE = EV::Time
586
587MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 601MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
588 602
589void ev_timer_start (struct ev_timer *w) 603void ev_timer_start (struct ev_timer *w)
590 INIT: 604 INIT:
591 CHECK_REPEAT (w->repeat); 605 CHECK_REPEAT (w->repeat);
710} 724}
711 OUTPUT: 725 OUTPUT:
712 RETVAL 726 RETVAL
713 727
714 728
715int status (struct ev_child *w) 729int rstatus (struct ev_child *w)
730 ALIAS:
731 rpid = 1
716 CODE: 732 CODE:
717 RETVAL = w->status; 733 RETVAL = ix ? w->rpid : w->rstatus;
718 OUTPUT: 734 OUTPUT:
719 RETVAL 735 RETVAL
736
737#ifndef WIN32
720 738
721MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 739MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
722 740
723BOOT: 741BOOT:
724{ 742{
849 867
850#void DESTROY (struct evhttp_request *req); 868#void DESTROY (struct evhttp_request *req);
851 869
852#endif 870#endif
853 871
872#endif
854 873
855 874
856 875
857 876
858 877

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines