return if ! -f $full;
- my $start_t = time();
-
if ( my $pid = fork ) {
# parent
close($client);
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);
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;
}