Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复某些情况下测速数值过大的问题 #290

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions task/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,15 @@ func downloadHandler(ip *net.IPAddr) float64 {
}
bufferRead, err := response.Body.Read(buffer)
if err != nil {
if err != io.EOF { // 文件下载完了,或因网络等问题导致链接中断,则退出循环(终止测速)
// 获取上个时间片
last_time_slice := timeStart.Add(timeSlice * time.Duration(timeCounter-1))
// 下载数据量 / (用当前时间 - 上个时间片/ 时间片)
e.Add(float64(contentRead-lastContentRead) / (float64(currentTime.Sub(last_time_slice)) / float64(timeSlice)))

if err == io.EOF { // 文件下载完了,或因网络等问题导致链接中断,则退出循环(终止测速)
break
}
e.Add(float64(contentRead-lastContentRead) / (float64(nextTime.Sub(currentTime)) / float64(timeSlice)))

}
contentRead += int64(bufferRead)
}
Expand Down