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

Comparing EV/EV.xs (file contents):
Revision 1.31 by root, Thu Nov 1 11:11:21 2007 UTC vs.
Revision 1.39 by root, Fri Nov 2 11:02:22 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
13#include "libev/ev.c" 10#include "libev/ev.c"
11#include "libev/event.h"
12#include "libev/event.c"
13#include "libev/evdns.c"
14 14
15typedef int Signal; 15typedef int Signal;
16 16
17static struct EVAPI evapi; 17static struct EVAPI evapi;
18 18
83 w->self = self; 83 w->self = self;
84 84
85 return (void *)w; 85 return (void *)w;
86} 86}
87 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;
95}
96
88static SV * 97static SV *
89e_bless (struct ev_watcher *w, HV *stash) 98e_bless (struct ev_watcher *w, HV *stash)
90{ 99{
91 SV *rv; 100 SV *rv;
92 101
108 dSP; 117 dSP;
109 I32 mark = SP - PL_stack_base; 118 I32 mark = SP - PL_stack_base;
110 SV *sv_self, *sv_events, *sv_status = 0; 119 SV *sv_self, *sv_events, *sv_status = 0;
111 static SV *sv_events_cache; 120 static SV *sv_events_cache;
112 121
113 fprintf (stderr, "e_cb %p,%x\n", w, revents);//D
114
115 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 122 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
116 123
117 if (sv_events_cache) 124 if (sv_events_cache)
118 { 125 {
119 sv_events = sv_events_cache; sv_events_cache = 0; 126 sv_events = sv_events_cache; sv_events_cache = 0;
149 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 156 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
150 SP = PL_stack_base + mark; PUTBACK; 157 SP = PL_stack_base + mark; PUTBACK;
151 } 158 }
152} 159}
153 160
154#if 0
155///////////////////////////////////////////////////////////////////////////// 161/////////////////////////////////////////////////////////////////////////////
156// DNS 162// DNS
157 163
158static void 164static void
159dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 165dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
201 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 207 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
202 } 208 }
203 209
204 LEAVE; 210 LEAVE;
205} 211}
206#endif
207 212
208#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 213#define CHECK_REPEAT(repeat) if (repeat < 0.) \
209 croak (# repeat " value must be >= 0"); 214 croak (# repeat " value must be >= 0");
210 215
211#define CHECK_FD(fh,fd) if ((fd) < 0) \ 216#define CHECK_FD(fh,fd) if ((fd) < 0) \
293 evapi.child_stop = ev_child_stop; 298 evapi.child_stop = ev_child_stop;
294 299
295 sv_setiv (sv, (IV)&evapi); 300 sv_setiv (sv, (IV)&evapi);
296 SvREADONLY_on (sv); 301 SvREADONLY_on (sv);
297 } 302 }
303
304 pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child);
298} 305}
299 306
300NV ev_now () 307NV ev_now ()
301 CODE: 308 CODE:
302 RETVAL = ev_now; 309 RETVAL = ev_now;
438void ev_io_stop (struct ev_io *w) 445void ev_io_stop (struct ev_io *w)
439 446
440void DESTROY (struct ev_io *w) 447void DESTROY (struct ev_io *w)
441 CODE: 448 CODE:
442 ev_io_stop (w); 449 ev_io_stop (w);
450 e_destroy (w);
443 451
444void set (struct ev_io *w, SV *fh, int events) 452void set (struct ev_io *w, SV *fh, int events)
445 CODE: 453 CODE:
446{ 454{
447 int active = w->active; 455 int active = w->active;
473 } 481 }
474} 482}
475 OUTPUT: 483 OUTPUT:
476 RETVAL 484 RETVAL
477 485
478short events (struct ev_io *w, short new_events = EV_UNDEF) 486int events (struct ev_io *w, int new_events = EV_UNDEF)
479 CODE: 487 CODE:
480{ 488{
481 RETVAL = w->events; 489 RETVAL = w->events;
482 490
483 if (items > 1) 491 if (items > 1)
500void ev_signal_stop (struct ev_signal *w) 508void ev_signal_stop (struct ev_signal *w)
501 509
502void DESTROY (struct ev_signal *w) 510void DESTROY (struct ev_signal *w)
503 CODE: 511 CODE:
504 ev_signal_stop (w); 512 ev_signal_stop (w);
513 e_destroy (w);
505 514
506void set (struct ev_signal *w, SV *signal = 0) 515void set (struct ev_signal *w, SV *signal = 0)
507 CODE: 516 CODE:
508{ 517{
509 Signal signum = sv_signum (signal); /* may croak here */ 518 Signal signum = sv_signum (signal); /* may croak here */
510 int active = w->active; 519 int active = w->active;
511 520
512 if (active) ev_signal_stop (w); 521 if (active) ev_signal_stop (w);
522
513 ev_signal_set (w, signum); 523 ev_signal_set (w, signum);
524
514 if (active) ev_signal_start (w); 525 if (active) ev_signal_start (w);
515} 526}
527
528int signal (struct ev_signal *w, SV *new_signal = 0)
529 CODE:
530{
531 Signal signum = new_signal ? sv_signum (signal) : 0; /* may croak here */
532 RETVAL = w->signum;
533
534 if (items > 1)
535 {
536 int active = w->active;
537 if (active) ev_signal_stop (w);
538
539 ev_signal_set (w, signum);
540
541 if (active) ev_signal_start (w);
542 }
543}
544 OUTPUT:
545 RETVAL
516 546
517MODULE = EV PACKAGE = EV::Time 547MODULE = EV PACKAGE = EV::Time
518 548
519MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 549MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
520 550
529 CHECK_REPEAT (w->repeat); 559 CHECK_REPEAT (w->repeat);
530 560
531void DESTROY (struct ev_timer *w) 561void DESTROY (struct ev_timer *w)
532 CODE: 562 CODE:
533 ev_timer_stop (w); 563 ev_timer_stop (w);
564 e_destroy (w);
534 565
535void set (struct ev_timer *w, NV after, NV repeat = 0.) 566void set (struct ev_timer *w, NV after, NV repeat = 0.)
536 INIT: 567 INIT:
537 CHECK_REPEAT (repeat); 568 CHECK_REPEAT (repeat);
538 CODE: 569 CODE:
552void ev_periodic_stop (struct ev_periodic *w) 583void ev_periodic_stop (struct ev_periodic *w)
553 584
554void DESTROY (struct ev_periodic *w) 585void DESTROY (struct ev_periodic *w)
555 CODE: 586 CODE:
556 ev_periodic_stop (w); 587 ev_periodic_stop (w);
588 e_destroy (w);
557 589
558void set (struct ev_periodic *w, NV at, NV interval = 0.) 590void set (struct ev_periodic *w, NV at, NV interval = 0.)
559 INIT: 591 INIT:
560 CHECK_REPEAT (interval); 592 CHECK_REPEAT (interval);
561 CODE: 593 CODE:
562{ 594{
563 int active = w->active; 595 int active = w->active;
564 if (active) ev_periodic_stop (w); 596 if (active) ev_periodic_stop (w);
597
565 ev_periodic_set (w, at, interval); 598 ev_periodic_set (w, at, interval);
599
566 if (active) ev_periodic_start (w); 600 if (active) ev_periodic_start (w);
567} 601}
568 602
569MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 603MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
570 604
573void ev_idle_stop (struct ev_idle *w) 607void ev_idle_stop (struct ev_idle *w)
574 608
575void DESTROY (struct ev_idle *w) 609void DESTROY (struct ev_idle *w)
576 CODE: 610 CODE:
577 ev_idle_stop (w); 611 ev_idle_stop (w);
612 e_destroy (w);
578 613
579MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 614MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
580 615
581void ev_prepare_start (struct ev_prepare *w) 616void ev_prepare_start (struct ev_prepare *w)
582 617
583void ev_prepare_stop (struct ev_prepare *w) 618void ev_prepare_stop (struct ev_prepare *w)
584 619
585void DESTROY (struct ev_prepare *w) 620void DESTROY (struct ev_prepare *w)
586 CODE: 621 CODE:
587 ev_prepare_stop (w); 622 ev_prepare_stop (w);
623 e_destroy (w);
588 624
589MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ 625MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
590 626
591void ev_check_start (struct ev_check *w) 627void ev_check_start (struct ev_check *w)
592 628
593void ev_check_stop (struct ev_check *w) 629void ev_check_stop (struct ev_check *w)
594 630
595void DESTROY (struct ev_check *w) 631void DESTROY (struct ev_check *w)
596 CODE: 632 CODE:
597 ev_check_stop (w); 633 ev_check_stop (w);
634 e_destroy (w);
598 635
599MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 636MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
600 637
601void ev_child_start (struct ev_child *w) 638void ev_child_start (struct ev_child *w)
602 639
603void ev_child_stop (struct ev_child *w) 640void ev_child_stop (struct ev_child *w)
604 641
605void DESTROY (struct ev_child *w) 642void DESTROY (struct ev_child *w)
606 CODE: 643 CODE:
607 ev_child_stop (w); 644 ev_child_stop (w);
645 e_destroy (w);
608 646
609void set (struct ev_child *w, int pid) 647void set (struct ev_child *w, int pid)
610 CODE: 648 CODE:
611{ 649{
612 int active = w->active; 650 int active = w->active;
613 if (active) ev_child_stop (w); 651 if (active) ev_child_stop (w);
652
614 ev_child_set (w, pid); 653 ev_child_set (w, pid);
654
615 if (active) ev_child_start (w); 655 if (active) ev_child_start (w);
616} 656}
617 657
658int pid (struct ev_child *w, int new_pid = 0)
659 CODE:
660{
661 RETVAL = newSVsv (w->pid);
662
663 if (items > 1)
664 {
665 int active = w->active;
666 if (active) ev_child_stop (w);
667
668 ev_child_set (w, new_pid);
669
670 if (active) ev_child_start (w);
671 }
672}
673 OUTPUT:
674 RETVAL
675
676
618int status (struct ev_child *w) 677int status (struct ev_child *w)
619 CODE: 678 CODE:
620 RETVAL = w->status; 679 RETVAL = w->status;
621 OUTPUT: 680 OUTPUT:
622 RETVAL 681 RETVAL
623
624#if 0
625 682
626MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 683MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
627 684
628BOOT: 685BOOT:
629{ 686{
712 769
713void evdns_search_add (char *domain) 770void evdns_search_add (char *domain)
714 771
715void evdns_search_ndots_set (int ndots) 772void evdns_search_ndots_set (int ndots)
716 773
774#if 0
717 775
718MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 776MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
719 777
720BOOT: 778BOOT:
721{ 779{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines