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.21 by root, Fri Aug 17 03:33:00 2001 UTC vs.
Revision 1.25 by root, Sun Aug 19 22:14:26 2001 UTC

77Linux::AIO::min_parallel $::AIO_PARALLEL; 77Linux::AIO::min_parallel $::AIO_PARALLEL;
78 78
79Event->io(fd => Linux::AIO::poll_fileno, 79Event->io(fd => Linux::AIO::poll_fileno,
80 poll => 'r', async => 1, 80 poll => 'r', async => 1,
81 cb => \&Linux::AIO::poll_cb); 81 cb => \&Linux::AIO::poll_cb);
82my $scheduler = Event->idle(
83 max => 0, min => 0, prio => 6, parked => 1,
84 cb => \&Coro::schedule);
85 82
86our %conn; # $conn{ip}{fh} => connobj 83our %conn; # $conn{ip}{fh} => connobj
87our %blocked; 84our %blocked;
88our %mimetype; 85our %mimetype;
89 86
152 } 149 }
153 $res .= "\015\012"; 150 $res .= "\015\012";
154 151
155 $res .= $content if defined $content and $self->{method} ne "HEAD"; 152 $res .= $content if defined $content and $self->{method} ne "HEAD";
156 153
157 print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";#d# 154 print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";
158 155
159 $self->{written} += 156 $self->{written} +=
160 print {$self->{fh}} $res; 157 print {$self->{fh}} $res;
161} 158}
162 159
274 271
275 $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80; 272 $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80;
276 273
277 weaken ($uri{$self->{remote_addr}}{$self->{uri}}{$self*1} = $self); 274 weaken ($uri{$self->{remote_addr}}{$self->{uri}}{$self*1} = $self);
278 275
276 eval {
279 $self->map_uri; 277 $self->map_uri;
280 $self->respond; 278 $self->respond;
279 };
280
281 die if $@ && !ref $@;
281 282
282 $self->eoconn; 283 $self->eoconn;
283 284
284 last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1"; 285 last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1";
285 286
380 $self->err(301, "moved permanently", { Location => "http://$host$self->{uri}/" }); 381 $self->err(301, "moved permanently", { Location => "http://$host$self->{uri}/" });
381 } else { 382 } else {
382 $ims < $self->{stat}[9] 383 $ims < $self->{stat}[9]
383 or $self->err(304, "not modified"); 384 or $self->err(304, "not modified");
384 385
385 if ($self->{method} eq "GET") {
386 if (-r "$path/index.html") { 386 if (-r "$path/index.html") {
387 $self->{path} .= "/index.html"; 387 $self->{path} .= "/index.html";
388 $self->handle_file; 388 $self->handle_file;
389 } else { 389 } else {
390 $self->handle_dir; 390 $self->handle_dir;
391 }
392 } 391 }
393 } 392 }
394 } elsif (-f _ && -r _) { 393 } elsif (-f _ && -r _) {
395 -x _ and $self->err(403, "forbidden"); 394 -x _ and $self->err(403, "forbidden");
396 $self->handle_file; 395 $self->handle_file;
432 goto ignore; 431 goto ignore;
433 } 432 }
434 goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; 433 goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l;
435 } 434 }
436 $hdr->{"Content-Range"} = "bytes */$length"; 435 $hdr->{"Content-Range"} = "bytes */$length";
436 $hdr->{"Content-Length"} = $length;
437 $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); 437 $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")");
438 $self->err(416, "not satisfiable", $hdr); 438 $self->err(416, "not satisfiable", $hdr, "");
439 439
440satisfiable: 440satisfiable:
441 # check for segmented downloads 441 # check for segmented downloads
442 if ($l && $::NO_SEGMENTED) { 442 if ($l && $::NO_SEGMENTED) {
443 if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { 443 if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) {
483 } else { 483 } else {
484 aio_read($fh, $l, ($h > $::BUFSIZE ? $::BUFSIZE : $h), 484 aio_read($fh, $l, ($h > $::BUFSIZE ? $::BUFSIZE : $h),
485 $buf, 0, sub { 485 $buf, 0, sub {
486 $r = $_[0]; 486 $r = $_[0];
487 $current->ready; 487 $current->ready;
488 $scheduler->now;
489 }); 488 });
490 &Coro::schedule; 489 &Coro::schedule;
491 last unless $r; 490 last unless $r;
492 } 491 }
493 my $w = $self->{fh}->syswrite($buf) 492 my $w = $self->{fh}->syswrite($buf)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines