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

Comparing EV/EV.xs (file contents):
Revision 1.162 by root, Tue Jan 15 21:49:38 2013 UTC vs.
Revision 1.164 by root, Fri Apr 5 21:04:18 2013 UTC

12static int 12static int
13sv_fileno (SV *fh) 13sv_fileno (SV *fh)
14{ 14{
15 return s_fileno (fh, 0); 15 return s_fileno (fh, 0);
16} 16}
17
18#ifndef GvCV_set
19# define GvCV_set(gv,cv) GvCV (gv) = cv
20#endif
17 21
18#define EV_STANDALONE 1 22#define EV_STANDALONE 1
19#define EV_PROTOTYPES 1 23#define EV_PROTOTYPES 1
20#define EV_USE_NANOSLEEP EV_USE_MONOTONIC 24#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
21#define EV_USE_FLOOR 1 25#define EV_USE_FLOOR 1
43#define e_fh(w) ((ev_watcher *)(w))->fh 47#define e_fh(w) ((ev_watcher *)(w))->fh
44#define e_data(w) ((ev_watcher *)(w))->data 48#define e_data(w) ((ev_watcher *)(w))->data
45 49
46#define WFLAG_KEEPALIVE 1 50#define WFLAG_KEEPALIVE 1
47#define WFLAG_UNREFED 2 /* has been unref'ed */ 51#define WFLAG_UNREFED 2 /* has been unref'ed */
52#define WFLAG_NOARGS 4 /* do not pass anything to the callback */
48 53
49#define UNREF(w) \ 54#define UNREF(w) \
50 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ 55 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
51 && ev_is_active (w)) \ 56 && ev_is_active (w)) \
52 { \ 57 { \
195 /* libev might have stopped the watcher */ 200 /* libev might have stopped the watcher */
196 if (expect_false (w->e_flags & WFLAG_UNREFED) 201 if (expect_false (w->e_flags & WFLAG_UNREFED)
197 && !ev_is_active (w)) 202 && !ev_is_active (w))
198 REF (w); 203 REF (w);
199 204
200 if (expect_true (sv_self_cache)) 205 PUSHMARK (SP);
206
207 if (!expect_true (e_flags (w) & WFLAG_NOARGS))
201 { 208 {
209 if (expect_true (sv_self_cache))
210 {
202 sv_self = sv_self_cache; sv_self_cache = 0; 211 sv_self = sv_self_cache; sv_self_cache = 0;
203 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); 212 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
213 }
214 else
215 {
216 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */
217 SvREADONLY_on (sv_self);
218 }
219
220 if (expect_true (sv_events_cache))
221 {
222 sv_events = sv_events_cache; sv_events_cache = 0;
223 SvIV_set (sv_events, revents);
224 SvIOK_only (sv_events);
225 }
226 else
227 {
228 sv_events = newSViv (revents);
229 SvREADONLY_on (sv_events);
230 }
231
232 EXTEND (SP, 2);
233 PUSHs (sv_self);
234 PUSHs (sv_events);
235
236 PUTBACK;
237 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
238
239 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
240 SvREFCNT_dec (sv_self);
241 else
242 {
243 SvREFCNT_dec (SvRV (sv_self));
244 SvRV_set (sv_self, &PL_sv_undef);
245 sv_self_cache = sv_self;
246 }
247
248 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
249 SvREFCNT_dec (sv_events);
250 else
251 sv_events_cache = sv_events;
204 } 252 }
205 else 253 else
206 { 254 {
207 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ 255 EXTEND (SP, 2);
208 SvREADONLY_on (sv_self); 256 PUSHs (sv_self);
257 PUSHs (sv_events);
258
259 PUTBACK;
260 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
209 } 261 }
210
211 if (expect_true (sv_events_cache))
212 {
213 sv_events = sv_events_cache; sv_events_cache = 0;
214 SvIV_set (sv_events, revents);
215 SvIOK_only (sv_events);
216 }
217 else
218 {
219 sv_events = newSViv (revents);
220 SvREADONLY_on (sv_events);
221 }
222
223 PUSHMARK (SP);
224 EXTEND (SP, 2);
225 PUSHs (sv_self);
226 PUSHs (sv_events);
227
228 PUTBACK;
229 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
230
231 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
232 SvREFCNT_dec (sv_self);
233 else
234 {
235 SvREFCNT_dec (SvRV (sv_self));
236 SvRV_set (sv_self, &PL_sv_undef);
237 sv_self_cache = sv_self;
238 }
239
240 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
241 SvREFCNT_dec (sv_events);
242 else
243 sv_events_cache = sv_events;
244 262
245 if (expect_false (SvTRUE (ERRSV))) 263 if (expect_false (SvTRUE (ERRSV)))
246 { 264 {
247 SPAGAIN; 265 SPAGAIN;
248 PUSHMARK (SP); 266 PUSHMARK (SP);
381 const_iv (EV_, SIGNAL) 399 const_iv (EV_, SIGNAL)
382 const_iv (EV_, CHILD) 400 const_iv (EV_, CHILD)
383 const_iv (EV_, STAT) 401 const_iv (EV_, STAT)
384 const_iv (EV_, IDLE) 402 const_iv (EV_, IDLE)
385 const_iv (EV_, PREPARE) 403 const_iv (EV_, PREPARE)
386 const_iv (EV_, CHECK) 404 /*const_iv (EV_, CHECK) needs special tretament */
387 const_iv (EV_, EMBED) 405 const_iv (EV_, EMBED)
388 const_iv (EV_, FORK) 406 const_iv (EV_, FORK)
389 const_iv (EV_, CLEANUP) 407 const_iv (EV_, CLEANUP)
390 const_iv (EV_, ASYNC) 408 const_iv (EV_, ASYNC)
391 const_iv (EV_, CUSTOM) 409 const_iv (EV_, CUSTOM)
425#endif 443#endif
426 }; 444 };
427 445
428 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 446 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
429 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 447 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
448
449 /* since this clashes with perl CHECK blocks, */
450 /* but we are interested in constants, */
451 /* and not blocks, we treat CHECK specially. */
452 {
453 /* the local $^W = 0 takes care of the warning */
454 CV *cv = newCONSTSUB (stash, "CHECK", newSViv (EV_CHECK));
455 /* now we need to re-set the gv, in case it was hijacked */
456 GvCV_set (gv_fetchpv ("EV::CHECK", GV_ADD, SVt_PVCV), cv);
457 }
430 458
431 stash_loop = gv_stashpv ("EV::Loop" , 1); 459 stash_loop = gv_stashpv ("EV::Loop" , 1);
432 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 460 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
433 stash_io = gv_stashpv ("EV::IO" , 1); 461 stash_io = gv_stashpv ("EV::IO" , 1);
434 stash_timer = gv_stashpv ("EV::Timer" , 1); 462 stash_timer = gv_stashpv ("EV::Timer" , 1);
642 _ae_io = 2 670 _ae_io = 2
643 CODE: 671 CODE:
644{ 672{
645 int fd = s_fileno (fh, events & EV_WRITE); 673 int fd = s_fileno (fh, events & EV_WRITE);
646 CHECK_FD (fh, fd); 674 CHECK_FD (fh, fd);
675 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
676 e_fh (RETVAL) = newSVsv (fh);
647 677
648 if (ix == 2) 678 if (ix == 2)
649 { 679 {
650 ix = 0;
651 events = events ? EV_WRITE : EV_READ; 680 events = events ? EV_WRITE : EV_READ;
681 e_flags (RETVAL) |= WFLAG_NOARGS;
652 } 682 }
653 683
654 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
655 e_fh (RETVAL) = newSVsv (fh);
656 ev_io_set (RETVAL, fd, events); 684 ev_io_set (RETVAL, fd, events);
657 if (!ix) START (io, RETVAL); 685 if (ix != 1) START (io, RETVAL);
658} 686}
659 OUTPUT: 687 OUTPUT:
660 RETVAL 688 RETVAL
661 689
662ev_timer *timer (NV after, NV repeat, SV *cb) 690ev_timer *timer (NV after, NV repeat, SV *cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines