… | |
… | |
77 | Linux::AIO::min_parallel $::AIO_PARALLEL; |
77 | Linux::AIO::min_parallel $::AIO_PARALLEL; |
78 | |
78 | |
79 | Event->io(fd => Linux::AIO::poll_fileno, |
79 | Event->io(fd => Linux::AIO::poll_fileno, |
80 | poll => 'r', async => 1, |
80 | poll => 'r', async => 1, |
81 | cb => \&Linux::AIO::poll_cb); |
81 | cb => \&Linux::AIO::poll_cb); |
82 | my $scheduler = Event->idle( |
|
|
83 | max => 0, min => 0, prio => 6, parked => 1, |
|
|
84 | cb => \&Coro::schedule); |
|
|
85 | |
82 | |
86 | our %conn; # $conn{ip}{fh} => connobj |
83 | our %conn; # $conn{ip}{fh} => connobj |
87 | our %blocked; |
84 | our %blocked; |
88 | our %mimetype; |
85 | our %mimetype; |
89 | |
86 | |
… | |
… | |
274 | |
271 | |
275 | $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80; |
272 | $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80; |
276 | |
273 | |
277 | weaken ($uri{$self->{remote_addr}}{$self->{uri}}{$self*1} = $self); |
274 | weaken ($uri{$self->{remote_addr}}{$self->{uri}}{$self*1} = $self); |
278 | |
275 | |
|
|
276 | eval { |
279 | $self->map_uri; |
277 | $self->map_uri; |
280 | $self->respond; |
278 | $self->respond; |
|
|
279 | }; |
|
|
280 | |
|
|
281 | die if $@ && !ref $@; |
281 | |
282 | |
282 | $self->eoconn; |
283 | $self->eoconn; |
283 | |
284 | |
284 | last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1"; |
285 | last if $self->{h}{connection} =~ /close/ || $self->{version} lt "1.1"; |
285 | |
286 | |
… | |
… | |
432 | goto ignore; |
433 | goto ignore; |
433 | } |
434 | } |
434 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; |
435 | goto satisfiable if $l >= 0 && $l < $length && $h >= 0 && $h > $l; |
435 | } |
436 | } |
436 | $hdr->{"Content-Range"} = "bytes */$length"; |
437 | $hdr->{"Content-Range"} = "bytes */$length"; |
|
|
438 | $hdr->{"Content-Length"} = $length; |
437 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
439 | $self->slog(9, "not satisfiable($self->{h}{range}|".$self->{h}{"user-agent"}.")"); |
438 | $self->err(416, "not satisfiable", $hdr); |
440 | $self->err(416, "not satisfiable", $hdr, ""); |
439 | |
441 | |
440 | satisfiable: |
442 | satisfiable: |
441 | # check for segmented downloads |
443 | # check for segmented downloads |
442 | if ($l && $::NO_SEGMENTED) { |
444 | if ($l && $::NO_SEGMENTED) { |
443 | if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |
445 | if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |
… | |
… | |
483 | } else { |
485 | } else { |
484 | aio_read($fh, $l, ($h > $::BUFSIZE ? $::BUFSIZE : $h), |
486 | aio_read($fh, $l, ($h > $::BUFSIZE ? $::BUFSIZE : $h), |
485 | $buf, 0, sub { |
487 | $buf, 0, sub { |
486 | $r = $_[0]; |
488 | $r = $_[0]; |
487 | $current->ready; |
489 | $current->ready; |
488 | $scheduler->now; |
|
|
489 | }); |
490 | }); |
490 | &Coro::schedule; |
491 | &Coro::schedule; |
491 | last unless $r; |
492 | last unless $r; |
492 | } |
493 | } |
493 | my $w = $self->{fh}->syswrite($buf) |
494 | my $w = $self->{fh}->syswrite($buf) |