… | |
… | |
55 | our $httpevent = new Coro::Signal; |
55 | our $httpevent = new Coro::Signal; |
56 | |
56 | |
57 | our $queue_file = new transferqueue $MAX_TRANSFERS; |
57 | our $queue_file = new transferqueue $MAX_TRANSFERS; |
58 | our $queue_index = new transferqueue 10; |
58 | our $queue_index = new transferqueue 10; |
59 | |
59 | |
60 | our $tbf_top = new tbf rate => 100000; |
60 | our $tbf_top = new tbf rate => $TBF_RATE || 100000; |
61 | |
61 | |
62 | my $unused_bytes = 0; |
62 | my $unused_bytes = 0; |
63 | my $unused_last = time; |
63 | my $unused_last = time; |
64 | |
64 | |
65 | sub unused_bandwidth { |
65 | sub unused_bandwidth { |
… | |
… | |
110 | if (@pool) { |
110 | if (@pool) { |
111 | (pop @pool)->ready; |
111 | (pop @pool)->ready; |
112 | } else { |
112 | } else { |
113 | async \&handler; |
113 | async \&handler; |
114 | } |
114 | } |
115 | |
|
|
116 | } |
115 | } |
117 | }; |
116 | }; |
118 | } |
117 | } |
119 | |
118 | |
120 | my $http_port = new Coro::Socket |
119 | my $http_port = new Coro::Socket |
… | |
… | |
193 | |
192 | |
194 | sub DESTROY { |
193 | sub DESTROY { |
195 | #my $self = shift; |
194 | #my $self = shift; |
196 | $::conns--; |
195 | $::conns--; |
197 | } |
196 | } |
|
|
197 | |
|
|
198 | sub prune_cache { |
|
|
199 | my $hash = $_[0]; |
|
|
200 | |
|
|
201 | for (keys %$hash) { |
|
|
202 | if (ref $hash->{$_} eq HASH::) { |
|
|
203 | prune_cache($hash->{$_}); |
|
|
204 | unless (scalar keys %{$hash->{$_}}) { |
|
|
205 | delete $hash->{$_}; |
|
|
206 | $d2++; |
|
|
207 | } |
|
|
208 | } |
|
|
209 | } |
|
|
210 | } |
|
|
211 | |
|
|
212 | sub prune_caches { |
|
|
213 | prune_cache \%conn; |
|
|
214 | prune_cache \%uri; |
|
|
215 | |
|
|
216 | for (keys %blocked) { |
|
|
217 | delete $blocked{$_} unless $blocked{$_}[0] > $::NOW; |
|
|
218 | } |
|
|
219 | } |
|
|
220 | |
|
|
221 | Event->timer(interval => 60, cb => \&prune_caches); |
198 | |
222 | |
199 | sub slog { |
223 | sub slog { |
200 | my $self = shift; |
224 | my $self = shift; |
201 | main::slog($_[0], "$self->{remote_id}> $_[1]"); |
225 | main::slog($_[0], "$self->{remote_id}> $_[1]"); |
202 | } |
226 | } |