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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines