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.35 by root, Thu Nov 1 13:33:12 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines