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.57 by root, Mon Dec 3 05:40:09 2001 UTC vs.
Revision 1.62 by root, Sun Jan 6 05:29:39 2002 UTC

50} 50}
51 51
52our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; 52our $connections = new Coro::Semaphore $MAX_CONNECTS || 250;
53our $httpevent = new Coro::Signal; 53our $httpevent = new Coro::Signal;
54 54
55our $queue_file = new transferqueue $MAX_TRANSFERS; 55our $queue_file = new transferqueue slots => $MAX_TRANSFERS, maxsize => 250_000_000;
56our $queue_index = new transferqueue 10; 56our $queue_index = new transferqueue slots => 10;
57
58our $requests;
57 59
58my @newcons; 60my @newcons;
59my @pool; 61my @pool;
60 62
61# one "execution thread" 63# one "execution thread"
161 my (undef, $iaddr) = unpack_sockaddr_in $peername 163 my (undef, $iaddr) = unpack_sockaddr_in $peername
162 or $self->err(500, "unable to decode peername"); 164 or $self->err(500, "unable to decode peername");
163 165
164 $self->{remote_addr} = 166 $self->{remote_addr} =
165 $self->{remote_id} = inet_ntoa $iaddr; 167 $self->{remote_id} = inet_ntoa $iaddr;
168
166 $self->{time} = $::NOW; 169 $self->{time} = $::NOW;
167 170
168 weaken ($Coro::current->{conn} = $self); 171 weaken ($Coro::current->{conn} = $self);
169 172
170 $::conns++; 173 $::conns++;
292 or $self->err(400, "bad request"); 295 or $self->err(400, "bad request");
293 296
294 $self->{h}{$h} = substr $v, 1 297 $self->{h}{$h} = substr $v, 1
295 while ($h, $v) = each %hdr; 298 while ($h, $v) = each %hdr;
296 } 299 }
300
301 $requests++;
297 302
298 # remote id should be unique per user 303 # remote id should be unique per user
299 my $id = $self->{remote_addr}; 304 my $id = $self->{remote_addr};
300 305
301 if (exists $self->{h}{"client-ip"}) { 306 if (exists $self->{h}{"client-ip"}) {
448 } 453 }
449 } 454 }
450 } elsif (-f _ && -r _) { 455 } elsif (-f _ && -r _) {
451 -x _ and $self->err(403, "forbidden"); 456 -x _ and $self->err(403, "forbidden");
452 457
453 if (%{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) { 458 if (keys %{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) {
454 my $timeout = $::NOW + 10; 459 my $timeout = $::NOW + 10;
455 while (%{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) { 460 while (keys %{$conn{$self->{remote_id}}} > $::MAX_TRANSFERS_IP) {
456 if ($timeout < $::NOW) { 461 if ($timeout < $::NOW) {
457 $self->block($::BLOCKTIME, "too many connections"); 462 $self->block($::BLOCKTIME, "too many connections");
458 } else { 463 } else {
459 $httpevent->wait; 464 $httpevent->wait;
460 } 465 }
509 514
510satisfiable: 515satisfiable:
511 # check for segmented downloads 516 # check for segmented downloads
512 if ($l && $::NO_SEGMENTED) { 517 if ($l && $::NO_SEGMENTED) {
513 my $timeout = $::NOW + 15; 518 my $timeout = $::NOW + 15;
514 while (%{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { 519 while (keys %{$uri{$self->{remote_id}}{$self->{uri}}} > 1) {
515 if ($timeout <= $::NOW) { 520 if ($timeout <= $::NOW) {
516 $self->block($::BLOCKTIME, "segmented downloads are forbidden"); 521 $self->block($::BLOCKTIME, "segmented downloads are forbidden");
517 #$self->err_segmented_download; 522 #$self->err_segmented_download;
518 } else { 523 } else {
519 $httpevent->wait; 524 $httpevent->wait;
566 } 571 }
567 } 572 }
568 573
569 if ($blocked{$self->{remote_id}}) { 574 if ($blocked{$self->{remote_id}}) {
570 $self->{h}{connection} = "close"; 575 $self->{h}{connection} = "close";
571 die bless {}, err:: 576 die bless {}, err::;
572 } 577 }
573 578
574 if (0) { # !AIO 579 if (0) { # !AIO
575 sysread $fh, $buf, $h > $bufsize ? $bufsize : $h 580 sysread $fh, $buf, $h > $bufsize ? $bufsize : $h
576 or last; 581 or last;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines