|
|
1 | use AnyEvent (); |
|
|
2 | |
1 | use Coro; |
3 | use Coro; |
2 | use Coro::Semaphore; |
4 | use Coro::Semaphore; |
3 | use Coro::SemaphoreSet; |
5 | use Coro::SemaphoreSet; |
4 | use Coro::EV; |
6 | use Coro::EV; |
5 | use Coro::Socket; |
7 | use Coro::Socket; |
… | |
… | |
136 | |
138 | |
137 | use Socket; |
139 | use Socket; |
138 | use HTTP::Date; |
140 | use HTTP::Date; |
139 | use Convert::Scalar 'weaken'; |
141 | use Convert::Scalar 'weaken'; |
140 | use IO::AIO; |
142 | use IO::AIO; |
|
|
143 | use AnyEvent::AIO; |
141 | |
144 | |
142 | IO::AIO::min_parallel $::AIO_PARALLEL; |
145 | IO::AIO::min_parallel $::AIO_PARALLEL; |
143 | |
|
|
144 | our $AIO_WATCHER = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; |
|
|
145 | |
146 | |
146 | our %conn; # $conn{ip}{self} => connobj |
147 | our %conn; # $conn{ip}{self} => connobj |
147 | our %uri; # $uri{ip}{uri}{self} |
148 | our %uri; # $uri{ip}{uri}{self} |
148 | our %blocked; |
149 | our %blocked; |
149 | our %mimetype; |
150 | our %mimetype; |
… | |
… | |
209 | for (keys %blocked) { |
210 | for (keys %blocked) { |
210 | delete $blocked{$_} unless $blocked{$_}[0] > $::NOW; |
211 | delete $blocked{$_} unless $blocked{$_}[0] > $::NOW; |
211 | } |
212 | } |
212 | } |
213 | } |
213 | |
214 | |
214 | our $PRUNE_WATCHER = EV::timer 60, 60, \&prune_caches; |
215 | our $PRUNE_WATCHER = AE::timer 60, 60, \&prune_caches; |
215 | |
216 | |
216 | sub slog { |
217 | sub slog { |
217 | my $self = shift; |
218 | my $self = shift; |
218 | main::slog($_[0], "$self->{remote_id}> $_[1]"); |
219 | main::slog($_[0], "$self->{remote_id}> $_[1]"); |
219 | } |
220 | } |
… | |
… | |
562 | $self->err (416, "not satisfiable", $hdr, ""); |
563 | $self->err (416, "not satisfiable", $hdr, ""); |
563 | |
564 | |
564 | satisfiable: |
565 | satisfiable: |
565 | # check for segmented downloads |
566 | # check for segmented downloads |
566 | if ($l && $::NO_SEGMENTED) { |
567 | if ($l && $::NO_SEGMENTED) { |
567 | my $timeout = $::NOW + 15; |
568 | my $timeout = $::NOW + 60; |
568 | while (keys %{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { |
569 | while (keys %{$uri{$self->{remote_id}}{$self->{uri}}} > 1) { |
569 | if ($timeout <= $::NOW) { |
570 | if ($timeout <= $::NOW) { |
570 | $self->block ($::BLOCKTIME, "segmented downloads are forbidden"); |
|
|
571 | #$self->err_segmented_download; |
571 | $self->err_segmented_download; |
572 | } else { |
572 | } else { |
573 | $httpevent->wait; |
573 | $httpevent->wait; |
574 | } |
574 | } |
575 | } |
575 | } |
576 | } |
576 | } |
… | |
… | |
621 | } |
621 | } |
622 | |
622 | |
623 | Coro::AIO::aio_read $fh, $l, ($h > $bufsize ? $bufsize : $h), my $buf, 0 |
623 | Coro::AIO::aio_read $fh, $l, ($h > $bufsize ? $bufsize : $h), my $buf, 0 |
624 | or last; |
624 | or last; |
625 | |
625 | |
|
|
626 | # readahead to work around rijk disk issues |
|
|
627 | IO::AIO::aio_readahead $fh, $l + $bufsize, $bufsize; |
|
|
628 | |
626 | $tbf->request (length $buf); |
629 | $tbf->request (length $buf); |
627 | my $w = $self->{fh}->syswrite ($buf) |
630 | my $w = $self->{fh}->syswrite ($buf) |
628 | or last; |
631 | or last; |
629 | $::written += $w; |
632 | $::written += $w; |
630 | $self->{written} += $w; |
633 | $self->{written} += $w; |