--- lib/PXElator/httpd.pm 2009/07/31 22:52:22 104 +++ lib/PXElator/httpd.pm 2009/07/31 23:22:05 105 @@ -48,8 +48,6 @@ return if ! -f $full; - my $start_t = time(); - if ( my $pid = fork ) { # parent close($client); @@ -65,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); @@ -75,21 +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%% %.2f K/s\r" + 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 - , ( $pos / 1024 ) / ( time() - $start_t ) + , $speed / 1024 + , ( $size - $pos ) / $speed ; } close($fh); close($client); - print "\n"; + print STDERR "\n"; exit; }