--- lib/PXElator/httpd.pm 2009/07/31 20:45:09 96 +++ lib/PXElator/httpd.pm 2009/07/31 23:22:05 105 @@ -39,6 +39,8 @@ use html; our $static_pids; +use Time::HiRes qw/time/; + sub static { my ($client,$path) = @_; @@ -61,8 +63,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,17 +71,31 @@ my $buff; my $pos = 0; - print "static $path $type $size block: $block\n"; + STDERR->autoflush(1); + warn "static $path $type $size block: $block\n"; + + my $start_t = time(); + my $last_t = $start_t; while( my $len = read $fh, $buff, $block ) { - print $client $buff; + syswrite $client,$buff; + $client->flush; $pos += $len; - printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size; + my $t = time(); + 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 + ; } close($fh); close($client); - print "\n"; + print STDERR "\n"; exit; }