--- lib/PXElator/httpd.pm 2009/07/31 22:52:22 104 +++ lib/PXElator/httpd.pm 2009/08/04 13:30:47 136 @@ -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,8 +37,7 @@ use html; our $static_pids; - -use Time::HiRes qw/time/; +use progress_bar; sub static { my ($client,$path) = @_; @@ -48,8 +46,6 @@ return if ! -f $full; - my $start_t = time(); - if ( my $pid = fork ) { # parent close($client); @@ -65,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); @@ -75,23 +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%% %.2f K/s\r" - , $path, $pos - , $size, $pos * 100 / $size - , ( $pos / 1024 ) / ( time() - $start_t ) - ; + progress_bar::tick( $path, $pos, $size ); } close($fh); close($client); - print "\n"; + print STDERR "\n"; + + warn "exit static child"; - exit; + exit(0); } use boolean; @@ -103,7 +98,7 @@ sub start_stop { my $daemon = shift; - my $pid = $pids->{$daemon}; + my $pid = $pids->{$daemon} || 'not started'; warn "start_stop $daemon $pid\n"; @@ -141,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 ) ) { @@ -261,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;