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.34 by root, Thu Nov 1 12:11:07 2007 UTC

30static int 30static int
31sv_signum (SV *sig) 31sv_signum (SV *sig)
32{ 32{
33 int signum; 33 int signum;
34 34
35 if (SvIV (sig) > 0) 35 SvGETMAGIC (sig);
36 return SvIV (sig);
37 36
38 for (signum = 1; signum < SIG_SIZE; ++signum) 37 for (signum = 1; signum < SIG_SIZE; ++signum)
39 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 38 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
40 return signum; 39 return signum;
41 40
41 if (SvIV (sig) > 0)
42 return SvIV (sig);
43
42 return -1; 44 return -1;
43} 45}
44 46
45///////////////////////////////////////////////////////////////////////////// 47/////////////////////////////////////////////////////////////////////////////
46// Event 48// Event
56 fh = SvRV (fh); 58 fh = SvRV (fh);
57 59
58 if (SvTYPE (fh) == SVt_PVGV) 60 if (SvTYPE (fh) == SVt_PVGV)
59 return PerlIO_fileno (IoIFP (sv_2io (fh))); 61 return PerlIO_fileno (IoIFP (sv_2io (fh)));
60 62
61 if (SvIOK (fh)) 63 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff))
62 return SvIV (fh); 64 return SvIV (fh);
63 65
64 return -1; 66 return -1;
65} 67}
66 68
79 w->fh = 0; 81 w->fh = 0;
80 w->cb_sv = newSVsv (cb_sv); 82 w->cb_sv = newSVsv (cb_sv);
81 w->self = self; 83 w->self = self;
82 84
83 return (void *)w; 85 return (void *)w;
86}
87
88static void *
89e_destroy (void *w_)
90{
91 struct ev_watcher *w = w_;
92
93 SvREFCNT_dec (w->fh ); w->fh = 0;
94 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
84} 95}
85 96
86static SV * 97static SV *
87e_bless (struct ev_watcher *w, HV *stash) 98e_bless (struct ev_watcher *w, HV *stash)
88{ 99{
201} 212}
202#endif 213#endif
203 214
204#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 215#define CHECK_REPEAT(repeat) if (repeat < 0.) \
205 croak (# repeat " value must be >= 0"); 216 croak (# repeat " value must be >= 0");
217
218#define CHECK_FD(fh,fd) if ((fd) < 0) \
219 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
206 220
207///////////////////////////////////////////////////////////////////////////// 221/////////////////////////////////////////////////////////////////////////////
208// XS interface functions 222// XS interface functions
209 223
210MODULE = EV PACKAGE = EV PREFIX = ev_ 224MODULE = EV PACKAGE = EV PREFIX = ev_
286 evapi.child_stop = ev_child_stop; 300 evapi.child_stop = ev_child_stop;
287 301
288 sv_setiv (sv, (IV)&evapi); 302 sv_setiv (sv, (IV)&evapi);
289 SvREADONLY_on (sv); 303 SvREADONLY_on (sv);
290 } 304 }
305
306 pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child);
291} 307}
292 308
293NV ev_now () 309NV ev_now ()
294 CODE: 310 CODE:
295 RETVAL = ev_now; 311 RETVAL = ev_now;
314 330
315struct ev_io *io (SV *fh, int events, SV *cb) 331struct ev_io *io (SV *fh, int events, SV *cb)
316 ALIAS: 332 ALIAS:
317 io_ns = 1 333 io_ns = 1
318 CODE: 334 CODE:
335{
336 int fd = sv_fileno (fh);
337 CHECK_FD (fh, fd);
338
319 RETVAL = e_new (sizeof (struct ev_io), cb); 339 RETVAL = e_new (sizeof (struct ev_io), cb);
320 RETVAL->fh = newSVsv (fh); 340 RETVAL->fh = newSVsv (fh);
321 ev_io_set (RETVAL, sv_fileno (RETVAL->fh), events); 341 ev_io_set (RETVAL, fd, events);
322 if (!ix) ev_io_start (RETVAL); 342 if (!ix) ev_io_start (RETVAL);
343}
323 OUTPUT: 344 OUTPUT:
324 RETVAL 345 RETVAL
325 346
326struct ev_timer *timer (NV after, NV repeat, SV *cb) 347struct ev_timer *timer (NV after, NV repeat, SV *cb)
327 ALIAS: 348 ALIAS:
426void ev_io_stop (struct ev_io *w) 447void ev_io_stop (struct ev_io *w)
427 448
428void DESTROY (struct ev_io *w) 449void DESTROY (struct ev_io *w)
429 CODE: 450 CODE:
430 ev_io_stop (w); 451 ev_io_stop (w);
452 e_destroy (w);
431 453
432void set (struct ev_io *w, SV *fh, int events) 454void set (struct ev_io *w, SV *fh, int events)
433 CODE: 455 CODE:
434{ 456{
435 int active = w->active; 457 int active = w->active;
458 int fd = sv_fileno (fh);
459 CHECK_FD (fh, fd);
460
436 if (active) ev_io_stop (w); 461 if (active) ev_io_stop (w);
437 462
438 sv_setsv (w->fh, fh); 463 sv_setsv (w->fh, fh);
439 ev_io_set (w, sv_fileno (w->fh), events); 464 ev_io_set (w, fd, events);
440 465
441 if (active) ev_io_start (w); 466 if (active) ev_io_start (w);
442} 467}
443 468
444SV *fh (struct ev_io *w, SV *new_fh = 0) 469SV *fh (struct ev_io *w, SV *new_fh = 0)
485void ev_signal_stop (struct ev_signal *w) 510void ev_signal_stop (struct ev_signal *w)
486 511
487void DESTROY (struct ev_signal *w) 512void DESTROY (struct ev_signal *w)
488 CODE: 513 CODE:
489 ev_signal_stop (w); 514 ev_signal_stop (w);
515 e_destroy (w);
490 516
491void set (struct ev_signal *w, SV *signal = 0) 517void set (struct ev_signal *w, SV *signal = 0)
492 CODE: 518 CODE:
493{ 519{
494 Signal signum = sv_signum (signal); /* may croak here */ 520 Signal signum = sv_signum (signal); /* may croak here */
514 CHECK_REPEAT (w->repeat); 540 CHECK_REPEAT (w->repeat);
515 541
516void DESTROY (struct ev_timer *w) 542void DESTROY (struct ev_timer *w)
517 CODE: 543 CODE:
518 ev_timer_stop (w); 544 ev_timer_stop (w);
545 e_destroy (w);
519 546
520void set (struct ev_timer *w, NV after, NV repeat = 0.) 547void set (struct ev_timer *w, NV after, NV repeat = 0.)
521 INIT: 548 INIT:
522 CHECK_REPEAT (repeat); 549 CHECK_REPEAT (repeat);
523 CODE: 550 CODE:
537void ev_periodic_stop (struct ev_periodic *w) 564void ev_periodic_stop (struct ev_periodic *w)
538 565
539void DESTROY (struct ev_periodic *w) 566void DESTROY (struct ev_periodic *w)
540 CODE: 567 CODE:
541 ev_periodic_stop (w); 568 ev_periodic_stop (w);
569 e_destroy (w);
542 570
543void set (struct ev_periodic *w, NV at, NV interval = 0.) 571void set (struct ev_periodic *w, NV at, NV interval = 0.)
544 INIT: 572 INIT:
545 CHECK_REPEAT (interval); 573 CHECK_REPEAT (interval);
546 CODE: 574 CODE:
558void ev_idle_stop (struct ev_idle *w) 586void ev_idle_stop (struct ev_idle *w)
559 587
560void DESTROY (struct ev_idle *w) 588void DESTROY (struct ev_idle *w)
561 CODE: 589 CODE:
562 ev_idle_stop (w); 590 ev_idle_stop (w);
591 e_destroy (w);
563 592
564MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 593MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
565 594
566void ev_prepare_start (struct ev_prepare *w) 595void ev_prepare_start (struct ev_prepare *w)
567 596
568void ev_prepare_stop (struct ev_prepare *w) 597void ev_prepare_stop (struct ev_prepare *w)
569 598
570void DESTROY (struct ev_prepare *w) 599void DESTROY (struct ev_prepare *w)
571 CODE: 600 CODE:
572 ev_prepare_stop (w); 601 ev_prepare_stop (w);
602 e_destroy (w);
573 603
574MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ 604MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
575 605
576void ev_check_start (struct ev_check *w) 606void ev_check_start (struct ev_check *w)
577 607
578void ev_check_stop (struct ev_check *w) 608void ev_check_stop (struct ev_check *w)
579 609
580void DESTROY (struct ev_check *w) 610void DESTROY (struct ev_check *w)
581 CODE: 611 CODE:
582 ev_check_stop (w); 612 ev_check_stop (w);
613 e_destroy (w);
583 614
584MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 615MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
585 616
586void ev_child_start (struct ev_child *w) 617void ev_child_start (struct ev_child *w)
587 618
588void ev_child_stop (struct ev_child *w) 619void ev_child_stop (struct ev_child *w)
589 620
590void DESTROY (struct ev_child *w) 621void DESTROY (struct ev_child *w)
591 CODE: 622 CODE:
592 ev_child_stop (w); 623 ev_child_stop (w);
624 e_destroy (w);
593 625
594void set (struct ev_child *w, int pid) 626void set (struct ev_child *w, int pid)
595 CODE: 627 CODE:
596{ 628{
597 int active = w->active; 629 int active = w->active;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines