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.64 by root, Wed Jan 23 04:49:50 2002 UTC vs.
Revision 1.67 by root, Sun May 19 21:00:47 2002 UTC

54our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; 54our $connections = new Coro::Semaphore $MAX_CONNECTS || 250;
55our $httpevent = new Coro::Signal; 55our $httpevent = new Coro::Signal;
56 56
57our $queue_file = new transferqueue $MAX_TRANSFERS; 57our $queue_file = new transferqueue $MAX_TRANSFERS;
58our $queue_index = new transferqueue 10; 58our $queue_index = new transferqueue 10;
59
60our $tbf_top = new tbf rate => 200000;
59 61
60my @newcons; 62my @newcons;
61my @pool; 63my @pool;
62 64
63# one "execution thread" 65# one "execution thread"
225 } 227 }
226 $res .= "\015\012"; 228 $res .= "\015\012";
227 229
228 $res .= $content if defined $content and $self->{method} ne "HEAD"; 230 $res .= $content if defined $content and $self->{method} ne "HEAD";
229 231
230 my $log = (POSIX::strftime "%Y-%m-%d %H:%M:%S", gmtime $NOW). 232 my $log = (POSIX::strftime "%Y-%m-%d %H:%M:%S", gmtime $::NOW).
231 " $self->{remote_id} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}.$GZ. 233 " $self->{remote_id} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}.$GZ.
232 " \"$self->{h}{referer}\"\n"; 234 " \"$self->{h}{referer}\"\n";
233 235
234 print $accesslog $log if $accesslog; 236 print $::accesslog $log if $::accesslog;
235 print STDERR $log; 237 print STDERR $log;
236 238
237 $self->{written} += 239 $tbf_top->request(length $res, 1e6);
238 print {$self->{fh}} $res; 240 $self->{written} += print {$self->{fh}} $res;
239} 241}
240 242
241sub err { 243sub err {
242 my $self = shift; 244 my $self = shift;
243 my ($code, $msg, $hdr, $content) = @_; 245 my ($code, $msg, $hdr, $content) = @_;
298 my (%hdr, $h, $v); 300 my (%hdr, $h, $v);
299 301
300 $hdr{lc $1} .= ",$2" 302 $hdr{lc $1} .= ",$2"
301 while $req =~ /\G 303 while $req =~ /\G
302 ([^:\000-\040]+): 304 ([^:\000-\040]+):
303 [\010\040]* 305 [\011\040]*
304 ((?: [^\015\012]+ | \015\012[\010\040] )*) 306 ((?: [^\015\012]+ | \015\012[\011\040] )*)
305 \015\012 307 \015\012
306 /gxc; 308 /gxc;
307 309
308 $req =~ /\G\015\012$/ 310 $req =~ /\G\015\012$/
309 or $self->err(400, "bad request"); 311 or $self->err(400, "bad request");
457 or $self->err(304, "not modified"); 459 or $self->err(304, "not modified");
458 460
459 if (-r "$path/index.html") { 461 if (-r "$path/index.html") {
460 # replace directory "size" by index.html filesize 462 # replace directory "size" by index.html filesize
461 $self->{stat} = [stat ($self->{path} .= "/index.html")]; 463 $self->{stat} = [stat ($self->{path} .= "/index.html")];
462 $self->handle_file($queue_index); 464 $self->handle_file($queue_index, $tbf_top);
463 } else { 465 } else {
464 $self->handle_dir; 466 $self->handle_dir;
465 } 467 }
466 } 468 }
467 } elsif (-f _ && -r _) { 469 } elsif (-f _ && -r _) {
476 $httpevent->wait; 478 $httpevent->wait;
477 } 479 }
478 } 480 }
479 } 481 }
480 482
481 $self->handle_file($queue_file); 483 $self->handle_file($queue_file, $tbf_top);
482 } else { 484 } else {
483 $self->err(404, "not found"); 485 $self->err(404, "not found");
484 } 486 }
485 } 487 }
486} 488}
497 }, 499 },
498 $idx); 500 $idx);
499} 501}
500 502
501sub handle_file { 503sub handle_file {
502 my ($self, $queue) = @_; 504 my ($self, $queue, $tbf) = @_;
503 my $length = $self->{stat}[7]; 505 my $length = $self->{stat}[7];
504 my $hdr = { 506 my $hdr = {
505 "Last-Modified" => time2str ((stat _)[9]), 507 "Last-Modified" => time2str ((stat _)[9]),
506 }; 508 };
507 509
598 Coro::ready($current); 600 Coro::ready($current);
599 }); 601 });
600 &Coro::schedule; 602 &Coro::schedule;
601 last unless $r; 603 last unless $r;
602 } 604 }
605
606 $tbf->request(length $buf);
603 my $w = syswrite $self->{fh}, $buf 607 my $w = syswrite $self->{fh}, $buf
604 or last; 608 or last;
605 $::written += $w; 609 $::written += $w;
606 $self->{written} += $w; 610 $self->{written} += $w;
607 $l += $r; 611 $l += $r;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines