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

Comparing EV/EV.xs (file contents):
Revision 1.70 by root, Fri Nov 16 10:37:28 2007 UTC vs.
Revision 1.77 by root, Fri Nov 23 16:37:37 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_USE_MONOTONIC 1
15#define EV_USE_REALTIME 1
16#define EV_SELECT_IS_WINSOCKET 0 14#define EV_SELECT_IS_WINSOCKET 0
17#ifdef _WIN32 15#ifdef _WIN32
18# define EV_SELECT_USE_FD_SET 0 16# define EV_SELECT_USE_FD_SET 0
19# define NFDBITS PERL_NFDBITS 17# define NFDBITS PERL_NFDBITS
20# define fd_mask Perl_fd_mask 18# define fd_mask Perl_fd_mask
91 fh = SvRV (fh); 89 fh = SvRV (fh);
92 90
93 if (SvTYPE (fh) == SVt_PVGV) 91 if (SvTYPE (fh) == SVt_PVGV)
94 return PerlIO_fileno (IoIFP (sv_2io (fh))); 92 return PerlIO_fileno (IoIFP (sv_2io (fh)));
95 93
96 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff)) 94 if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL))
97 return SvIV (fh); 95 return SvIV (fh);
98 96
99 return -1; 97 return -1;
100} 98}
101 99
144 } 142 }
145 143
146 return rv; 144 return rv;
147} 145}
148 146
147static SV *sv_events_cache;
148
149static void 149static void
150e_cb (struct ev_watcher *w, int revents) 150e_cb (struct ev_watcher *w, int revents)
151{ 151{
152 dSP; 152 dSP;
153 I32 mark = SP - PL_stack_base; 153 I32 mark = SP - PL_stack_base;
154 SV *sv_self, *sv_events, *sv_status = 0; 154 SV *sv_self, *sv_events;
155 static SV *sv_events_cache;
156 155
157 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 */
158 157
159 if (sv_events_cache) 158 if (sv_events_cache)
160 { 159 {
171 170
172 PUTBACK; 171 PUTBACK;
173 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 172 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
174 173
175 SvREFCNT_dec (sv_self); 174 SvREFCNT_dec (sv_self);
175
176 if (sv_events_cache)
176 SvREFCNT_dec (sv_status); 177 SvREFCNT_dec (sv_events);
178 else
179 sv_events_cache = sv_events;
180
181 if (SvTRUE (ERRSV))
182 {
183 PUSHMARK (SP);
184 PUTBACK;
185 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
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);
177 214
178 if (sv_events_cache) 215 if (sv_events_cache)
179 SvREFCNT_dec (sv_events); 216 SvREFCNT_dec (sv_events);
180 else 217 else
181 sv_events_cache = sv_events; 218 sv_events_cache = sv_events;
326 const_iv (EV, LOOP_ONESHOT) 363 const_iv (EV, LOOP_ONESHOT)
327 const_iv (EV, LOOP_NONBLOCK) 364 const_iv (EV, LOOP_NONBLOCK)
328 const_iv (EV, UNLOOP_ONE) 365 const_iv (EV, UNLOOP_ONE)
329 const_iv (EV, UNLOOP_ALL) 366 const_iv (EV, UNLOOP_ALL)
330 367
331 const_iv (EV, METHOD_SELECT) 368 const_iv (EV, BACKEND_SELECT)
332 const_iv (EV, METHOD_POLL) 369 const_iv (EV, BACKEND_POLL)
333 const_iv (EV, METHOD_EPOLL) 370 const_iv (EV, BACKEND_EPOLL)
334 const_iv (EV, METHOD_KQUEUE) 371 const_iv (EV, BACKEND_KQUEUE)
335 const_iv (EV, METHOD_DEVPOLL) 372 const_iv (EV, BACKEND_DEVPOLL)
336 const_iv (EV, METHOD_PORT) 373 const_iv (EV, BACKEND_PORT)
337 const_iv (EV, FLAG_AUTO) 374 const_iv (EV, FLAG_AUTO)
338 const_iv (EV, FLAG_NOENV) 375 const_iv (EV, FLAG_NOENV)
339 }; 376 };
340 377
341 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; )
359 evapi.ver = EV_API_VERSION; 396 evapi.ver = EV_API_VERSION;
360 evapi.rev = EV_API_REVISION; 397 evapi.rev = EV_API_REVISION;
361 evapi.sv_fileno = sv_fileno; 398 evapi.sv_fileno = sv_fileno;
362 evapi.sv_signum = sv_signum; 399 evapi.sv_signum = sv_signum;
363 evapi.now = ev_now; 400 evapi.now = ev_now;
364 evapi.method = ev_method; 401 evapi.backend = ev_backend;
365 evapi.unloop = ev_unloop; 402 evapi.unloop = ev_unloop;
366 evapi.time = ev_time; 403 evapi.time = ev_time;
367 evapi.loop = ev_loop; 404 evapi.loop = ev_loop;
368 evapi.once = ev_once; 405 evapi.once = ev_once;
369 evapi.io_start = ev_io_start; 406 evapi.io_start = ev_io_start;
381 evapi.prepare_stop = ev_prepare_stop; 418 evapi.prepare_stop = ev_prepare_stop;
382 evapi.check_start = ev_check_start; 419 evapi.check_start = ev_check_start;
383 evapi.check_stop = ev_check_stop; 420 evapi.check_stop = ev_check_stop;
384 evapi.child_start = ev_child_start; 421 evapi.child_start = ev_child_start;
385 evapi.child_stop = ev_child_stop; 422 evapi.child_stop = ev_child_stop;
423 evapi.ref = ev_ref;
424 evapi.unref = ev_unref;
386 425
387 sv_setiv (sv, (IV)&evapi); 426 sv_setiv (sv, (IV)&evapi);
388 SvREADONLY_on (sv); 427 SvREADONLY_on (sv);
389 } 428 }
390#ifndef _WIN32 429#ifndef _WIN32
392#endif 431#endif
393} 432}
394 433
395NV ev_now () 434NV ev_now ()
396 435
397int ev_method () 436unsigned int ev_backend ()
398 437
399NV ev_time () 438NV ev_time ()
400 439
401int ev_default_loop (int methods = EVFLAG_AUTO) 440unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
402 441
403void ev_loop (int flags = 0) 442void ev_loop (int flags = 0)
404 443
405void ev_unloop (int how = 1) 444void ev_unloop (int how = 1)
406 445
497 ev_child_set (RETVAL, pid); 536 ev_child_set (RETVAL, pid);
498 if (!ix) ev_child_start (RETVAL); 537 if (!ix) ev_child_start (RETVAL);
499 OUTPUT: 538 OUTPUT:
500 RETVAL 539 RETVAL
501 540
541void once (SV *fh, int events, SV *timeout, SV *cb)
542 CODE:
543 ev_once (
544 sv_fileno (fh), events,
545 SvOK (timeout) ? SvNV (timeout) : -1.,
546 e_once_cb,
547 newSVsv (cb)
548 );
502 549
503PROTOTYPES: DISABLE 550PROTOTYPES: DISABLE
504 551
505MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 552MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
506 553

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines