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

Comparing EV/EV.xs (file contents):
Revision 1.32 by root, Thu Nov 1 11:11:39 2007 UTC vs.
Revision 1.38 by root, Thu Nov 1 17:45:30 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
147 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);
148 SP = PL_stack_base + mark; PUTBACK; 157 SP = PL_stack_base + mark; PUTBACK;
149 } 158 }
150} 159}
151 160
152#if 0
153///////////////////////////////////////////////////////////////////////////// 161/////////////////////////////////////////////////////////////////////////////
154// DNS 162// DNS
155 163
156static void 164static void
157dns_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)
199 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);
200 } 208 }
201 209
202 LEAVE; 210 LEAVE;
203} 211}
204#endif
205 212
206#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 213#define CHECK_REPEAT(repeat) if (repeat < 0.) \
207 croak (# repeat " value must be >= 0"); 214 croak (# repeat " value must be >= 0");
208 215
209#define CHECK_FD(fh,fd) if ((fd) < 0) \ 216#define CHECK_FD(fh,fd) if ((fd) < 0) \
291 evapi.child_stop = ev_child_stop; 298 evapi.child_stop = ev_child_stop;
292 299
293 sv_setiv (sv, (IV)&evapi); 300 sv_setiv (sv, (IV)&evapi);
294 SvREADONLY_on (sv); 301 SvREADONLY_on (sv);
295 } 302 }
303
304 pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child);
296} 305}
297 306
298NV ev_now () 307NV ev_now ()
299 CODE: 308 CODE:
300 RETVAL = ev_now; 309 RETVAL = ev_now;
436void ev_io_stop (struct ev_io *w) 445void ev_io_stop (struct ev_io *w)
437 446
438void DESTROY (struct ev_io *w) 447void DESTROY (struct ev_io *w)
439 CODE: 448 CODE:
440 ev_io_stop (w); 449 ev_io_stop (w);
450 e_destroy (w);
441 451
442void set (struct ev_io *w, SV *fh, int events) 452void set (struct ev_io *w, SV *fh, int events)
443 CODE: 453 CODE:
444{ 454{
445 int active = w->active; 455 int active = w->active;
471 } 481 }
472} 482}
473 OUTPUT: 483 OUTPUT:
474 RETVAL 484 RETVAL
475 485
476short events (struct ev_io *w, short new_events = EV_UNDEF) 486int events (struct ev_io *w, int new_events = EV_UNDEF)
477 CODE: 487 CODE:
478{ 488{
479 RETVAL = w->events; 489 RETVAL = w->events;
480 490
481 if (items > 1) 491 if (items > 1)
498void ev_signal_stop (struct ev_signal *w) 508void ev_signal_stop (struct ev_signal *w)
499 509
500void DESTROY (struct ev_signal *w) 510void DESTROY (struct ev_signal *w)
501 CODE: 511 CODE:
502 ev_signal_stop (w); 512 ev_signal_stop (w);
513 e_destroy (w);
503 514
504void set (struct ev_signal *w, SV *signal = 0) 515void set (struct ev_signal *w, SV *signal = 0)
505 CODE: 516 CODE:
506{ 517{
507 Signal signum = sv_signum (signal); /* may croak here */ 518 Signal signum = sv_signum (signal); /* may croak here */
527 CHECK_REPEAT (w->repeat); 538 CHECK_REPEAT (w->repeat);
528 539
529void DESTROY (struct ev_timer *w) 540void DESTROY (struct ev_timer *w)
530 CODE: 541 CODE:
531 ev_timer_stop (w); 542 ev_timer_stop (w);
543 e_destroy (w);
532 544
533void set (struct ev_timer *w, NV after, NV repeat = 0.) 545void set (struct ev_timer *w, NV after, NV repeat = 0.)
534 INIT: 546 INIT:
535 CHECK_REPEAT (repeat); 547 CHECK_REPEAT (repeat);
536 CODE: 548 CODE:
550void ev_periodic_stop (struct ev_periodic *w) 562void ev_periodic_stop (struct ev_periodic *w)
551 563
552void DESTROY (struct ev_periodic *w) 564void DESTROY (struct ev_periodic *w)
553 CODE: 565 CODE:
554 ev_periodic_stop (w); 566 ev_periodic_stop (w);
567 e_destroy (w);
555 568
556void set (struct ev_periodic *w, NV at, NV interval = 0.) 569void set (struct ev_periodic *w, NV at, NV interval = 0.)
557 INIT: 570 INIT:
558 CHECK_REPEAT (interval); 571 CHECK_REPEAT (interval);
559 CODE: 572 CODE:
571void ev_idle_stop (struct ev_idle *w) 584void ev_idle_stop (struct ev_idle *w)
572 585
573void DESTROY (struct ev_idle *w) 586void DESTROY (struct ev_idle *w)
574 CODE: 587 CODE:
575 ev_idle_stop (w); 588 ev_idle_stop (w);
589 e_destroy (w);
576 590
577MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 591MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
578 592
579void ev_prepare_start (struct ev_prepare *w) 593void ev_prepare_start (struct ev_prepare *w)
580 594
581void ev_prepare_stop (struct ev_prepare *w) 595void ev_prepare_stop (struct ev_prepare *w)
582 596
583void DESTROY (struct ev_prepare *w) 597void DESTROY (struct ev_prepare *w)
584 CODE: 598 CODE:
585 ev_prepare_stop (w); 599 ev_prepare_stop (w);
600 e_destroy (w);
586 601
587MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ 602MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
588 603
589void ev_check_start (struct ev_check *w) 604void ev_check_start (struct ev_check *w)
590 605
591void ev_check_stop (struct ev_check *w) 606void ev_check_stop (struct ev_check *w)
592 607
593void DESTROY (struct ev_check *w) 608void DESTROY (struct ev_check *w)
594 CODE: 609 CODE:
595 ev_check_stop (w); 610 ev_check_stop (w);
611 e_destroy (w);
596 612
597MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 613MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
598 614
599void ev_child_start (struct ev_child *w) 615void ev_child_start (struct ev_child *w)
600 616
601void ev_child_stop (struct ev_child *w) 617void ev_child_stop (struct ev_child *w)
602 618
603void DESTROY (struct ev_child *w) 619void DESTROY (struct ev_child *w)
604 CODE: 620 CODE:
605 ev_child_stop (w); 621 ev_child_stop (w);
622 e_destroy (w);
606 623
607void set (struct ev_child *w, int pid) 624void set (struct ev_child *w, int pid)
608 CODE: 625 CODE:
609{ 626{
610 int active = w->active; 627 int active = w->active;
616int status (struct ev_child *w) 633int status (struct ev_child *w)
617 CODE: 634 CODE:
618 RETVAL = w->status; 635 RETVAL = w->status;
619 OUTPUT: 636 OUTPUT:
620 RETVAL 637 RETVAL
621
622#if 0
623 638
624MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 639MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
625 640
626BOOT: 641BOOT:
627{ 642{
710 725
711void evdns_search_add (char *domain) 726void evdns_search_add (char *domain)
712 727
713void evdns_search_ndots_set (int ndots) 728void evdns_search_ndots_set (int ndots)
714 729
730#if 0
715 731
716MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 732MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
717 733
718BOOT: 734BOOT:
719{ 735{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines