… | |
… | |
22 | our $accesslog; |
22 | our $accesslog; |
23 | our $errorlog; |
23 | our $errorlog; |
24 | |
24 | |
25 | our $NOW; |
25 | our $NOW; |
26 | our $HTTP_NOW; |
26 | our $HTTP_NOW; |
|
|
27 | |
|
|
28 | our $ERROR_LOG; |
|
|
29 | our $ACCESS_LOG; |
27 | |
30 | |
28 | Event->timer(interval => 1, hard => 1, cb => sub { |
31 | Event->timer(interval => 1, hard => 1, cb => sub { |
29 | $NOW = time; |
32 | $NOW = time; |
30 | $HTTP_NOW = time2str $NOW; |
33 | $HTTP_NOW = time2str $NOW; |
31 | })->now; |
34 | })->now; |
… | |
… | |
137 | listen_on $http_port; |
140 | listen_on $http_port; |
138 | } |
141 | } |
139 | |
142 | |
140 | package conn; |
143 | package conn; |
141 | |
144 | |
|
|
145 | use strict; |
|
|
146 | use bytes; |
|
|
147 | |
142 | use Socket; |
148 | use Socket; |
143 | use HTTP::Date; |
149 | use HTTP::Date; |
144 | use Convert::Scalar 'weaken'; |
150 | use Convert::Scalar 'weaken'; |
145 | use IO::AIO; |
151 | use IO::AIO; |
146 | |
152 | |
… | |
… | |
202 | for (keys %$hash) { |
208 | for (keys %$hash) { |
203 | if (ref $hash->{$_} eq HASH::) { |
209 | if (ref $hash->{$_} eq HASH::) { |
204 | prune_cache($hash->{$_}); |
210 | prune_cache($hash->{$_}); |
205 | unless (scalar keys %{$hash->{$_}}) { |
211 | unless (scalar keys %{$hash->{$_}}) { |
206 | delete $hash->{$_}; |
212 | delete $hash->{$_}; |
207 | $d2++; |
|
|
208 | } |
213 | } |
209 | } |
214 | } |
210 | } |
215 | } |
211 | } |
216 | } |
212 | |
217 | |
… | |
… | |
597 | |
602 | |
598 | if ($self->{method} eq "GET") { |
603 | if ($self->{method} eq "GET") { |
599 | $self->{time} = $::NOW; |
604 | $self->{time} = $::NOW; |
600 | $self->{written} = 0; |
605 | $self->{written} = 0; |
601 | |
606 | |
602 | my $current = $Coro::current; |
607 | my $fh; |
603 | |
|
|
604 | my ($fh, $buf, $r); |
|
|
605 | |
608 | |
606 | open $fh, "<", $self->{path} |
609 | open $fh, "<", $self->{path} |
607 | or die "$self->{path}: late open failure ($!)"; |
610 | or die "$self->{path}: late open failure ($!)"; |
608 | |
611 | |
609 | $h -= $l - 1; |
612 | $h -= $l - 1; |
… | |
… | |
630 | if ($blocked{$self->{remote_id}}) { |
633 | if ($blocked{$self->{remote_id}}) { |
631 | $self->{h}{connection} = "close"; |
634 | $self->{h}{connection} = "close"; |
632 | die bless {}, err::; |
635 | die bless {}, err::; |
633 | } |
636 | } |
634 | |
637 | |
635 | Coro::AIO::aio_read $fh, $l, ($h > $bufsize ? $bufsize : $h), $buf, 0 |
638 | Coro::AIO::aio_read $fh, $l, ($h > $bufsize ? $bufsize : $h), my $buf, 0 |
636 | or last; |
639 | or last; |
637 | |
640 | |
638 | $tbf->request (length $buf); |
641 | $tbf->request (length $buf); |
639 | my $w = syswrite $self->{fh}, $buf |
642 | my $w = syswrite $self->{fh}, $buf |
640 | or last; |
643 | or last; |
641 | $::written += $w; |
644 | $::written += $w; |
642 | $self->{written} += $w; |
645 | $self->{written} += $w; |
643 | $l += $r; |
646 | $l += $w; |
644 | } |
647 | } |
645 | |
648 | |
646 | close $fh; |
649 | close $fh; |
647 | } |
650 | } |
648 | } |
651 | } |