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.71 by root, Mon Jul 29 21:41:54 2002 UTC vs.
Revision 1.77 by root, Sat Sep 17 20:21:11 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 => 100000; 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
140package conn; 139package conn;
141 140
142use Socket; 141use Socket;
143use HTTP::Date; 142use HTTP::Date;
144use Convert::Scalar 'weaken'; 143use Convert::Scalar 'weaken';
145use Linux::AIO; 144use IO::AIO;
146 145
147Linux::AIO::min_parallel $::AIO_PARALLEL; 146IO::AIO::min_parallel $::AIO_PARALLEL;
148 147
149Event->io(fd => Linux::AIO::poll_fileno, 148Event->io(fd => IO::AIO::poll_fileno,
150 poll => 'r', async => 1, 149 poll => 'r', async => 1,
151 cb => \&Linux::AIO::poll_cb); 150 cb => \&IO::AIO::poll_cb);
152 151
153our %conn; # $conn{ip}{self} => connobj 152our %conn; # $conn{ip}{self} => connobj
154our %uri; # $uri{ip}{uri}{self} 153our %uri; # $uri{ip}{uri}{self}
155our %blocked; 154our %blocked;
156our %mimetype; 155our %mimetype;
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}
505 my $self = shift; 529 my $self = shift;
506 my $idx = $self->diridx; 530 my $idx = $self->diridx;
507 531
508 $self->response(200, "ok", 532 $self->response(200, "ok",
509 { 533 {
510 "Content-Type" => "text/html", 534 "Content-Type" => "text/html; charset=utf-8",
511 "Content-Length" => length $idx, 535 "Content-Length" => length $idx,
512 "Last-Modified" => time2str ($self->{stat}[9]), 536 "Last-Modified" => time2str ($self->{stat}[9]),
513 }, 537 },
514 $idx); 538 $idx);
515} 539}
516 540
517sub handle_file { 541sub handle_file {
518 my ($self, $queue, $tbf) = @_; 542 my ($self, $queue, $tbf) = @_;
519 my $length = $self->{stat}[7]; 543 my $length = $self->{stat}[7];
520 my $hdr = { 544 my $hdr = {
521 "Last-Modified" => time2str ((stat _)[9]), 545 "Last-Modified" => time2str ((stat _)[9]),
546 "Accept-Ranges" => "bytes",
522 }; 547 };
523 548
524 my @code = (200, "ok"); 549 my @code = (200, "ok");
525 my ($l, $h); 550 my ($l, $h);
526 551

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines