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.68 by root, Mon May 20 04:08:03 2002 UTC vs.
Revision 1.76 by root, Wed Jul 13 13:58:51 2005 UTC

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 59
60our $tbf_top = new tbf rate => 200000; 60our $tbf_top = new tbf rate => $TBF_RATE || 100000;
61 61
62my $unused_bytes = 0; 62my $unused_bytes = 0;
63my $unused_last = time; 63my $unused_last = time;
64 64
65sub unused_bandwidth { 65sub unused_bandwidth {
110 if (@pool) { 110 if (@pool) {
111 (pop @pool)->ready; 111 (pop @pool)->ready;
112 } else { 112 } else {
113 async \&handler; 113 async \&handler;
114 } 114 }
115
116 } 115 }
117 }; 116 };
118} 117}
119 118
120my $http_port = new Coro::Socket 119my $http_port = new Coro::Socket
193 192
194sub DESTROY { 193sub DESTROY {
195 #my $self = shift; 194 #my $self = shift;
196 $::conns--; 195 $::conns--;
197} 196}
197
198sub prune_cache {
199 my $hash = $_[0];
200
201 for (keys %$hash) {
202 if (ref $hash->{$_} eq HASH::) {
203 prune_cache($hash->{$_});
204 unless (scalar keys %{$hash->{$_}}) {
205 delete $hash->{$_};
206 $d2++;
207 }
208 }
209 }
210}
211
212sub prune_caches {
213 prune_cache \%conn;
214 prune_cache \%uri;
215
216 for (keys %blocked) {
217 delete $blocked{$_} unless $blocked{$_}[0] > $::NOW;
218 }
219}
220
221Event->timer(interval => 60, cb => \&prune_caches);
198 222
199sub slog { 223sub slog {
200 my $self = shift; 224 my $self = shift;
201 main::slog($_[0], "$self->{remote_id}> $_[1]"); 225 main::slog($_[0], "$self->{remote_id}> $_[1]");
202} 226}
232 $hdr->{"Content-Length"} = length $content; 256 $hdr->{"Content-Length"} = length $content;
233 $GZ = sprintf "GZ%02d", 100 - 100*((length $content) / $orig); 257 $GZ = sprintf "GZ%02d", 100 - 100*((length $content) / $orig);
234 } 258 }
235 259
236 $res .= "Date: $HTTP_NOW\015\012"; 260 $res .= "Date: $HTTP_NOW\015\012";
261 $res .= "Server: $::NAME\015\012";
237 262
238 while (my ($h, $v) = each %$hdr) { 263 while (my ($h, $v) = each %$hdr) {
239 $res .= "$h: $v\015\012" 264 $res .= "$h: $v\015\012"
240 } 265 }
241 $res .= "\015\012"; 266 $res .= "\015\012";
504 my $self = shift; 529 my $self = shift;
505 my $idx = $self->diridx; 530 my $idx = $self->diridx;
506 531
507 $self->response(200, "ok", 532 $self->response(200, "ok",
508 { 533 {
509 "Content-Type" => "text/html", 534 "Content-Type" => "text/html; charset=utf-8",
510 "Content-Length" => length $idx, 535 "Content-Length" => length $idx,
511 "Last-Modified" => time2str ($self->{stat}[9]), 536 "Last-Modified" => time2str ($self->{stat}[9]),
512 }, 537 },
513 $idx); 538 $idx);
514} 539}
515 540
516sub handle_file { 541sub handle_file {
517 my ($self, $queue, $tbf) = @_; 542 my ($self, $queue, $tbf) = @_;
518 my $length = $self->{stat}[7]; 543 my $length = $self->{stat}[7];
519 my $hdr = { 544 my $hdr = {
520 "Last-Modified" => time2str ((stat _)[9]), 545 "Last-Modified" => time2str ((stat _)[9]),
546 "Accept-Ranges" => "bytes",
521 }; 547 };
522 548
523 my @code = (200, "ok"); 549 my @code = (200, "ok");
524 my ($l, $h); 550 my ($l, $h);
525 551
568 594
569 $self->response(@code, $hdr, ""); 595 $self->response(@code, $hdr, "");
570 596
571 if ($self->{method} eq "GET") { 597 if ($self->{method} eq "GET") {
572 $self->{time} = $::NOW; 598 $self->{time} = $::NOW;
599 $self->{written} = 0;
573 600
574 my $current = $Coro::current; 601 my $current = $Coro::current;
575 602
576 my ($fh, $buf, $r); 603 my ($fh, $buf, $r);
577 604
593 while ($h > 0) { 620 while ($h > 0) {
594 unless ($locked) { 621 unless ($locked) {
595 if ($locked ||= $transfer->try($::WAIT_INTERVAL)) { 622 if ($locked ||= $transfer->try($::WAIT_INTERVAL)) {
596 $bufsize = $::BUFSIZE; 623 $bufsize = $::BUFSIZE;
597 $self->{time} = $::NOW; 624 $self->{time} = $::NOW;
625 $self->{written} = 0;
598 } 626 }
599 } 627 }
600 628
601 if ($blocked{$self->{remote_id}}) { 629 if ($blocked{$self->{remote_id}}) {
602 $self->{h}{connection} = "close"; 630 $self->{h}{connection} = "close";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines