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

Comparing cvsroot/Coro/myhttpd/httpd.pl (file contents):
Revision 1.36 by root, Sun Sep 2 00:54:00 2001 UTC vs.
Revision 1.38 by root, Sun Sep 2 02:27:51 2001 UTC

42my @pool; 42my @pool;
43 43
44# one "execution thread" 44# one "execution thread"
45sub handler { 45sub handler {
46 while () { 46 while () {
47 my $new = pop @newcons;
48 if ($new) { 47 if (@newcons) {
49 eval { 48 eval {
50 conn->new(@$new)->handle; 49 conn->new(@{pop @newcons})->handle;
51 }; 50 };
52 slog 1, "$@" if $@ && !ref $@; 51 slog 1, "$@" if $@ && !ref $@;
53 $connections->up; 52 $connections->up;
54 } else { 53 } else {
55 last if @pool >= $MAX_POOL; 54 last if @pool >= $MAX_POOL;
99use Convert::Scalar 'weaken'; 98use Convert::Scalar 'weaken';
100use Linux::AIO; 99use Linux::AIO;
101 100
102Linux::AIO::min_parallel $::AIO_PARALLEL; 101Linux::AIO::min_parallel $::AIO_PARALLEL;
103 102
104my $aio_requests = new Coro::Semaphore $::AIO_PARALLEL * 4;
105
106Event->io(fd => Linux::AIO::poll_fileno, 103Event->io(fd => Linux::AIO::poll_fileno,
107 poll => 'r', async => 1, 104 poll => 'r', async => 1,
108 cb => \&Linux::AIO::poll_cb); 105 cb => \&Linux::AIO::poll_cb);
109 106
110our %conn; # $conn{ip}{self} => connobj 107our %conn; # $conn{ip}{self} => connobj
519 while ($h > 0) { 516 while ($h > 0) {
520 if (0) { 517 if (0) {
521 sysread $fh, $buf, $h > $::BUFSIZE ? $::BUFSIZE : $h 518 sysread $fh, $buf, $h > $::BUFSIZE ? $::BUFSIZE : $h
522 or last; 519 or last;
523 } else { 520 } else {
524 undef $buf;
525 $aio_requests->down;
526 aio_read($fh, $l, ($h > $::BUFSIZE ? $::BUFSIZE : $h), 521 aio_read($fh, $l, ($h > $::BUFSIZE ? $::BUFSIZE : $h),
527 $buf, 0, sub { 522 $buf, 0, sub {
528 $r = $_[0]; 523 $r = $_[0];
529 $current->ready; 524 Coro::ready($current);
530 }); 525 });
531 &Coro::schedule; 526 &Coro::schedule;
532 $aio_requests->up;
533 last unless $r; 527 last unless $r;
534 } 528 }
535 my $w = $self->{fh}->syswrite($buf) 529 my $w = syswrite $self->{fh}, $buf
536 or last; 530 or last;
537 $::written += $w; 531 $::written += $w;
538 $self->{written} += $w; 532 $self->{written} += $w;
539 $l += $r; 533 $l += $r;
540 } 534 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines