… | |
… | |
32 | our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; |
32 | our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; |
33 | |
33 | |
34 | our $wait_factor = 0.95; |
34 | our $wait_factor = 0.95; |
35 | |
35 | |
36 | our @transfers = ( |
36 | our @transfers = ( |
37 | [(new Coro::Semaphore $MAX_TRANSFERS_SMALL || 50), 600], |
37 | [(new Coro::Semaphore $MAX_TRANSFERS_SMALL || 50), 1], |
38 | [(new Coro::Semaphore $MAX_TRANSFERS_LARGE || 50), 600], |
38 | [(new Coro::Semaphore $MAX_TRANSFERS_LARGE || 50), 1], |
39 | ); |
39 | ); |
40 | |
40 | |
41 | my @newcons; |
41 | my @newcons; |
42 | my @pool; |
42 | my @pool; |
43 | |
43 | |
… | |
… | |
193 | sub err { |
193 | sub err { |
194 | my $self = shift; |
194 | my $self = shift; |
195 | my ($code, $msg, $hdr, $content) = @_; |
195 | my ($code, $msg, $hdr, $content) = @_; |
196 | |
196 | |
197 | unless (defined $content) { |
197 | unless (defined $content) { |
198 | $content = "$code $msg"; |
198 | $content = "$code $msg\n"; |
199 | $hdr->{"Content-Type"} = "text/plain"; |
199 | $hdr->{"Content-Type"} = "text/plain"; |
200 | $hdr->{"Content-Length"} = length $content; |
200 | $hdr->{"Content-Length"} = length $content; |
201 | } |
201 | } |
202 | $hdr->{"Connection"} = "close"; |
202 | $hdr->{"Connection"} = "close"; |
203 | |
203 | |
… | |
… | |
452 | } |
452 | } |
453 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h >= $l; |
453 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h >= $l; |
454 | } |
454 | } |
455 | $hdr->{"Content-Range"} = "bytes */$length"; |
455 | $hdr->{"Content-Range"} = "bytes */$length"; |
456 | $hdr->{"Content-Length"} = $length; |
456 | $hdr->{"Content-Length"} = $length; |
457 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
|
|
458 | $self->err(416, "not satisfiable", $hdr, ""); |
457 | $self->err(416, "not satisfiable", $hdr, ""); |
459 | |
458 | |
460 | satisfiable: |
459 | satisfiable: |
461 | # check for segmented downloads |
460 | # check for segmented downloads |
462 | if ($l && $::NO_SEGMENTED) { |
461 | if ($l && $::NO_SEGMENTED) { |
… | |
… | |
486 | $self->response(@code, $hdr, ""); |
485 | $self->response(@code, $hdr, ""); |
487 | |
486 | |
488 | if ($self->{method} eq "GET") { |
487 | if ($self->{method} eq "GET") { |
489 | $self->{time} = $::NOW; |
488 | $self->{time} = $::NOW; |
490 | |
489 | |
|
|
490 | my $fudge = $queue->[0]->waiters; |
|
|
491 | $fudge = $fudge ? ($fudge+1)/$fudge : 1; |
|
|
492 | |
|
|
493 | $queue->[1] *= $fudge; |
491 | my $transfer = $queue->[0]->guard; |
494 | my $transfer = $queue->[0]->guard; |
|
|
495 | |
|
|
496 | if ($fudge != 1) { |
|
|
497 | $queue->[1] /= $fudge; |
|
|
498 | $queue->[1] = $queue->[1] * $::wait_factor |
|
|
499 | + ($::NOW - $self->{time}) * (1 - $::wait_factor); |
|
|
500 | } |
|
|
501 | $self->{time} = $::NOW; |
|
|
502 | |
492 | $self->{fh}->writable or return; |
503 | $self->{fh}->writable or return; |
493 | |
|
|
494 | $queue->[1] = $queue->[1] * $::wait_factor |
|
|
495 | + ($::NOW - $self->{time}) * (1 - $::wait_factor); |
|
|
496 | $self->{time} = $::NOW; |
|
|
497 | |
504 | |
498 | my ($fh, $buf, $r); |
505 | my ($fh, $buf, $r); |
499 | my $current = $Coro::current; |
506 | my $current = $Coro::current; |
500 | open $fh, "<", $self->{path} |
507 | open $fh, "<", $self->{path} |
501 | or die "$self->{path}: late open failure ($!)"; |
508 | or die "$self->{path}: late open failure ($!)"; |