mirror of https://github.com/zlatinb/muwire
do not update speed reading if the sampling is too frequent
parent
cac3ff0bcf
commit
56e02c4981
|
@ -164,14 +164,15 @@ public class Downloader {
|
|||
|
||||
public int speed() {
|
||||
int currSpeed = 0
|
||||
if (getCurrentState() == DownloadState.DOWNLOADING) {
|
||||
long dataRead = dataSinceLastRead.getAndSet(0)
|
||||
long now = System.currentTimeMillis()
|
||||
if (now > lastSpeedRead)
|
||||
currSpeed = (int) (dataRead * 1000.0d / (now - lastSpeedRead))
|
||||
lastSpeedRead = now
|
||||
}
|
||||
|
||||
if (getCurrentState() != DownloadState.DOWNLOADING)
|
||||
return currSpeed
|
||||
long now = System.currentTimeMillis()
|
||||
if (now < lastSpeedRead + 50)
|
||||
return speedArr.average()
|
||||
long dataRead = dataSinceLastRead.getAndSet(0)
|
||||
currSpeed = (int) (dataRead * 1000.0d / (now - lastSpeedRead))
|
||||
lastSpeedRead = now
|
||||
|
||||
// this is not very accurate since each slot may hold more than a second
|
||||
if (speedArr.size() != downloadManager.muSettings.speedSmoothSeconds) {
|
||||
speedArr.clear()
|
||||
|
|
Loading…
Reference in New Issue