17 |
use File::Slurp; |
use File::Slurp; |
18 |
#use JSON; |
#use JSON; |
19 |
use IO::Socket::INET; |
use IO::Socket::INET; |
|
use Module::Refresh; |
|
20 |
|
|
21 |
our $pids; |
our $pids; |
22 |
$pids = { httpd => $$ } unless defined $pids; # keep pids on refresh |
$pids = { httpd => $$ } unless defined $pids; # keep pids on refresh |
37 |
|
|
38 |
use html; |
use html; |
39 |
our $static_pids; |
our $static_pids; |
40 |
|
use progress_bar; |
|
use Time::HiRes qw/time/; |
|
41 |
|
|
42 |
sub static { |
sub static { |
43 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
69 |
my $buff; |
my $buff; |
70 |
my $pos = 0; |
my $pos = 0; |
71 |
|
|
|
STDERR->autoflush(1); |
|
72 |
warn "static $path $type $size block: $block\n"; |
warn "static $path $type $size block: $block\n"; |
73 |
|
|
74 |
my $start_t = time(); |
progress_bar::start; |
|
my $last_t = $start_t; |
|
75 |
|
|
76 |
while( my $len = read $fh, $buff, $block ) { |
while( my $len = read $fh, $buff, $block ) { |
77 |
syswrite $client,$buff; |
print $client $buff; |
78 |
$client->flush; |
$client->flush; |
79 |
$pos += $len; |
$pos += $len; |
80 |
my $t = time(); |
progress_bar::tick( $path, $pos, $size ); |
|
next unless $t - $last_t > 0.75; |
|
|
$last_t = $t; |
|
|
my $speed = ( $pos ) / ( $t - $start_t ); |
|
|
printf STDERR "%s %d/%d %.2f%% %.2f K/s ETA %.1fs\r" |
|
|
, $path, $pos |
|
|
, $size, $pos * 100 / $size |
|
|
, $speed / 1024 |
|
|
, ( $size - $pos ) / $speed |
|
|
; |
|
81 |
} |
} |
82 |
close($fh); |
close($fh); |
83 |
close($client); |
close($client); |
84 |
|
|
85 |
print STDERR "\n"; |
print STDERR "\n"; |
86 |
|
|
87 |
exit; |
warn "exit static child"; |
88 |
|
|
89 |
|
exit(0); |
90 |
} |
} |
91 |
|
|
92 |
use boolean; |
use boolean; |
136 |
sub get_request { |
sub get_request { |
137 |
my ( $client, $path, $param ) = @_; |
my ( $client, $path, $param ) = @_; |
138 |
|
|
139 |
|
server->refresh; |
140 |
|
|
141 |
warn "get_request $path ", $param ? dump( $param ) : '', "\n"; |
warn "get_request $path ", $param ? dump( $param ) : '', "\n"; |
142 |
|
|
143 |
if ( my $found = static( $client,$path ) ) { |
if ( my $found = static( $client,$path ) ) { |
258 |
start_stop 'screen'; |
start_stop 'screen'; |
259 |
start_stop 'kvm'; |
start_stop 'kvm'; |
260 |
|
|
261 |
while (my $client = $server->accept()) { |
while (1) { |
262 |
$client->autoflush(1); |
my $client = $server->accept() || next; # ALARM trickle us |
263 |
my $request = <$client>; |
my $request = <$client>; |
264 |
|
|
265 |
warn "request $request\n" if $debug; |
warn "request $request\n" if $debug; |
266 |
|
|
|
Module::Refresh->refresh; |
|
|
|
|
267 |
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { |
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { |
268 |
my $path = $1; |
my $path = $1; |
269 |
my $param; |
my $param; |