48 |
|
|
49 |
return if ! -f $full; |
return if ! -f $full; |
50 |
|
|
|
my $start_t = time(); |
|
|
|
|
51 |
if ( my $pid = fork ) { |
if ( my $pid = fork ) { |
52 |
# parent |
# parent |
53 |
close($client); |
close($client); |
63 |
|
|
64 |
my $size = -s $full || return; |
my $size = -s $full || return; |
65 |
|
|
|
$client->autoflush(1); |
|
|
|
|
66 |
print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n"; |
print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n"; |
67 |
|
|
68 |
open(my $fh, $full); |
open(my $fh, $full); |
71 |
my $buff; |
my $buff; |
72 |
my $pos = 0; |
my $pos = 0; |
73 |
|
|
74 |
print "static $path $type $size block: $block\n"; |
STDERR->autoflush(1); |
75 |
|
warn "static $path $type $size block: $block\n"; |
76 |
|
|
77 |
|
my $start_t = time(); |
78 |
|
my $last_t = $start_t; |
79 |
|
|
80 |
while( my $len = read $fh, $buff, $block ) { |
while( my $len = read $fh, $buff, $block ) { |
81 |
print $client $buff; |
syswrite $client,$buff; |
82 |
|
$client->flush; |
83 |
$pos += $len; |
$pos += $len; |
84 |
printf "%s %d/%d %.2f%% %.2f K/s\r" |
my $t = time(); |
85 |
|
next unless $t - $last_t > 0.75; |
86 |
|
$last_t = $t; |
87 |
|
my $speed = ( $pos ) / ( $t - $start_t ); |
88 |
|
printf STDERR "%s %d/%d %.2f%% %.2f K/s ETA %.1fs\r" |
89 |
, $path, $pos |
, $path, $pos |
90 |
, $size, $pos * 100 / $size |
, $size, $pos * 100 / $size |
91 |
, ( $pos / 1024 ) / ( time() - $start_t ) |
, $speed / 1024 |
92 |
|
, ( $size - $pos ) / $speed |
93 |
; |
; |
94 |
} |
} |
95 |
close($fh); |
close($fh); |
96 |
close($client); |
close($client); |
97 |
|
|
98 |
print "\n"; |
print STDERR "\n"; |
99 |
|
|
100 |
exit; |
exit; |
101 |
} |
} |