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.43 by root, Wed Sep 12 20:29:43 2001 UTC vs.
Revision 1.44 by root, Fri Sep 14 12:38:18 2001 UTC

1use Coro; 1use Coro;
2use Coro::Semaphore; 2use Coro::Semaphore;
3use Coro::Event; 3use Coro::Event;
4use Coro::Socket; 4use Coro::Socket;
5use Coro::Signal;
5 6
6use HTTP::Date; 7use HTTP::Date;
7 8
8no utf8; 9no utf8;
9use bytes; 10use bytes;
28 my $format = shift; 29 my $format = shift;
29 printf "---: $format\n", @_; 30 printf "---: $format\n", @_;
30} 31}
31 32
32our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; 33our $connections = new Coro::Semaphore $MAX_CONNECTS || 250;
34our $httpevent = new Coro::Signal;
33 35
34our $wait_factor = 0.95; 36our $wait_factor = 0.95;
35 37
36our @transfers = ( 38our @transfers = (
37 [(new Coro::Semaphore $MAX_TRANSFERS_SMALL || 50), 1], 39 [(new Coro::Semaphore $MAX_TRANSFERS_SMALL || 50), 1],
168 my $self = shift; 170 my $self = shift;
169 171
170 # clean up hints 172 # clean up hints
171 delete $conn{$self->{remote_id}}{$self*1}; 173 delete $conn{$self->{remote_id}}{$self*1};
172 delete $uri{$self->{remote_id}}{$self->{uri}}{$self*1}; 174 delete $uri{$self->{remote_id}}{$self->{uri}}{$self*1};
175
176 $httpevent->broadcast;
173} 177}
174 178
175sub slog { 179sub slog {
176 my $self = shift; 180 my $self = shift;
177 main::slog($_[0], ($self->{remote_id} || $self->{remote_addr}) ."> $_[1]"); 181 main::slog($_[0], ($self->{remote_id} || $self->{remote_addr}) ."> $_[1]");
292 296
293 delete $blocked{$id}; 297 delete $blocked{$id};
294 } 298 }
295 299
296 if (%{$conn{$id}} >= $::MAX_CONN_IP) { 300 if (%{$conn{$id}} >= $::MAX_CONN_IP) {
297 my $delay = $::PER_TIMEOUT + 15; 301 my $delay = $::PER_TIMEOUT + $::NOW + 15;
298 while (%{$conn{$id}} >= $::MAX_CONN_IP) { 302 while (%{$conn{$id}} >= $::MAX_CONN_IP) {
299 if ($delay <= 0) { 303 if ($delay < $::NOW) {
300 $self->slog(2, "blocked ip $id"); 304 $self->slog(2, "blocked ip $id");
301 $self->err_blocked; 305 $self->err_blocked;
302 } else { 306 } else {
303 Coro::Event::do_timer(after => 4); $delay -= 4; 307 $httpevent->wait;
304 } 308 }
305 } 309 }
306 } 310 }
307 311
308 # find out server name and port 312 # find out server name and port
335 $self->eoconn; 339 $self->eoconn;
336 340
337 die if $@ && !ref $@; 341 die if $@ && !ref $@;
338 342
339 last if $self->{h}{connection} =~ /close/ || $self->{version} < 1.1; 343 last if $self->{h}{connection} =~ /close/ || $self->{version} < 1.1;
344
345 $httpevent->broadcast;
340 346
341 $fh->timeout($::PER_TIMEOUT); 347 $fh->timeout($::PER_TIMEOUT);
342 } 348 }
343} 349}
344 350
470 $self->err(416, "not satisfiable", $hdr, ""); 476 $self->err(416, "not satisfiable", $hdr, "");
471 477
472satisfiable: 478satisfiable:
473 # check for segmented downloads 479 # check for segmented downloads
474 if ($l && $::NO_SEGMENTED) { 480 if ($l && $::NO_SEGMENTED) {
475 my $delay = $::PER_TIMEOUT + 15; 481 my $delay = $::NOW + $::PER_TIMEOUT + 15;
476 while (%{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { 482 while (%{$uri{$self->{remote_id}}{$self->{uri}}} > 1) {
477 if ($delay <= 0) { 483 if ($delay <= $::NOW) {
478 $self->err_segmented_download; 484 $self->err_segmented_download;
479 } else { 485 } else {
480 Coro::Event::do_timer(after => 4); $delay -= 4; 486 $httpevent->broadcast;
481 } 487 }
482 } 488 }
483 } 489 }
484 490
485 $hdr->{"Content-Range"} = "bytes $l-$h/$length"; 491 $hdr->{"Content-Range"} = "bytes $l-$h/$length";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines