--- lib/PXElator/httpd.pm 2009/07/31 22:52:22 104 +++ lib/PXElator/httpd.pm 2009/08/02 12:09:02 115 @@ -38,8 +38,7 @@ use html; our $static_pids; - -use Time::HiRes qw/time/; +use progress_bar; sub static { my ($client,$path) = @_; @@ -48,8 +47,6 @@ return if ! -f $full; - my $start_t = time(); - if ( my $pid = fork ) { # parent close($client); @@ -65,8 +62,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 +70,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;