--- lib/PXElator/httpd.pm 2009/07/31 20:45:09 96 +++ lib/PXElator/httpd.pm 2009/08/03 19:59:08 128 @@ -17,7 +17,6 @@ use File::Slurp; #use JSON; use IO::Socket::INET; -use Module::Refresh; our $pids; $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh @@ -38,6 +37,7 @@ use html; our $static_pids; +use progress_bar; sub static { my ($client,$path) = @_; @@ -61,8 +61,6 @@ my $size = -s $full || return; - $client->autoflush(1); - print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n"; open(my $fh, $full); @@ -71,19 +69,24 @@ my $buff; my $pos = 0; - print "static $path $type $size block: $block\n"; + warn "static $path $type $size block: $block\n"; + + progress_bar::start; while( my $len = read $fh, $buff, $block ) { print $client $buff; + $client->flush; $pos += $len; - printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size; + progress_bar::tick( $path, $pos, $size ); } close($fh); close($client); - print "\n"; + print STDERR "\n"; + + warn "exit static child"; - exit; + exit(0); } use boolean; @@ -133,6 +136,8 @@ sub get_request { my ( $client, $path, $param ) = @_; + server->refresh; + warn "get_request $path ", $param ? dump( $param ) : '', "\n"; if ( my $found = static( $client,$path ) ) { @@ -253,14 +258,12 @@ start_stop 'screen'; start_stop 'kvm'; - while (my $client = $server->accept()) { - $client->autoflush(1); + while (1) { + my $client = $server->accept() || next; # ALARM trickle us my $request = <$client>; warn "request $request\n" if $debug; - Module::Refresh->refresh; - if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { my $path = $1; my $param;