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

Comparing EV/EV.xs (file contents):
Revision 1.61 by root, Thu Nov 8 17:24:00 2007 UTC vs.
Revision 1.76 by root, Fri Nov 23 13:08:56 2007 UTC

9 9
10/* fix perl api breakage */ 10/* fix perl api breakage */
11#undef signal 11#undef signal
12#undef sigaction 12#undef sigaction
13 13
14#define EV_SELECT_USE_WIN32_HANDLES 0 14#define EV_SELECT_IS_WINSOCKET 0
15#ifdef _WIN32
15#define EV_SELECT_USE_FD_SET 0 16# define EV_SELECT_USE_FD_SET 0
17# define NFDBITS PERL_NFDBITS
18# define fd_mask Perl_fd_mask
19#endif
16/* due to bugs in OS X we have to use libev/ explicitly here */ 20/* due to bugs in OS X we have to use libev/ explicitly here */
17#include "libev/ev.c" 21#include "libev/ev.c"
18#include "event.c" 22#include "event.c"
19 23
20#ifndef WIN32 24#ifndef _WIN32
21#define DNS_USE_GETTIMEOFDAY_FOR_ID 1 25#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
22#if !defined (WIN32) && !defined(__CYGWIN__) 26#if !defined (WIN32) && !defined(__CYGWIN__)
23# define HAVE_STRUCT_IN6_ADDR 1 27# define HAVE_STRUCT_IN6_ADDR 1
24#endif 28#endif
25#undef HAVE_STRTOK_R 29#undef HAVE_STRTOK_R
26#undef strtok_r 30#undef strtok_r
27#define strtok_r fake_strtok_r 31#define strtok_r fake_strtok_r
32#include "evdns.h"
28#include "evdns.c" 33#include "evdns.c"
29#endif 34#endif
30 35
31#ifndef WIN32 36#ifndef _WIN32
32# include <pthread.h> 37# include <pthread.h>
33#endif 38#endif
34 39
35typedef int Signal; 40typedef int Signal;
36 41
84 fh = SvRV (fh); 89 fh = SvRV (fh);
85 90
86 if (SvTYPE (fh) == SVt_PVGV) 91 if (SvTYPE (fh) == SVt_PVGV)
87 return PerlIO_fileno (IoIFP (sv_2io (fh))); 92 return PerlIO_fileno (IoIFP (sv_2io (fh)));
88 93
89 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff)) 94 if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL))
90 return SvIV (fh); 95 return SvIV (fh);
91 96
92 return -1; 97 return -1;
93} 98}
94 99
100 SvPOK_only (self); 105 SvPOK_only (self);
101 SvCUR_set (self, size); 106 SvCUR_set (self, size);
102 107
103 w = (struct ev_watcher *)SvPVX (self); 108 w = (struct ev_watcher *)SvPVX (self);
104 109
105 ev_watcher_init (w, e_cb); 110 ev_init (w, e_cb);
106 111
107 w->data = 0; 112 w->data = 0;
108 w->fh = 0; 113 w->fh = 0;
109 w->cb_sv = newSVsv (cb_sv); 114 w->cb_sv = newSVsv (cb_sv);
110 w->self = self; 115 w->self = self;
137 } 142 }
138 143
139 return rv; 144 return rv;
140} 145}
141 146
147static SV *sv_events_cache;
148
142static void 149static void
143e_cb (struct ev_watcher *w, int revents) 150e_cb (struct ev_watcher *w, int revents)
144{ 151{
145 dSP; 152 dSP;
146 I32 mark = SP - PL_stack_base; 153 I32 mark = SP - PL_stack_base;
147 SV *sv_self, *sv_events, *sv_status = 0; 154 SV *sv_self, *sv_events;
148 static SV *sv_events_cache;
149 155
150 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 156 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
151 157
152 if (sv_events_cache) 158 if (sv_events_cache)
153 { 159 {
162 PUSHs (sv_self); 168 PUSHs (sv_self);
163 PUSHs (sv_events); 169 PUSHs (sv_events);
164 170
165 PUTBACK; 171 PUTBACK;
166 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 172 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
167 SP = PL_stack_base + mark; PUTBACK;
168 173
169 SvREFCNT_dec (sv_self); 174 SvREFCNT_dec (sv_self);
170 SvREFCNT_dec (sv_status);
171 175
172 if (sv_events_cache) 176 if (sv_events_cache)
173 SvREFCNT_dec (sv_events); 177 SvREFCNT_dec (sv_events);
174 else 178 else
175 sv_events_cache = sv_events; 179 sv_events_cache = sv_events;
177 if (SvTRUE (ERRSV)) 181 if (SvTRUE (ERRSV))
178 { 182 {
179 PUSHMARK (SP); 183 PUSHMARK (SP);
180 PUTBACK; 184 PUTBACK;
181 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 185 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
182 SP = PL_stack_base + mark; PUTBACK;
183 } 186 }
187
188 SP = PL_stack_base + mark;
189 PUTBACK;
190}
191
192static void
193e_once_cb (int revents, void *arg)
194{
195 dSP;
196 I32 mark = SP - PL_stack_base;
197 SV *sv_events;
198
199 if (sv_events_cache)
200 {
201 sv_events = sv_events_cache; sv_events_cache = 0;
202 SvIV_set (sv_events, revents);
203 }
204 else
205 sv_events = newSViv (revents);
206
207 PUSHMARK (SP);
208 XPUSHs (sv_events);
209
210 PUTBACK;
211 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
212
213 SvREFCNT_dec ((SV *)arg);
214
215 if (sv_events_cache)
216 SvREFCNT_dec (sv_events);
217 else
218 sv_events_cache = sv_events;
219
220 if (SvTRUE (ERRSV))
221 {
222 PUSHMARK (SP);
223 PUTBACK;
224 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
225 }
226
227 SP = PL_stack_base + mark;
228 PUTBACK;
184} 229}
185 230
186static ev_tstamp 231static ev_tstamp
187e_periodic_cb (struct ev_periodic *w, ev_tstamp now) 232e_periodic_cb (struct ev_periodic *w, ev_tstamp now)
188{ 233{
227} 272}
228 273
229///////////////////////////////////////////////////////////////////////////// 274/////////////////////////////////////////////////////////////////////////////
230// DNS 275// DNS
231 276
232#ifndef WIN32 277#ifndef _WIN32
233static void 278static void
234dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 279dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
235{ 280{
236 dSP; 281 dSP;
237 SV *cb = (SV *)arg; 282 SV *cb = (SV *)arg;
315 const_iv (EV_, CHECK) 360 const_iv (EV_, CHECK)
316 const_iv (EV_, ERROR) 361 const_iv (EV_, ERROR)
317 362
318 const_iv (EV, LOOP_ONESHOT) 363 const_iv (EV, LOOP_ONESHOT)
319 const_iv (EV, LOOP_NONBLOCK) 364 const_iv (EV, LOOP_NONBLOCK)
365 const_iv (EV, UNLOOP_ONE)
366 const_iv (EV, UNLOOP_ALL)
320 367
321 const_iv (EV, METHOD_AUTO)
322 const_iv (EV, METHOD_SELECT) 368 const_iv (EV, BACKEND_SELECT)
323 const_iv (EV, METHOD_POLL) 369 const_iv (EV, BACKEND_POLL)
324 const_iv (EV, METHOD_EPOLL) 370 const_iv (EV, BACKEND_EPOLL)
325 const_iv (EV, METHOD_KQUEUE) 371 const_iv (EV, BACKEND_KQUEUE)
326 const_iv (EV, METHOD_DEVPOLL) 372 const_iv (EV, BACKEND_DEVPOLL)
327 const_iv (EV, METHOD_PORT) 373 const_iv (EV, BACKEND_PORT)
328 const_iv (EV, METHOD_ANY) 374 const_iv (EV, FLAG_AUTO)
375 const_iv (EV, FLAG_NOENV)
329 }; 376 };
330 377
331 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 378 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
332 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 379 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
333 380
349 evapi.ver = EV_API_VERSION; 396 evapi.ver = EV_API_VERSION;
350 evapi.rev = EV_API_REVISION; 397 evapi.rev = EV_API_REVISION;
351 evapi.sv_fileno = sv_fileno; 398 evapi.sv_fileno = sv_fileno;
352 evapi.sv_signum = sv_signum; 399 evapi.sv_signum = sv_signum;
353 evapi.now = ev_now; 400 evapi.now = ev_now;
354 evapi.method = ev_method; 401 evapi.backend = ev_backend;
355 evapi.unloop = ev_unloop; 402 evapi.unloop = ev_unloop;
356 evapi.time = ev_time; 403 evapi.time = ev_time;
357 evapi.loop = ev_loop; 404 evapi.loop = ev_loop;
358 evapi.once = ev_once; 405 evapi.once = ev_once;
359 evapi.io_start = ev_io_start; 406 evapi.io_start = ev_io_start;
375 evapi.child_stop = ev_child_stop; 422 evapi.child_stop = ev_child_stop;
376 423
377 sv_setiv (sv, (IV)&evapi); 424 sv_setiv (sv, (IV)&evapi);
378 SvREADONLY_on (sv); 425 SvREADONLY_on (sv);
379 } 426 }
380#ifndef WIN32 427#ifndef _WIN32
381 pthread_atfork (0, 0, ev_default_fork); 428 pthread_atfork (0, 0, ev_default_fork);
382#endif 429#endif
383} 430}
384 431
385NV ev_now () 432NV ev_now ()
386 433
387int ev_method () 434unsigned int ev_backend ()
388 435
389NV ev_time () 436NV ev_time ()
390 437
391int ev_default_loop (int methods = EVMETHOD_AUTO) 438unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
392 439
393void ev_loop (int flags = 0) 440void ev_loop (int flags = 0)
394 441
395void ev_unloop (int how = 1) 442void ev_unloop (int how = 1)
396 443
479 OUTPUT: 526 OUTPUT:
480 RETVAL 527 RETVAL
481 528
482struct ev_child *child (int pid, SV *cb) 529struct ev_child *child (int pid, SV *cb)
483 ALIAS: 530 ALIAS:
484 check_ns = 1 531 child_ns = 1
485 CODE: 532 CODE:
486 RETVAL = e_new (sizeof (struct ev_child), cb); 533 RETVAL = e_new (sizeof (struct ev_child), cb);
487 ev_child_set (RETVAL, pid); 534 ev_child_set (RETVAL, pid);
488 if (!ix) ev_child_start (RETVAL); 535 if (!ix) ev_child_start (RETVAL);
489 OUTPUT: 536 OUTPUT:
490 RETVAL 537 RETVAL
491 538
539void once (SV *fh, int events, SV *timeout, SV *cb)
540 CODE:
541 ev_once (
542 sv_fileno (fh), events,
543 SvOK (timeout) ? SvNV (timeout) : -1.,
544 e_once_cb,
545 newSVsv (cb)
546 );
492 547
493PROTOTYPES: DISABLE 548PROTOTYPES: DISABLE
494 549
495MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 550MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
496 551
796 CODE: 851 CODE:
797 RETVAL = ix ? w->rpid : w->rstatus; 852 RETVAL = ix ? w->rpid : w->rstatus;
798 OUTPUT: 853 OUTPUT:
799 RETVAL 854 RETVAL
800 855
801#ifndef WIN32 856#ifndef _WIN32
802 857
803MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 858MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
804 859
805BOOT: 860BOOT:
806{ 861{
877 932
878int evdns_set_option (char *option, char *val, int flags) 933int evdns_set_option (char *option, char *val, int flags)
879 934
880int evdns_resolv_conf_parse (int flags, const char *filename) 935int evdns_resolv_conf_parse (int flags, const char *filename)
881 936
882#ifdef MS_WINDOWS 937#ifdef _WIN32
883 938
884int evdns_config_windows_nameservers () 939int evdns_config_windows_nameservers ()
885 940
886#endif 941#endif
887 942

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines