ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/httpd.pl
(Generate patch)

Comparing Coro/myhttpd/httpd.pl (file contents):
Revision 1.78 by root, Sun Dec 4 19:36:28 2005 UTC vs.
Revision 1.79 by root, Fri Dec 1 03:53:33 2006 UTC

1use Coro; 1use Coro;
2use Coro::Semaphore; 2use Coro::Semaphore;
3use Coro::Event; 3use Coro::Event;
4use Coro::Socket; 4use Coro::Socket;
5use Coro::Signal; 5use Coro::Signal;
6use Coro::AIO ();
6 7
7use HTTP::Date; 8use HTTP::Date;
8use POSIX (); 9use POSIX ();
9 10
10use Compress::Zlib (); 11use Compress::Zlib ();
143use Convert::Scalar 'weaken'; 144use Convert::Scalar 'weaken';
144use IO::AIO; 145use IO::AIO;
145 146
146IO::AIO::min_parallel $::AIO_PARALLEL; 147IO::AIO::min_parallel $::AIO_PARALLEL;
147 148
148Event->io(fd => IO::AIO::poll_fileno, 149Event->io (fd => IO::AIO::poll_fileno,
149 poll => 'r', async => 1, 150 poll => 'r', async => 1,
150 cb => \&IO::AIO::poll_cb); 151 cb => \&IO::AIO::poll_cb);
151 152
152our %conn; # $conn{ip}{self} => connobj 153our %conn; # $conn{ip}{self} => connobj
153our %uri; # $uri{ip}{uri}{self} 154our %uri; # $uri{ip}{uri}{self}
154our %blocked; 155our %blocked;
155our %mimetype; 156our %mimetype;
629 if ($blocked{$self->{remote_id}}) { 630 if ($blocked{$self->{remote_id}}) {
630 $self->{h}{connection} = "close"; 631 $self->{h}{connection} = "close";
631 die bless {}, err::; 632 die bless {}, err::;
632 } 633 }
633 634
634 if (0) { # !AIO 635 Coro::AIO::aio_read $fh, $l, ($h > $bufsize ? $bufsize : $h), $buf, 0
635 sysread $fh, $buf, $h > $bufsize ? $bufsize : $h
636 or last; 636 or last;
637 } else {
638 aio_read($fh, $l, ($h > $bufsize ? $bufsize : $h),
639 $buf, 0, sub {
640 $r = $_[0];
641 Coro::ready($current);
642 });
643 &Coro::schedule;
644 last unless $r;
645 }
646 637
647 $tbf->request(length $buf); 638 $tbf->request (length $buf);
648 my $w = syswrite $self->{fh}, $buf 639 my $w = syswrite $self->{fh}, $buf
649 or last; 640 or last;
650 $::written += $w; 641 $::written += $w;
651 $self->{written} += $w; 642 $self->{written} += $w;
652 $l += $r; 643 $l += $r;
655 close $fh; 646 close $fh;
656 } 647 }
657} 648}
658 649
6591 6501
651

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines