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

Comparing EV/EV.xs (file contents):
Revision 1.29 by root, Thu Nov 1 06:48:49 2007 UTC vs.
Revision 1.63 by root, Sat Nov 10 03:19:21 2007 UTC

2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define TIMEOUT_NONE HUGE_VAL
8#define HAVE_EPOLL 1
9
10#define EV_PROTOTYPES 1 7#define EV_PROTOTYPES 1
11#include "EV/EVAPI.h" 8#include "EV/EVAPI.h"
12 9
10/* fix perl api breakage */
11#undef signal
12#undef sigaction
13
14#define EV_SELECT_USE_WIN32_HANDLES 0
15#define EV_SELECT_USE_FD_SET 0
16/* due to bugs in OS X we have to use libev/ explicitly here */
13#include "libev/ev.c" 17#include "libev/ev.c"
18#include "event.c"
19
20#ifndef WIN32
21#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
22#if !defined (WIN32) && !defined(__CYGWIN__)
23# define HAVE_STRUCT_IN6_ADDR 1
24#endif
25#undef HAVE_STRTOK_R
26#undef strtok_r
27#define strtok_r fake_strtok_r
28#include "evdns.h"
29#include "evdns.c"
30#endif
31
32#ifndef WIN32
33# include <pthread.h>
34#endif
14 35
15typedef int Signal; 36typedef int Signal;
16 37
17static struct EVAPI evapi; 38static struct EVAPI evapi;
18 39
19static HV 40static HV
20 *stash_watcher, 41 *stash_watcher,
21 *stash_io, 42 *stash_io,
22 *stash_time,
23 *stash_timer, 43 *stash_timer,
24 *stash_periodic, 44 *stash_periodic,
25 *stash_signal, 45 *stash_signal,
26 *stash_idle, 46 *stash_idle,
27 *stash_prepare, 47 *stash_prepare,
28 *stash_check, 48 *stash_check,
29 *stash_child; 49 *stash_child;
30 50
51#ifndef SIG_SIZE
52/* kudos to Slaven Rezic for the idea */
53static char sig_size [] = { SIG_NUM };
54# define SIG_SIZE (sizeof (sig_size) + 1)
55#endif
56
31static int 57static int
32sv_signum (SV *sig) 58sv_signum (SV *sig)
33{ 59{
34 int signum; 60 int signum;
35 61
36 if (SvIV (sig) > 0) 62 SvGETMAGIC (sig);
37 return SvIV (sig);
38 63
39 for (signum = 1; signum < SIG_SIZE; ++signum) 64 for (signum = 1; signum < SIG_SIZE; ++signum)
40 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 65 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
41 return signum; 66 return signum;
42 67
68 if (SvIV (sig) > 0)
69 return SvIV (sig);
70
43 return -1; 71 return -1;
44} 72}
45 73
46///////////////////////////////////////////////////////////////////////////// 74/////////////////////////////////////////////////////////////////////////////
47// Event 75// Event
57 fh = SvRV (fh); 85 fh = SvRV (fh);
58 86
59 if (SvTYPE (fh) == SVt_PVGV) 87 if (SvTYPE (fh) == SVt_PVGV)
60 return PerlIO_fileno (IoIFP (sv_2io (fh))); 88 return PerlIO_fileno (IoIFP (sv_2io (fh)));
61 89
62 if (SvIOK (fh)) 90 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff))
63 return SvIV (fh); 91 return SvIV (fh);
64 92
65 return -1; 93 return -1;
66} 94}
67 95
73 SvPOK_only (self); 101 SvPOK_only (self);
74 SvCUR_set (self, size); 102 SvCUR_set (self, size);
75 103
76 w = (struct ev_watcher *)SvPVX (self); 104 w = (struct ev_watcher *)SvPVX (self);
77 105
78 ev_watcher_init (w, e_cb); 106 ev_init (w, e_cb);
79 107
108 w->data = 0;
80 w->fh = 0; 109 w->fh = 0;
81 w->cb_sv = newSVsv (cb_sv); 110 w->cb_sv = newSVsv (cb_sv);
82 w->self = self; 111 w->self = self;
83 112
84 return (void *)w; 113 return (void *)w;
114}
115
116static void
117e_destroy (void *w_)
118{
119 struct ev_watcher *w = (struct ev_watcher *)w_;
120
121 SvREFCNT_dec (w->fh ); w->fh = 0;
122 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
123 SvREFCNT_dec (w->data ); w->data = 0;
85} 124}
86 125
87static SV * 126static SV *
88e_bless (struct ev_watcher *w, HV *stash) 127e_bless (struct ev_watcher *w, HV *stash)
89{ 128{
122 PUSHMARK (SP); 161 PUSHMARK (SP);
123 EXTEND (SP, 2); 162 EXTEND (SP, 2);
124 PUSHs (sv_self); 163 PUSHs (sv_self);
125 PUSHs (sv_events); 164 PUSHs (sv_events);
126 165
127 if (revents & EV_CHILD)
128 XPUSHs (sv_status = newSViv (((struct ev_child *)w)->status));
129
130 PUTBACK; 166 PUTBACK;
131 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 167 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
132 SP = PL_stack_base + mark; PUTBACK; 168 SP = PL_stack_base + mark; PUTBACK;
133 169
134 SvREFCNT_dec (sv_self); 170 SvREFCNT_dec (sv_self);
146 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 182 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
147 SP = PL_stack_base + mark; PUTBACK; 183 SP = PL_stack_base + mark; PUTBACK;
148 } 184 }
149} 185}
150 186
151#if 0 187static ev_tstamp
188e_periodic_cb (struct ev_periodic *w, ev_tstamp now)
189{
190 ev_tstamp retval;
191 int count;
192 dSP;
193
194 ENTER;
195 SAVETMPS;
196
197 PUSHMARK (SP);
198 EXTEND (SP, 2);
199 PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */
200 PUSHs (newSVnv (now));
201
202 PUTBACK;
203 count = call_sv (w->fh, G_SCALAR | G_EVAL);
204 SPAGAIN;
205
206 if (SvTRUE (ERRSV))
207 {
208 PUSHMARK (SP);
209 PUTBACK;
210 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
211 SPAGAIN;
212 }
213
214 if (count > 0)
215 {
216 retval = SvNV (TOPs);
217
218 if (retval < now)
219 retval = now;
220 }
221 else
222 retval = now;
223
224 FREETMPS;
225 LEAVE;
226
227 return retval;
228}
229
152///////////////////////////////////////////////////////////////////////////// 230/////////////////////////////////////////////////////////////////////////////
153// DNS 231// DNS
154 232
233#ifndef WIN32
155static void 234static void
156dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 235dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
157{ 236{
158 dSP; 237 dSP;
159 SV *cb = (SV *)arg; 238 SV *cb = (SV *)arg;
203#endif 282#endif
204 283
205#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 284#define CHECK_REPEAT(repeat) if (repeat < 0.) \
206 croak (# repeat " value must be >= 0"); 285 croak (# repeat " value must be >= 0");
207 286
287#define CHECK_FD(fh,fd) if ((fd) < 0) \
288 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
289
208///////////////////////////////////////////////////////////////////////////// 290/////////////////////////////////////////////////////////////////////////////
209// XS interface functions 291// XS interface functions
210 292
211MODULE = EV PACKAGE = EV PREFIX = ev_ 293MODULE = EV PACKAGE = EV PREFIX = ev_
212 294
213PROTOTYPES: ENABLE 295PROTOTYPES: ENABLE
214 296
215BOOT: 297BOOT:
216{ 298{
217 int i;
218 HV *stash = gv_stashpv ("EV", 1); 299 HV *stash = gv_stashpv ("EV", 1);
219 300
220 static const struct { 301 static const struct {
221 const char *name; 302 const char *name;
222 IV iv; 303 IV iv;
223 } *civ, const_iv[] = { 304 } *civ, const_iv[] = {
224# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 305# define const_iv(pfx, name) { # name, (IV) pfx ## name },
306 const_iv (EV_, MINPRI)
307 const_iv (EV_, MAXPRI)
308
225 const_iv (EV_, UNDEF) 309 const_iv (EV_, UNDEF)
226 const_iv (EV_, NONE) 310 const_iv (EV_, NONE)
227 const_iv (EV_, TIMEOUT) 311 const_iv (EV_, TIMEOUT)
228 const_iv (EV_, READ) 312 const_iv (EV_, READ)
229 const_iv (EV_, WRITE) 313 const_iv (EV_, WRITE)
233 const_iv (EV_, ERROR) 317 const_iv (EV_, ERROR)
234 318
235 const_iv (EV, LOOP_ONESHOT) 319 const_iv (EV, LOOP_ONESHOT)
236 const_iv (EV, LOOP_NONBLOCK) 320 const_iv (EV, LOOP_NONBLOCK)
237 321
238 const_iv (EV, METHOD_NONE) 322 const_iv (EV, METHOD_AUTO)
239 const_iv (EV, METHOD_SELECT) 323 const_iv (EV, METHOD_SELECT)
324 const_iv (EV, METHOD_POLL)
240 const_iv (EV, METHOD_EPOLL) 325 const_iv (EV, METHOD_EPOLL)
326 const_iv (EV, METHOD_KQUEUE)
327 const_iv (EV, METHOD_DEVPOLL)
328 const_iv (EV, METHOD_PORT)
329 const_iv (EV, METHOD_ANY)
241 }; 330 };
242 331
243 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 332 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
244 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 333 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
245 334
246 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 335 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
247 stash_io = gv_stashpv ("EV::Io" , 1); 336 stash_io = gv_stashpv ("EV::Io" , 1);
248 stash_time = gv_stashpv ("EV::Time" , 1);
249 stash_timer = gv_stashpv ("EV::Timer" , 1); 337 stash_timer = gv_stashpv ("EV::Timer" , 1);
250 stash_periodic = gv_stashpv ("EV::Periodic", 1); 338 stash_periodic = gv_stashpv ("EV::Periodic", 1);
251 stash_signal = gv_stashpv ("EV::Signal" , 1); 339 stash_signal = gv_stashpv ("EV::Signal" , 1);
252 stash_idle = gv_stashpv ("EV::Idle" , 1); 340 stash_idle = gv_stashpv ("EV::Idle" , 1);
253 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 341 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
261 /* the poor man's shared library emulator */ 349 /* the poor man's shared library emulator */
262 evapi.ver = EV_API_VERSION; 350 evapi.ver = EV_API_VERSION;
263 evapi.rev = EV_API_REVISION; 351 evapi.rev = EV_API_REVISION;
264 evapi.sv_fileno = sv_fileno; 352 evapi.sv_fileno = sv_fileno;
265 evapi.sv_signum = sv_signum; 353 evapi.sv_signum = sv_signum;
266 evapi.now = &ev_now; 354 evapi.now = ev_now;
267 evapi.method = &ev_method; 355 evapi.method = ev_method;
268 evapi.loop_done = &ev_loop_done; 356 evapi.unloop = ev_unloop;
269 evapi.time = ev_time; 357 evapi.time = ev_time;
270 evapi.loop = ev_loop; 358 evapi.loop = ev_loop;
271 evapi.once = ev_once; 359 evapi.once = ev_once;
272 evapi.io_start = ev_io_start; 360 evapi.io_start = ev_io_start;
273 evapi.io_stop = ev_io_stop; 361 evapi.io_stop = ev_io_stop;
288 evapi.child_stop = ev_child_stop; 376 evapi.child_stop = ev_child_stop;
289 377
290 sv_setiv (sv, (IV)&evapi); 378 sv_setiv (sv, (IV)&evapi);
291 SvREADONLY_on (sv); 379 SvREADONLY_on (sv);
292 } 380 }
381#ifndef WIN32
382 pthread_atfork (0, 0, ev_default_fork);
383#endif
293} 384}
294 385
295NV ev_now () 386NV ev_now ()
296 CODE:
297 RETVAL = ev_now;
298 OUTPUT:
299 RETVAL
300 387
301int ev_method () 388int ev_method ()
302 CODE:
303 RETVAL = ev_method;
304 OUTPUT:
305 RETVAL
306 389
307NV ev_time () 390NV ev_time ()
308 391
309void ev_init (int flags = 0) 392int ev_default_loop (int methods = EVMETHOD_AUTO)
310 393
311void ev_loop (int flags = 0) 394void ev_loop (int flags = 0)
312 395
313void ev_loop_done (int value = 1) 396void ev_unloop (int how = 1)
314 CODE:
315 ev_loop_done = value;
316 397
317struct ev_io *io (SV *fh, int events, SV *cb) 398struct ev_io *io (SV *fh, int events, SV *cb)
318 ALIAS: 399 ALIAS:
319 io_ns = 1 400 io_ns = 1
320 CODE: 401 CODE:
402{
403 int fd = sv_fileno (fh);
404 CHECK_FD (fh, fd);
405
321 RETVAL = e_new (sizeof (struct ev_io), cb); 406 RETVAL = e_new (sizeof (struct ev_io), cb);
322 RETVAL->fh = newSVsv (fh); 407 RETVAL->fh = newSVsv (fh);
323 ev_io_set (RETVAL, sv_fileno (RETVAL->fh), events); 408 ev_io_set (RETVAL, fd, events);
324 if (!ix) ev_io_start (RETVAL); 409 if (!ix) ev_io_start (RETVAL);
410}
325 OUTPUT: 411 OUTPUT:
326 RETVAL 412 RETVAL
327 413
328struct ev_timer *timer (NV after, NV repeat, SV *cb) 414struct ev_timer *timer (NV after, NV repeat, SV *cb)
329 ALIAS: 415 ALIAS:
335 ev_timer_set (RETVAL, after, repeat); 421 ev_timer_set (RETVAL, after, repeat);
336 if (!ix) ev_timer_start (RETVAL); 422 if (!ix) ev_timer_start (RETVAL);
337 OUTPUT: 423 OUTPUT:
338 RETVAL 424 RETVAL
339 425
340struct ev_periodic *periodic (NV at, NV interval, SV *cb) 426SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
341 ALIAS: 427 ALIAS:
342 periodic_ns = 1 428 periodic_ns = 1
343 INIT: 429 INIT:
344 CHECK_REPEAT (interval); 430 CHECK_REPEAT (interval);
345 CODE: 431 CODE:
432{
433 struct ev_periodic *w;
346 RETVAL = e_new (sizeof (struct ev_periodic), cb); 434 w = e_new (sizeof (struct ev_periodic), cb);
347 ev_periodic_set (RETVAL, at, interval); 435 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
436 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
437 RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic);
348 if (!ix) ev_periodic_start (RETVAL); 438 if (!ix) ev_periodic_start (w);
439}
349 OUTPUT: 440 OUTPUT:
350 RETVAL 441 RETVAL
351 442
352struct ev_signal *signal (Signal signum, SV *cb) 443struct ev_signal *signal (Signal signum, SV *cb)
353 ALIAS: 444 ALIAS:
391 482
392struct ev_child *child (int pid, SV *cb) 483struct ev_child *child (int pid, SV *cb)
393 ALIAS: 484 ALIAS:
394 check_ns = 1 485 check_ns = 1
395 CODE: 486 CODE:
396 RETVAL = e_new (sizeof (struct ev_check), cb); 487 RETVAL = e_new (sizeof (struct ev_child), cb);
397 ev_child_set (RETVAL, pid); 488 ev_child_set (RETVAL, pid);
398 if (!ix) ev_child_start (RETVAL); 489 if (!ix) ev_child_start (RETVAL);
399 OUTPUT: 490 OUTPUT:
400 RETVAL 491 RETVAL
401 492
415 sv_setsv (w->cb_sv, new_cb); 506 sv_setsv (w->cb_sv, new_cb);
416} 507}
417 OUTPUT: 508 OUTPUT:
418 RETVAL 509 RETVAL
419 510
511SV *data (struct ev_watcher *w, SV *new_data = 0)
512 CODE:
513{
514 RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
515}
516 OUTPUT:
517 RETVAL
518
420void trigger (struct ev_watcher *w, int revents = EV_NONE) 519void trigger (struct ev_watcher *w, int revents = EV_NONE)
421 CODE: 520 CODE:
422 w->cb (w, revents); 521 w->cb (w, revents);
423 522
424MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ 523int priority (struct ev_watcher *w, int new_priority = 0)
425
426void ev_io_start (struct ev_io *w)
427
428void ev_io_stop (struct ev_io *w)
429
430void DESTROY (struct ev_io *w)
431 CODE: 524 CODE:
432 ev_io_stop (w);
433
434void set (struct ev_io *w, SV *fh, int events)
435 CODE:
436{ 525{
437 int active = w->active; 526 RETVAL = w->priority;
438 if (active) ev_io_stop (w);
439
440 sv_setsv (w->fh, fh);
441 ev_io_set (w, sv_fileno (w->fh), events);
442
443 if (active) ev_io_start (w);
444}
445
446SV *fh (struct ev_io *w, SV *new_fh = 0)
447 CODE:
448{
449 RETVAL = newSVsv (w->fh);
450 527
451 if (items > 1) 528 if (items > 1)
452 { 529 {
453 int active = w->active; 530 int active = ev_is_active (w);
531
532 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
533 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
534
535 if (active)
536 {
537 /* grrr. */
538 PUSHMARK (SP);
539 XPUSHs (ST (0));
540 call_method ("stop", G_DISCARD | G_VOID);
541 }
542
543 ev_set_priority (w, new_priority);
544
545 if (active)
546 {
547 PUSHMARK (SP);
548 XPUSHs (ST (0));
549 call_method ("start", G_DISCARD | G_VOID);
550 }
551 }
552}
553 OUTPUT:
554 RETVAL
555
556MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_
557
558void ev_io_start (struct ev_io *w)
559
560void ev_io_stop (struct ev_io *w)
561
562void DESTROY (struct ev_io *w)
563 CODE:
564 ev_io_stop (w);
565 e_destroy (w);
566
567void set (struct ev_io *w, SV *fh, int events)
568 CODE:
569{
570 int active = ev_is_active (w);
571 int fd = sv_fileno (fh);
572 CHECK_FD (fh, fd);
573
574 if (active) ev_io_stop (w);
575
576 sv_setsv (w->fh, fh);
577 ev_io_set (w, fd, events);
578
579 if (active) ev_io_start (w);
580}
581
582SV *fh (struct ev_io *w, SV *new_fh = 0)
583 CODE:
584{
585 RETVAL = newSVsv (w->fh);
586
587 if (items > 1)
588 {
589 int active = ev_is_active (w);
454 if (active) ev_io_stop (w); 590 if (active) ev_io_stop (w);
455 591
456 sv_setsv (w->fh, new_fh); 592 sv_setsv (w->fh, new_fh);
457 ev_io_set (w, sv_fileno (w->fh), w->events); 593 ev_io_set (w, sv_fileno (w->fh), w->events);
458 594
460 } 596 }
461} 597}
462 OUTPUT: 598 OUTPUT:
463 RETVAL 599 RETVAL
464 600
465short events (struct ev_io *w, short new_events = EV_UNDEF) 601int events (struct ev_io *w, int new_events = EV_UNDEF)
466 CODE: 602 CODE:
467{ 603{
468 RETVAL = w->events; 604 RETVAL = w->events;
469 605
470 if (items > 1) 606 if (items > 1)
471 { 607 {
472 int active = w->active; 608 int active = ev_is_active (w);
473 if (active) ev_io_stop (w); 609 if (active) ev_io_stop (w);
474 610
475 ev_io_set (w, w->fd, new_events); 611 ev_io_set (w, w->fd, new_events);
476 612
477 if (active) ev_io_start (w); 613 if (active) ev_io_start (w);
487void ev_signal_stop (struct ev_signal *w) 623void ev_signal_stop (struct ev_signal *w)
488 624
489void DESTROY (struct ev_signal *w) 625void DESTROY (struct ev_signal *w)
490 CODE: 626 CODE:
491 ev_signal_stop (w); 627 ev_signal_stop (w);
628 e_destroy (w);
492 629
493void set (struct ev_signal *w, SV *signal = 0) 630void set (struct ev_signal *w, SV *signal)
494 CODE: 631 CODE:
495{ 632{
496 Signal signum = sv_signum (signal); /* may croak here */ 633 Signal signum = sv_signum (signal); /* may croak here */
497 int active = w->active; 634 int active = ev_is_active (w);
498 635
499 if (active) ev_signal_stop (w); 636 if (active) ev_signal_stop (w);
637
500 ev_signal_set (w, signum); 638 ev_signal_set (w, signum);
639
501 if (active) ev_signal_start (w); 640 if (active) ev_signal_start (w);
502} 641}
503 642
504MODULE = EV PACKAGE = EV::Time 643int signal (struct ev_signal *w, SV *new_signal = 0)
644 CODE:
645{
646 RETVAL = w->signum;
647
648 if (items > 1)
649 {
650 Signal signum = sv_signum (new_signal); /* may croak here */
651 int active = ev_is_active (w);
652 if (active) ev_signal_stop (w);
653
654 ev_signal_set (w, signum);
655
656 if (active) ev_signal_start (w);
657 }
658}
659 OUTPUT:
660 RETVAL
505 661
506MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 662MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
507 663
508void ev_timer_start (struct ev_timer *w) 664void ev_timer_start (struct ev_timer *w)
509 INIT: 665 INIT:
516 CHECK_REPEAT (w->repeat); 672 CHECK_REPEAT (w->repeat);
517 673
518void DESTROY (struct ev_timer *w) 674void DESTROY (struct ev_timer *w)
519 CODE: 675 CODE:
520 ev_timer_stop (w); 676 ev_timer_stop (w);
677 e_destroy (w);
521 678
522void set (struct ev_timer *w, NV after, NV repeat = 0.) 679void set (struct ev_timer *w, NV after, NV repeat = 0.)
523 INIT: 680 INIT:
524 CHECK_REPEAT (repeat); 681 CHECK_REPEAT (repeat);
525 CODE: 682 CODE:
526{ 683{
527 int active = w->active; 684 int active = ev_is_active (w);
528 if (active) ev_timer_stop (w); 685 if (active) ev_timer_stop (w);
529 ev_timer_set (w, after, repeat); 686 ev_timer_set (w, after, repeat);
530 if (active) ev_timer_start (w); 687 if (active) ev_timer_start (w);
531} 688}
532 689
536 INIT: 693 INIT:
537 CHECK_REPEAT (w->interval); 694 CHECK_REPEAT (w->interval);
538 695
539void ev_periodic_stop (struct ev_periodic *w) 696void ev_periodic_stop (struct ev_periodic *w)
540 697
698void ev_periodic_again (struct ev_periodic *w)
699
541void DESTROY (struct ev_periodic *w) 700void DESTROY (struct ev_periodic *w)
542 CODE: 701 CODE:
543 ev_periodic_stop (w); 702 ev_periodic_stop (w);
703 e_destroy (w);
544 704
545void set (struct ev_periodic *w, NV at, NV interval = 0.) 705void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
546 INIT: 706 INIT:
547 CHECK_REPEAT (interval); 707 CHECK_REPEAT (interval);
548 CODE: 708 CODE:
549{ 709{
550 int active = w->active; 710 int active = ev_is_active (w);
551 if (active) ev_periodic_stop (w); 711 if (active) ev_periodic_stop (w);
712
713 SvREFCNT_dec (w->fh);
714 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
552 ev_periodic_set (w, at, interval); 715 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
716
553 if (active) ev_periodic_start (w); 717 if (active) ev_periodic_start (w);
554} 718}
555 719
556MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 720MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
557 721
560void ev_idle_stop (struct ev_idle *w) 724void ev_idle_stop (struct ev_idle *w)
561 725
562void DESTROY (struct ev_idle *w) 726void DESTROY (struct ev_idle *w)
563 CODE: 727 CODE:
564 ev_idle_stop (w); 728 ev_idle_stop (w);
729 e_destroy (w);
565 730
566MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 731MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
567 732
568void ev_prepare_start (struct ev_prepare *w) 733void ev_prepare_start (struct ev_prepare *w)
569 734
570void ev_prepare_stop (struct ev_prepare *w) 735void ev_prepare_stop (struct ev_prepare *w)
571 736
572void DESTROY (struct ev_prepare *w) 737void DESTROY (struct ev_prepare *w)
573 CODE: 738 CODE:
574 ev_prepare_stop (w); 739 ev_prepare_stop (w);
740 e_destroy (w);
575 741
576MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ 742MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
577 743
578void ev_check_start (struct ev_check *w) 744void ev_check_start (struct ev_check *w)
579 745
580void ev_check_stop (struct ev_check *w) 746void ev_check_stop (struct ev_check *w)
581 747
582void DESTROY (struct ev_check *w) 748void DESTROY (struct ev_check *w)
583 CODE: 749 CODE:
584 ev_check_stop (w); 750 ev_check_stop (w);
751 e_destroy (w);
585 752
586MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 753MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
587 754
588void ev_child_start (struct ev_child *w) 755void ev_child_start (struct ev_child *w)
589 756
590void ev_child_stop (struct ev_child *w) 757void ev_child_stop (struct ev_child *w)
591 758
592void DESTROY (struct ev_child *w) 759void DESTROY (struct ev_child *w)
593 CODE: 760 CODE:
594 ev_child_stop (w); 761 ev_child_stop (w);
762 e_destroy (w);
595 763
596void set (struct ev_child *w, int pid) 764void set (struct ev_child *w, int pid)
597 CODE: 765 CODE:
598{ 766{
599 int active = w->active; 767 int active = ev_is_active (w);
600 if (active) ev_child_stop (w); 768 if (active) ev_child_stop (w);
769
601 ev_child_set (w, pid); 770 ev_child_set (w, pid);
771
602 if (active) ev_child_start (w); 772 if (active) ev_child_start (w);
603} 773}
604 774
775int pid (struct ev_child *w, int new_pid = 0)
776 CODE:
777{
778 RETVAL = w->pid;
779
780 if (items > 1)
781 {
782 int active = ev_is_active (w);
783 if (active) ev_child_stop (w);
784
785 ev_child_set (w, new_pid);
786
787 if (active) ev_child_start (w);
788 }
789}
790 OUTPUT:
791 RETVAL
792
793
605int status (struct ev_child *w) 794int rstatus (struct ev_child *w)
795 ALIAS:
796 rpid = 1
606 CODE: 797 CODE:
607 RETVAL = w->status; 798 RETVAL = ix ? w->rpid : w->rstatus;
608 OUTPUT: 799 OUTPUT:
609 RETVAL 800 RETVAL
610 801
611#if 0 802#ifndef WIN32
612 803
613MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 804MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
614 805
615BOOT: 806BOOT:
616{ 807{
699 890
700void evdns_search_add (char *domain) 891void evdns_search_add (char *domain)
701 892
702void evdns_search_ndots_set (int ndots) 893void evdns_search_ndots_set (int ndots)
703 894
895#if 0
704 896
705MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 897MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
706 898
707BOOT: 899BOOT:
708{ 900{
740 932
741#void DESTROY (struct evhttp_request *req); 933#void DESTROY (struct evhttp_request *req);
742 934
743#endif 935#endif
744 936
937#endif
745 938
746 939
747 940
748 941
749 942

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines