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

Comparing EV/EV.xs (file contents):
Revision 1.103 by root, Wed Dec 26 14:55:22 2007 UTC vs.
Revision 1.126 by root, Tue Jul 14 00:09:59 2009 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/* fix perl api breakage */
6#undef signal
7#undef sigaction
8
9#include "schmorp.h"
6 10
7#define EV_PROTOTYPES 1 11#define EV_PROTOTYPES 1
8#define EV_USE_NANOSLEEP EV_USE_MONOTONIC 12#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
9#define EV_H <ev.h> 13#define EV_H <ev.h>
10#include "EV/EVAPI.h" 14#include "EV/EVAPI.h"
11
12/* fix perl api breakage */
13#undef signal
14#undef sigaction
15 15
16#define EV_SELECT_IS_WINSOCKET 0 16#define EV_SELECT_IS_WINSOCKET 0
17#ifdef _WIN32 17#ifdef _WIN32
18# define EV_SELECT_USE_FD_SET 0 18# define EV_SELECT_USE_FD_SET 0
19# define NFDBITS PERL_NFDBITS 19# define NFDBITS PERL_NFDBITS
27#endif 27#endif
28 28
29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
30 30
31#define WFLAG_KEEPALIVE 1 31#define WFLAG_KEEPALIVE 1
32#define WFLAG_UNREFED 2 /* has been unref'ed */
32 33
33#define UNREF(w) \ 34#define UNREF(w) \
34 if (!((w)->flags & WFLAG_KEEPALIVE) \ 35 if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
35 && !ev_is_active (w)) \ 36 && ev_is_active (w)) \
37 { \
36 ev_unref (e_loop (w)); 38 ev_unref (e_loop (w)); \
39 (w)->e_flags |= WFLAG_UNREFED; \
40 }
37 41
38#define REF(w) \ 42#define REF(w) \
39 if (!((w)->flags & WFLAG_KEEPALIVE) \ 43 if ((w)->e_flags & WFLAG_UNREFED) \
40 && ev_is_active (w)) \ 44 { \
45 (w)->e_flags &= ~WFLAG_UNREFED; \
41 ev_ref (e_loop (w)); 46 ev_ref (e_loop (w)); \
47 }
42 48
43#define START(type,w) \ 49#define START(type,w) \
44 do { \ 50 do { \
51 ev_ ## type ## _start (e_loop (w), w); \
45 UNREF (w); \ 52 UNREF (w); \
46 ev_ ## type ## _start (e_loop (w), w); \
47 } while (0) 53 } while (0)
48 54
49#define STOP(type,w) \ 55#define STOP(type,w) \
50 do { \ 56 do { \
51 REF (w); \ 57 REF (w); \
77 *stash_stat, 83 *stash_stat,
78 *stash_idle, 84 *stash_idle,
79 *stash_prepare, 85 *stash_prepare,
80 *stash_check, 86 *stash_check,
81 *stash_embed, 87 *stash_embed,
82 *stash_fork; 88 *stash_fork,
83 89 *stash_async;
84#ifndef SIG_SIZE
85/* kudos to Slaven Rezic for the idea */
86static char sig_size [] = { SIG_NUM };
87# define SIG_SIZE (sizeof (sig_size) + 1)
88#endif
89
90static Signal
91sv_signum (SV *sig)
92{
93 Signal signum;
94
95 SvGETMAGIC (sig);
96
97 for (signum = 1; signum < SIG_SIZE; ++signum)
98 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
99 return signum;
100
101 signum = SvIV (sig);
102
103 if (signum > 0 && signum < SIG_SIZE)
104 return signum;
105
106 return -1;
107}
108 90
109///////////////////////////////////////////////////////////////////////////// 91/////////////////////////////////////////////////////////////////////////////
110// Event 92// Event
111 93
112static void e_cb (EV_P_ ev_watcher *w, int revents); 94static void e_cb (EV_P_ ev_watcher *w, int revents);
113 95
114static int
115sv_fileno (SV *fh)
116{
117 SvGETMAGIC (fh);
118
119 if (SvROK (fh))
120 fh = SvRV (fh);
121
122 if (SvTYPE (fh) == SVt_PVGV)
123 return PerlIO_fileno (IoIFP (sv_2io (fh)));
124
125 if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL))
126 return SvIV (fh);
127
128 return -1;
129}
130
131static void * 96static void *
132e_new (int size, SV *cb_sv, SV *loop) 97e_new (int size, SV *cb_sv, SV *loop)
133{ 98{
99 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0;
134 ev_watcher *w; 100 ev_watcher *w;
135 SV *self = NEWSV (0, size); 101 SV *self = NEWSV (0, size);
136 SvPOK_only (self); 102 SvPOK_only (self);
137 SvCUR_set (self, size); 103 SvCUR_set (self, size);
138 104
139 w = (ev_watcher *)SvPVX (self); 105 w = (ev_watcher *)SvPVX (self);
140 106
141 ev_init (w, e_cb); 107 ev_init (w, cv ? e_cb : 0);
142 108
143 w->loop = SvREFCNT_inc (SvRV (loop)); 109 w->loop = SvREFCNT_inc (SvRV (loop));
144 w->flags = WFLAG_KEEPALIVE; 110 w->e_flags = WFLAG_KEEPALIVE;
145 w->data = 0; 111 w->data = 0;
146 w->fh = 0; 112 w->fh = 0;
147 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); 113 w->cb_sv = SvREFCNT_inc (cv);
148 w->self = self; 114 w->self = self;
149 115
150 return (void *)w; 116 return (void *)w;
151} 117}
152 118
153static void 119static void
176 } 142 }
177 143
178 return rv; 144 return rv;
179} 145}
180 146
181static SV *sv_events_cache; 147static SV *sv_self_cache, *sv_events_cache;
182 148
183static void 149static void
184e_cb (EV_P_ ev_watcher *w, int revents) 150e_cb (EV_P_ ev_watcher *w, int revents)
185{ 151{
186 dSP; 152 dSP;
187 I32 mark = SP - PL_stack_base; 153 I32 mark = SP - PL_stack_base;
188 SV *sv_self, *sv_events; 154 SV *sv_self, *sv_events;
189 155
156 /* libev might have stopped the watcher */
157 if (expect_false (w->e_flags & WFLAG_UNREFED)
158 && !ev_is_active (w))
159 REF (w);
160
161 if (expect_true (sv_self_cache))
162 {
163 sv_self = sv_self_cache; sv_self_cache = 0;
164 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
165 }
166 else
167 {
190 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 168 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
169 SvREADONLY_on (sv_self);
170 }
171
172 if (expect_true (sv_events_cache))
173 {
174 sv_events = sv_events_cache; sv_events_cache = 0;
175 SvIV_set (sv_events, revents);
176 }
177 else
178 {
179 sv_events = newSViv (revents);
180 SvREADONLY_on (sv_events);
181 }
182
183 PUSHMARK (SP);
184 EXTEND (SP, 2);
185 PUSHs (sv_self);
186 PUSHs (sv_events);
187
188 PUTBACK;
189 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
190
191 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
192 SvREFCNT_dec (sv_self);
193 else
194 {
195 SvREFCNT_dec (SvRV (sv_self));
196 SvRV_set (sv_self, &PL_sv_undef);
197 sv_self_cache = sv_self;
198 }
199
200 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
201 SvREFCNT_dec (sv_events);
202 else
203 sv_events_cache = sv_events;
204
205 if (expect_false (SvTRUE (ERRSV)))
206 {
207 SPAGAIN;
208 PUSHMARK (SP);
209 PUTBACK;
210 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
211 }
212
213 SP = PL_stack_base + mark;
214 PUTBACK;
215}
216
217static void
218e_once_cb (int revents, void *arg)
219{
220 dSP;
221 I32 mark = SP - PL_stack_base;
222 SV *sv_events;
191 223
192 if (sv_events_cache) 224 if (sv_events_cache)
193 { 225 {
194 sv_events = sv_events_cache; sv_events_cache = 0; 226 sv_events = sv_events_cache; sv_events_cache = 0;
195 SvIV_set (sv_events, revents); 227 SvIV_set (sv_events, revents);
196 } 228 }
197 else 229 else
198 sv_events = newSViv (revents); 230 sv_events = newSViv (revents);
199 231
200 PUSHMARK (SP); 232 PUSHMARK (SP);
201 EXTEND (SP, 2);
202 PUSHs (sv_self);
203 PUSHs (sv_events); 233 XPUSHs (sv_events);
204 234
205 PUTBACK; 235 PUTBACK;
206 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 236 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
207 237
208 SvREFCNT_dec (sv_self); 238 SvREFCNT_dec ((SV *)arg);
209 239
210 if (sv_events_cache) 240 if (sv_events_cache)
211 SvREFCNT_dec (sv_events); 241 SvREFCNT_dec (sv_events);
212 else 242 else
213 sv_events_cache = sv_events; 243 sv_events_cache = sv_events;
222 252
223 SP = PL_stack_base + mark; 253 SP = PL_stack_base + mark;
224 PUTBACK; 254 PUTBACK;
225} 255}
226 256
227static void
228e_once_cb (int revents, void *arg)
229{
230 dSP;
231 I32 mark = SP - PL_stack_base;
232 SV *sv_events;
233
234 if (sv_events_cache)
235 {
236 sv_events = sv_events_cache; sv_events_cache = 0;
237 SvIV_set (sv_events, revents);
238 }
239 else
240 sv_events = newSViv (revents);
241
242 PUSHMARK (SP);
243 XPUSHs (sv_events);
244
245 PUTBACK;
246 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
247
248 SvREFCNT_dec ((SV *)arg);
249
250 if (sv_events_cache)
251 SvREFCNT_dec (sv_events);
252 else
253 sv_events_cache = sv_events;
254
255 if (SvTRUE (ERRSV))
256 {
257 SPAGAIN;
258 PUSHMARK (SP);
259 PUTBACK;
260 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
261 }
262
263 SP = PL_stack_base + mark;
264 PUTBACK;
265}
266
267static ev_tstamp 257static ev_tstamp
268e_periodic_cb (ev_periodic *w, ev_tstamp now) 258e_periodic_cb (ev_periodic *w, ev_tstamp now)
269{ 259{
270 ev_tstamp retval; 260 ev_tstamp retval;
271 int count; 261 int count;
335 const_iv (EV_, MINPRI) 325 const_iv (EV_, MINPRI)
336 const_iv (EV_, MAXPRI) 326 const_iv (EV_, MAXPRI)
337 327
338 const_iv (EV_, UNDEF) 328 const_iv (EV_, UNDEF)
339 const_iv (EV_, NONE) 329 const_iv (EV_, NONE)
340 const_iv (EV_, TIMEOUT)
341 const_iv (EV_, READ) 330 const_iv (EV_, READ)
342 const_iv (EV_, WRITE) 331 const_iv (EV_, WRITE)
332 const_iv (EV_, IO)
333 const_iv (EV_, TIMEOUT)
334 const_iv (EV_, TIMER)
335 const_iv (EV_, PERIODIC)
343 const_iv (EV_, SIGNAL) 336 const_iv (EV_, SIGNAL)
337 const_iv (EV_, CHILD)
338 const_iv (EV_, STAT)
344 const_iv (EV_, IDLE) 339 const_iv (EV_, IDLE)
340 const_iv (EV_, PREPARE)
345 const_iv (EV_, CHECK) 341 const_iv (EV_, CHECK)
342 const_iv (EV_, EMBED)
343 const_iv (EV_, FORK)
344 const_iv (EV_, ASYNC)
345 const_iv (EV_, CUSTOM)
346 const_iv (EV_, ERROR) 346 const_iv (EV_, ERROR)
347 347
348 const_iv (EV, LOOP_NONBLOCK)
348 const_iv (EV, LOOP_ONESHOT) 349 const_iv (EV, LOOP_ONESHOT)
350
349 const_iv (EV, LOOP_NONBLOCK) 351 const_iv (EV, UNLOOP_CANCEL)
350 const_iv (EV, UNLOOP_ONE) 352 const_iv (EV, UNLOOP_ONE)
351 const_iv (EV, UNLOOP_ALL) 353 const_iv (EV, UNLOOP_ALL)
352 354
353 const_iv (EV, BACKEND_SELECT) 355 const_iv (EV, BACKEND_SELECT)
354 const_iv (EV, BACKEND_POLL) 356 const_iv (EV, BACKEND_POLL)
357 const_iv (EV, BACKEND_DEVPOLL) 359 const_iv (EV, BACKEND_DEVPOLL)
358 const_iv (EV, BACKEND_PORT) 360 const_iv (EV, BACKEND_PORT)
359 const_iv (EV, FLAG_AUTO) 361 const_iv (EV, FLAG_AUTO)
360 const_iv (EV, FLAG_NOENV) 362 const_iv (EV, FLAG_NOENV)
361 const_iv (EV, FLAG_FORKCHECK) 363 const_iv (EV, FLAG_FORKCHECK)
364
365 const_iv (EV_, VERSION_MAJOR)
366 const_iv (EV_, VERSION_MINOR)
362 }; 367 };
363 368
364 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 369 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
365 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 370 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
366 371
375 stash_check = gv_stashpv ("EV::Check" , 1); 380 stash_check = gv_stashpv ("EV::Check" , 1);
376 stash_child = gv_stashpv ("EV::Child" , 1); 381 stash_child = gv_stashpv ("EV::Child" , 1);
377 stash_embed = gv_stashpv ("EV::Embed" , 1); 382 stash_embed = gv_stashpv ("EV::Embed" , 1);
378 stash_stat = gv_stashpv ("EV::Stat" , 1); 383 stash_stat = gv_stashpv ("EV::Stat" , 1);
379 stash_fork = gv_stashpv ("EV::Fork" , 1); 384 stash_fork = gv_stashpv ("EV::Fork" , 1);
385 stash_async = gv_stashpv ("EV::Async" , 1);
380 386
381 { 387 {
382 SV *sv = perl_get_sv ("EV::API", TRUE); 388 SV *sv = perl_get_sv ("EV::API", TRUE);
383 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 389 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
384 390
385 /* the poor man's shared library emulator */ 391 /* the poor man's shared library emulator */
386 evapi.ver = EV_API_VERSION; 392 evapi.ver = EV_API_VERSION;
387 evapi.rev = EV_API_REVISION; 393 evapi.rev = EV_API_REVISION;
388 evapi.sv_fileno = sv_fileno; 394 evapi.sv_fileno = s_fileno;
389 evapi.sv_signum = sv_signum; 395 evapi.sv_signum = s_signum;
390 evapi.supported_backends = ev_supported_backends (); 396 evapi.supported_backends = ev_supported_backends ();
391 evapi.recommended_backends = ev_recommended_backends (); 397 evapi.recommended_backends = ev_recommended_backends ();
392 evapi.embeddable_backends = ev_embeddable_backends (); 398 evapi.embeddable_backends = ev_embeddable_backends ();
393 evapi.time = ev_time; 399 evapi.time_ = ev_time;
394 evapi.sleep = ev_sleep; 400 evapi.sleep_ = ev_sleep;
395 evapi.loop_new = ev_loop_new; 401 evapi.loop_new = ev_loop_new;
396 evapi.loop_destroy = ev_loop_destroy; 402 evapi.loop_destroy = ev_loop_destroy;
397 evapi.loop_fork = ev_loop_fork; 403 evapi.loop_fork = ev_loop_fork;
398 evapi.loop_count = ev_loop_count; 404 evapi.loop_count = ev_loop_count;
405 evapi.loop_depth = ev_loop_depth;
406 evapi.set_userdata = ev_set_userdata;
407 evapi.userdata = ev_userdata;
399 evapi.now = ev_now; 408 evapi.now = ev_now;
409 evapi.now_update = ev_now_update;
410 evapi.suspend = ev_suspend;
411 evapi.resume = ev_resume;
400 evapi.backend = ev_backend; 412 evapi.backend = ev_backend;
401 evapi.unloop = ev_unloop; 413 evapi.unloop = ev_unloop;
414 evapi.invoke_pending = ev_invoke_pending;
415 evapi.set_loop_release_cb = ev_set_loop_release_cb;
416 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
402 evapi.ref = ev_ref; 417 evapi.ref = ev_ref;
403 evapi.unref = ev_unref; 418 evapi.unref = ev_unref;
404 evapi.loop = ev_loop; 419 evapi.loop = ev_loop;
405 evapi.once = ev_once; 420 evapi.once = ev_once;
406 evapi.io_start = ev_io_start; 421 evapi.io_start = ev_io_start;
426 evapi.embed_start = ev_embed_start; 441 evapi.embed_start = ev_embed_start;
427 evapi.embed_stop = ev_embed_stop; 442 evapi.embed_stop = ev_embed_stop;
428 evapi.embed_sweep = ev_embed_sweep; 443 evapi.embed_sweep = ev_embed_sweep;
429 evapi.fork_start = ev_fork_start; 444 evapi.fork_start = ev_fork_start;
430 evapi.fork_stop = ev_fork_stop; 445 evapi.fork_stop = ev_fork_stop;
446 evapi.async_start = ev_async_start;
447 evapi.async_stop = ev_async_stop;
448 evapi.async_send = ev_async_send;
431 evapi.clear_pending = ev_clear_pending; 449 evapi.clear_pending = ev_clear_pending;
432 evapi.invoke = ev_invoke; 450 evapi.invoke = ev_invoke;
433 451
434 sv_setiv (sv, (IV)&evapi); 452 sv_setiv (sv, (IV)&evapi);
435 SvREADONLY_on (sv); 453 SvREADONLY_on (sv);
467 485
468unsigned int ev_recommended_backends () 486unsigned int ev_recommended_backends ()
469 487
470unsigned int ev_embeddable_backends () 488unsigned int ev_embeddable_backends ()
471 489
490void ev_sleep (NV interval)
491
472NV ev_time () 492NV ev_time ()
473 493
474NV ev_now () 494NV ev_now ()
475 C_ARGS: evapi.default_loop 495 C_ARGS: evapi.default_loop
476 496
497void ev_now_update ()
498 C_ARGS: evapi.default_loop
499
500void ev_suspend ()
501 C_ARGS: evapi.default_loop
502
503void ev_resume ()
504 C_ARGS: evapi.default_loop
505
477unsigned int ev_backend () 506unsigned int ev_backend ()
478 C_ARGS: evapi.default_loop 507 C_ARGS: evapi.default_loop
479 508
509void ev_loop_verify ()
510 C_ARGS: evapi.default_loop
511
480unsigned int ev_loop_count () 512unsigned int ev_loop_count ()
481 C_ARGS: evapi.default_loop 513 C_ARGS: evapi.default_loop
482 514
515unsigned int ev_loop_depth ()
516 C_ARGS: evapi.default_loop
517
483void ev_set_io_collect_interval (NV interval) 518void ev_set_io_collect_interval (NV interval)
484 C_ARGS: evapi.default_loop, interval 519 C_ARGS: evapi.default_loop, interval
485 520
486void ev_set_timeout_collect_interval (NV interval) 521void ev_set_timeout_collect_interval (NV interval)
487 C_ARGS: evapi.default_loop, interval 522 C_ARGS: evapi.default_loop, interval
488 523
489void ev_loop (int flags = 0) 524void ev_loop (int flags = 0)
490 C_ARGS: evapi.default_loop, flags 525 C_ARGS: evapi.default_loop, flags
491 526
492void ev_unloop (int how = 1) 527void ev_unloop (int how = EVUNLOOP_ONE)
493 C_ARGS: evapi.default_loop, how 528 C_ARGS: evapi.default_loop, how
494 529
495void ev_feed_fd_event (int fd, int revents = EV_NONE) 530void ev_feed_fd_event (int fd, int revents = EV_NONE)
496 C_ARGS: evapi.default_loop, fd, revents 531 C_ARGS: evapi.default_loop, fd, revents
497 532
498void ev_feed_signal_event (SV *signal) 533void ev_feed_signal_event (SV *signal)
499 CODE: 534 CODE:
500{ 535{
501 Signal signum = sv_signum (signal); 536 Signal signum = s_signum (signal);
502 CHECK_SIG (signal, signum); 537 CHECK_SIG (signal, signum);
503 538
504 ev_feed_signal_event (evapi.default_loop, signum); 539 ev_feed_signal_event (evapi.default_loop, signum);
505} 540}
506 541
507ev_io *io (SV *fh, int events, SV *cb) 542ev_io *io (SV *fh, int events, SV *cb)
508 ALIAS: 543 ALIAS:
509 io_ns = 1 544 io_ns = 1
510 CODE: 545 CODE:
511{ 546{
512 int fd = sv_fileno (fh); 547 int fd = s_fileno (fh, events & EV_WRITE);
513 CHECK_FD (fh, fd); 548 CHECK_FD (fh, fd);
514 549
515 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); 550 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
516 RETVAL->fh = newSVsv (fh); 551 RETVAL->fh = newSVsv (fh);
517 ev_io_set (RETVAL, fd, events); 552 ev_io_set (RETVAL, fd, events);
552ev_signal *signal (SV *signal, SV *cb) 587ev_signal *signal (SV *signal, SV *cb)
553 ALIAS: 588 ALIAS:
554 signal_ns = 1 589 signal_ns = 1
555 CODE: 590 CODE:
556{ 591{
557 Signal signum = sv_signum (signal); 592 Signal signum = s_signum (signal);
558 CHECK_SIG (signal, signum); 593 CHECK_SIG (signal, signum);
559 594
560 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); 595 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
561 ev_signal_set (RETVAL, signum); 596 ev_signal_set (RETVAL, signum);
562 if (!ix) START (signal, RETVAL); 597 if (!ix) START (signal, RETVAL);
602 ev_fork_set (RETVAL); 637 ev_fork_set (RETVAL);
603 if (!ix) START (fork, RETVAL); 638 if (!ix) START (fork, RETVAL);
604 OUTPUT: 639 OUTPUT:
605 RETVAL 640 RETVAL
606 641
607ev_child *child (int pid, SV *cb) 642ev_child *child (int pid, int trace, SV *cb)
608 ALIAS: 643 ALIAS:
609 child_ns = 1 644 child_ns = 1
610 CODE: 645 CODE:
611 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 646 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
612 ev_child_set (RETVAL, pid); 647 ev_child_set (RETVAL, pid, trace);
613 if (!ix) START (child, RETVAL); 648 if (!ix) START (child, RETVAL);
614 OUTPUT: 649 OUTPUT:
615 RETVAL 650 RETVAL
616 651
617ev_stat *stat (SV *path, NV interval, SV *cb) 652ev_stat *stat (SV *path, NV interval, SV *cb)
623 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 658 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
624 if (!ix) START (stat, RETVAL); 659 if (!ix) START (stat, RETVAL);
625 OUTPUT: 660 OUTPUT:
626 RETVAL 661 RETVAL
627 662
628ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef) 663ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
629 ALIAS: 664 ALIAS:
630 embed_ns = 1 665 embed_ns = 1
631 CODE: 666 CODE:
632{ 667{
633 if (!(ev_backend (loop) & ev_embeddable_backends ())) 668 if (!(ev_backend (loop) & ev_embeddable_backends ()))
634 croak ("passed loop is not embeddable via EV::embed,"); 669 croak ("passed loop is not embeddable via EV::embed,");
635 670
636 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); 671 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
637 RETVAL->fh = newSVsv (ST (0)); 672 RETVAL->fh = newSVsv (ST (0));
638 ev_embed_set (RETVAL, loop); 673 ev_embed_set (RETVAL, loop);
639
640 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
641
642 if (!ix) START (embed, RETVAL); 674 if (!ix) START (embed, RETVAL);
643} 675}
676 OUTPUT:
677 RETVAL
678
679ev_async *async (SV *cb)
680 ALIAS:
681 async_ns = 1
682 CODE:
683 RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
684 ev_async_set (RETVAL);
685 if (!ix) START (async, RETVAL);
644 OUTPUT: 686 OUTPUT:
645 RETVAL 687 RETVAL
646 688
647void once (SV *fh, int events, SV *timeout, SV *cb) 689void once (SV *fh, int events, SV *timeout, SV *cb)
648 CODE: 690 CODE:
649 ev_once ( 691 ev_once (
650 evapi.default_loop, 692 evapi.default_loop,
651 sv_fileno (fh), events, 693 s_fileno (fh, events & EV_WRITE), events,
652 SvOK (timeout) ? SvNV (timeout) : -1., 694 SvOK (timeout) ? SvNV (timeout) : -1.,
653 e_once_cb, 695 e_once_cb,
654 newSVsv (cb) 696 newSVsv (cb)
655 ); 697 );
656 698
672 C_ARGS: e_loop (w), w, revents 714 C_ARGS: e_loop (w), w, revents
673 715
674int keepalive (ev_watcher *w, int new_value = 0) 716int keepalive (ev_watcher *w, int new_value = 0)
675 CODE: 717 CODE:
676{ 718{
677 RETVAL = w->flags & WFLAG_KEEPALIVE; 719 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
678 new_value = new_value ? WFLAG_KEEPALIVE : 0; 720 new_value = new_value ? WFLAG_KEEPALIVE : 0;
679 721
680 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 722 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
681 { 723 {
724 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
682 REF (w); 725 REF (w);
683 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value;
684 UNREF (w); 726 UNREF (w);
685 } 727 }
686} 728}
687 OUTPUT: 729 OUTPUT:
688 RETVAL 730 RETVAL
689 731
690SV *cb (ev_watcher *w, SV *new_cb = 0) 732SV *cb (ev_watcher *w, SV *new_cb = 0)
691 CODE: 733 CODE:
692{ 734{
693 RETVAL = newSVsv (w->cb_sv);
694
695 if (items > 1) 735 if (items > 1)
696 sv_setsv (w->cb_sv, new_cb); 736 {
737 new_cb = s_get_cv_croak (new_cb);
738 RETVAL = newRV_noinc (w->cb_sv);
739 w->cb_sv = SvREFCNT_inc (new_cb);
740 }
741 else
742 RETVAL = newRV_inc (w->cb_sv);
697} 743}
698 OUTPUT: 744 OUTPUT:
699 RETVAL 745 RETVAL
700 746
701SV *data (ev_watcher *w, SV *new_data = 0) 747SV *data (ev_watcher *w, SV *new_data = 0)
766 e_destroy (w); 812 e_destroy (w);
767 813
768void set (ev_io *w, SV *fh, int events) 814void set (ev_io *w, SV *fh, int events)
769 CODE: 815 CODE:
770{ 816{
771 int fd = sv_fileno (fh); 817 int fd = s_fileno (fh, events & EV_WRITE);
772 CHECK_FD (fh, fd); 818 CHECK_FD (fh, fd);
773 819
774 sv_setsv (w->fh, fh); 820 sv_setsv (w->fh, fh);
775 RESET (io, w, (w, fd, events)); 821 RESET (io, w, (w, fd, events));
776} 822}
778SV *fh (ev_io *w, SV *new_fh = 0) 824SV *fh (ev_io *w, SV *new_fh = 0)
779 CODE: 825 CODE:
780{ 826{
781 if (items > 1) 827 if (items > 1)
782 { 828 {
783 int fd = sv_fileno (new_fh); 829 int fd = s_fileno (new_fh, w->events & EV_WRITE);
784 CHECK_FD (new_fh, fd); 830 CHECK_FD (new_fh, fd);
785 831
786 RETVAL = w->fh; 832 RETVAL = w->fh;
787 w->fh = newSVsv (new_fh); 833 w->fh = newSVsv (new_fh);
788 834
821 e_destroy (w); 867 e_destroy (w);
822 868
823void set (ev_signal *w, SV *signal) 869void set (ev_signal *w, SV *signal)
824 CODE: 870 CODE:
825{ 871{
826 Signal signum = sv_signum (signal); 872 Signal signum = s_signum (signal);
827 CHECK_SIG (signal, signum); 873 CHECK_SIG (signal, signum);
828 874
829 RESET (signal, w, (w, signum)); 875 RESET (signal, w, (w, signum));
830} 876}
831 877
834{ 880{
835 RETVAL = w->signum; 881 RETVAL = w->signum;
836 882
837 if (items > 1) 883 if (items > 1)
838 { 884 {
839 Signal signum = sv_signum (new_signal); 885 Signal signum = s_signum (new_signal);
840 CHECK_SIG (new_signal, signum); 886 CHECK_SIG (new_signal, signum);
841 887
842 RESET (signal, w, (w, signum)); 888 RESET (signal, w, (w, signum));
843 } 889 }
844} 890}
859 905
860void ev_timer_again (ev_timer *w) 906void ev_timer_again (ev_timer *w)
861 INIT: 907 INIT:
862 CHECK_REPEAT (w->repeat); 908 CHECK_REPEAT (w->repeat);
863 CODE: 909 CODE:
864 REF (w);
865 ev_timer_again (e_loop (w), w); 910 ev_timer_again (e_loop (w), w);
866 UNREF (w); 911 UNREF (w);
867 912
868void DESTROY (ev_timer *w) 913void DESTROY (ev_timer *w)
869 CODE: 914 CODE:
874 INIT: 919 INIT:
875 CHECK_REPEAT (repeat); 920 CHECK_REPEAT (repeat);
876 CODE: 921 CODE:
877 RESET (timer, w, (w, after, repeat)); 922 RESET (timer, w, (w, after, repeat));
878 923
879NV at (ev_timer *w)
880 CODE:
881 RETVAL = w->at;
882 OUTPUT:
883 RETVAL
884
885MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 924MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
886 925
887void ev_periodic_start (ev_periodic *w) 926void ev_periodic_start (ev_periodic *w)
888 INIT: 927 INIT:
889 CHECK_REPEAT (w->interval); 928 CHECK_REPEAT (w->interval);
894 CODE: 933 CODE:
895 STOP (periodic, w); 934 STOP (periodic, w);
896 935
897void ev_periodic_again (ev_periodic *w) 936void ev_periodic_again (ev_periodic *w)
898 CODE: 937 CODE:
899 REF (w);
900 ev_periodic_again (e_loop (w), w); 938 ev_periodic_again (e_loop (w), w);
901 UNREF (w); 939 UNREF (w);
902 940
903void DESTROY (ev_periodic *w) 941void DESTROY (ev_periodic *w)
904 CODE: 942 CODE:
916 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 954 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
917} 955}
918 956
919NV at (ev_periodic *w) 957NV at (ev_periodic *w)
920 CODE: 958 CODE:
921 RETVAL = w->at; 959 RETVAL = ev_periodic_at (w);
922 OUTPUT: 960 OUTPUT:
923 RETVAL 961 RETVAL
924 962
925MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 963MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
926 964
995void DESTROY (ev_child *w) 1033void DESTROY (ev_child *w)
996 CODE: 1034 CODE:
997 STOP (child, w); 1035 STOP (child, w);
998 e_destroy (w); 1036 e_destroy (w);
999 1037
1000void set (ev_child *w, int pid) 1038void set (ev_child *w, int pid, int trace)
1001 CODE: 1039 CODE:
1002 RESET (child, w, (w, pid)); 1040 RESET (child, w, (w, pid, trace));
1003 1041
1004int pid (ev_child *w, int new_pid = 0)
1005 CODE:
1006{
1007 RETVAL = w->pid;
1008
1009 if (items > 1)
1010 RESET (child, w, (w, new_pid));
1011}
1012 OUTPUT:
1013 RETVAL
1014
1015
1016int rstatus (ev_child *w) 1042int pid (ev_child *w)
1017 ALIAS: 1043 ALIAS:
1018 rpid = 1 1044 rpid = 1
1045 rstatus = 2
1019 CODE: 1046 CODE:
1020 RETVAL = ix ? w->rpid : w->rstatus; 1047 RETVAL = ix == 0 ? w->pid
1048 : ix == 1 ? w->rpid
1049 : w->rstatus;
1021 OUTPUT: 1050 OUTPUT:
1022 RETVAL 1051 RETVAL
1023 1052
1024MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1053MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1025 1054
1141 CODE: 1170 CODE:
1142 RETVAL = newSVsv (w->fh); 1171 RETVAL = newSVsv (w->fh);
1143 OUTPUT: 1172 OUTPUT:
1144 RETVAL 1173 RETVAL
1145 1174
1175void ev_embed_sweep (ev_embed *w)
1176 C_ARGS: e_loop (w), w
1177
1178MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1179
1180void ev_async_start (ev_async *w)
1181 CODE:
1182 START (async, w);
1183
1184void ev_async_stop (ev_async *w)
1185 CODE:
1186 STOP (async, w);
1187
1188void DESTROY (ev_async *w)
1189 CODE:
1190 STOP (async, w);
1191 e_destroy (w);
1192
1193void ev_async_send (ev_async *w)
1194 C_ARGS: e_loop (w), w
1195
1196SV *ev_async_async_pending (ev_async *w)
1197 CODE:
1198 RETVAL = boolSV (ev_async_pending (w));
1199 OUTPUT:
1200 RETVAL
1201
1146MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1202MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1147 1203
1148SV *new (SV *klass, unsigned int flags = 0) 1204SV *new (SV *klass, unsigned int flags = 0)
1149 CODE: 1205 CODE:
1150{ 1206{
1163 if (loop != evapi.default_loop) /* global destruction sucks */ 1219 if (loop != evapi.default_loop) /* global destruction sucks */
1164 ev_loop_destroy (loop); 1220 ev_loop_destroy (loop);
1165 1221
1166void ev_loop_fork (struct ev_loop *loop) 1222void ev_loop_fork (struct ev_loop *loop)
1167 1223
1224void ev_loop_verify (struct ev_loop *loop)
1225
1168NV ev_now (struct ev_loop *loop) 1226NV ev_now (struct ev_loop *loop)
1169 1227
1228void ev_now_update (struct ev_loop *loop)
1229
1230void ev_suspend (struct ev_loop *loop)
1231
1232void ev_resume (struct ev_loop *loop)
1233
1170void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) 1234void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1171 1235
1172void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) 1236void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1173 1237
1174unsigned int ev_backend (struct ev_loop *loop) 1238unsigned int ev_backend (struct ev_loop *loop)
1175 1239
1176unsigned int ev_loop_count (struct ev_loop *loop) 1240unsigned int ev_loop_count (struct ev_loop *loop)
1177 1241
1242unsigned int ev_loop_depth (struct ev_loop *loop)
1243
1178void ev_loop (struct ev_loop *loop, int flags = 0) 1244void ev_loop (struct ev_loop *loop, int flags = 0)
1179 1245
1180void ev_unloop (struct ev_loop *loop, int how = 1) 1246void ev_unloop (struct ev_loop *loop, int how = 1)
1181 1247
1182void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) 1248void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1184#if 0 1250#if 0
1185 1251
1186void ev_feed_signal_event (struct ev_loop *loop, SV *signal) 1252void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1187 CODE: 1253 CODE:
1188{ 1254{
1189 Signal signum = sv_signum (signal); 1255 Signal signum = s_signum (signal);
1190 CHECK_SIG (signal, signum); 1256 CHECK_SIG (signal, signum);
1191 1257
1192 ev_feed_signal_event (loop, signum); 1258 ev_feed_signal_event (loop, signum);
1193} 1259}
1194 1260
1197ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) 1263ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1198 ALIAS: 1264 ALIAS:
1199 io_ns = 1 1265 io_ns = 1
1200 CODE: 1266 CODE:
1201{ 1267{
1202 int fd = sv_fileno (fh); 1268 int fd = s_fileno (fh, events & EV_WRITE);
1203 CHECK_FD (fh, fd); 1269 CHECK_FD (fh, fd);
1204 1270
1205 RETVAL = e_new (sizeof (ev_io), cb, ST (0)); 1271 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1206 RETVAL->fh = newSVsv (fh); 1272 RETVAL->fh = newSVsv (fh);
1207 ev_io_set (RETVAL, fd, events); 1273 ev_io_set (RETVAL, fd, events);
1244ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) 1310ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1245 ALIAS: 1311 ALIAS:
1246 signal_ns = 1 1312 signal_ns = 1
1247 CODE: 1313 CODE:
1248{ 1314{
1249 Signal signum = sv_signum (signal); 1315 Signal signum = s_signum (signal);
1250 CHECK_SIG (signal, signum); 1316 CHECK_SIG (signal, signum);
1251 1317
1252 RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); 1318 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1253 ev_signal_set (RETVAL, signum); 1319 ev_signal_set (RETVAL, signum);
1254 if (!ix) START (signal, RETVAL); 1320 if (!ix) START (signal, RETVAL);
1296 ev_fork_set (RETVAL); 1362 ev_fork_set (RETVAL);
1297 if (!ix) START (fork, RETVAL); 1363 if (!ix) START (fork, RETVAL);
1298 OUTPUT: 1364 OUTPUT:
1299 RETVAL 1365 RETVAL
1300 1366
1301ev_child *child (struct ev_loop *loop, int pid, SV *cb) 1367ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1302 ALIAS: 1368 ALIAS:
1303 child_ns = 1 1369 child_ns = 1
1304 CODE: 1370 CODE:
1305 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1371 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1306 ev_child_set (RETVAL, pid); 1372 ev_child_set (RETVAL, pid, trace);
1307 if (!ix) START (child, RETVAL); 1373 if (!ix) START (child, RETVAL);
1308 OUTPUT: 1374 OUTPUT:
1309 RETVAL 1375 RETVAL
1310 1376
1311ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1377ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1317 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 1383 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1318 if (!ix) START (stat, RETVAL); 1384 if (!ix) START (stat, RETVAL);
1319 OUTPUT: 1385 OUTPUT:
1320 RETVAL 1386 RETVAL
1321 1387
1322ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef) 1388ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1323 ALIAS: 1389 ALIAS:
1324 embed_ns = 1 1390 embed_ns = 1
1325 CODE: 1391 CODE:
1326{ 1392{
1327 if (!(ev_backend (other) & ev_embeddable_backends ())) 1393 if (!(ev_backend (other) & ev_embeddable_backends ()))
1328 croak ("passed loop is not embeddable via EV::embed,"); 1394 croak ("passed loop is not embeddable via EV::embed,");
1329 1395
1330 RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); 1396 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1331 RETVAL->fh = newSVsv (ST (1)); 1397 RETVAL->fh = newSVsv (ST (1));
1332 ev_embed_set (RETVAL, other); 1398 ev_embed_set (RETVAL, other);
1333
1334 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
1335
1336 if (!ix) START (embed, RETVAL); 1399 if (!ix) START (embed, RETVAL);
1337} 1400}
1401 OUTPUT:
1402 RETVAL
1403
1404ev_async *async (struct ev_loop *loop, SV *cb)
1405 ALIAS:
1406 async_ns = 1
1407 CODE:
1408 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1409 ev_async_set (RETVAL);
1410 if (!ix) START (async, RETVAL);
1338 OUTPUT: 1411 OUTPUT:
1339 RETVAL 1412 RETVAL
1340 1413
1341void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb) 1414void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1342 CODE: 1415 CODE:
1343 ev_once ( 1416 ev_once (
1344 loop, 1417 loop,
1345 sv_fileno (fh), events, 1418 s_fileno (fh, events & EV_WRITE), events,
1346 SvOK (timeout) ? SvNV (timeout) : -1., 1419 SvOK (timeout) ? SvNV (timeout) : -1.,
1347 e_once_cb, 1420 e_once_cb,
1348 newSVsv (cb) 1421 newSVsv (cb)
1349 ); 1422 );
1350 1423

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines