SVN: toys/rsget.pl/RSGet/Curl.pm
sparky
sparky at pld-linux.org
Sat Mar 5 01:20:40 CET 2011
Author: sparky
Date: Sat Mar 5 01:20:40 2011
New Revision: 12191
Modified:
toys/rsget.pl/RSGet/Curl.pm
Log:
- get download speed from curl, don't calculate manually
Modified: toys/rsget.pl/RSGet/Curl.pm
==============================================================================
--- toys/rsget.pl/RSGet/Curl.pm (original)
+++ toys/rsget.pl/RSGet/Curl.pm Sat Mar 5 01:20:40 2011
@@ -482,6 +482,7 @@
my $get_obj = $supercurl->{get_obj};
delete $supercurl->{get_obj};
+ $supercurl->{speed_end} = $curl->getinfo( CURLINFO_SPEED_DOWNLOAD );
if ( $supercurl->{file} ) {
close $supercurl->{file};
$get_obj->print( "DONE " . donemsg( $supercurl ) );
@@ -608,7 +609,6 @@
}
}
-my $avg_speed = 0;
sub update_status
{
my $time = time;
@@ -642,12 +642,9 @@
next;
}
- my $speed = "???";
- if ( $time_diff > 0 ) {
- my $s = $size_diff / ( $time_diff * 1024 );
- $speed = sprintf "%.2f", $s;
- $total_speed += $s;
- }
+ my $s = $supercurl->{curl}->getinfo( CURLINFO_SPEED_DOWNLOAD ) / 1024;
+ my $speed = sprintf "%.2f", $s;
+ $total_speed += $s;
my $eta = "";
if ( $size_total > 0 and $time_diff > 0 and $size_diff > 0 ) {
@@ -658,12 +655,11 @@
$supercurl->{get_obj}->print( "$size; ${speed}KB/s$eta" );
}
- $avg_speed = ($avg_speed * 9 + $total_speed) / 10;
my $running = scalar keys %active_curl;
RSGet::Line::status(
'running cURL' => $running,
- 'total speed' => ( sprintf '%.2fKB/s', $avg_speed )
+ 'total speed' => ( sprintf '%.2fKB/s', $total_speed )
);
return;
}
@@ -672,11 +668,10 @@
{
my $supercurl = shift;
- my $size_diff = $supercurl->{size_got} - $supercurl->{size_start};
my $time_diff = time() - $supercurl->{time_start};
$time_diff = 1 unless $time_diff;
my $eta = s2string( $time_diff );
- my $speed = sprintf "%.2f", $size_diff / ( $time_diff * 1024 );
+ my $speed = sprintf "%.2f", $supercurl->{speed_end} / 1024;
return bignum( $supercurl->{size_got} ) . "; ${speed}KB/s $eta";
}
More information about the pld-cvs-commit
mailing list