Skip to content

Commit c045b91

Browse files
committed
修复 因修复上个 BUG 而产生的新 BUG(下载速度为 0.00)...
1 parent d8db541 commit c045b91

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

task/download.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,13 @@ func downloadHandler(ip *net.IPAddr) float64 {
167167
}
168168
bufferRead, err := response.Body.Read(buffer)
169169
if err != nil {
170+
if err != io.EOF { // 如果文件下载过程中遇到报错(如 Timeout),且并不是因为文件下载完了,则退出循环(终止测速)
171+
break
172+
}
170173
// 获取上个时间片
171174
last_time_slice := timeStart.Add(timeSlice * time.Duration(timeCounter-1))
172175
// 下载数据量 / (用当前时间 - 上个时间片/ 时间片)
173176
e.Add(float64(contentRead-lastContentRead) / (float64(currentTime.Sub(last_time_slice)) / float64(timeSlice)))
174-
175-
if err == io.EOF { // 文件下载完了,或因网络等问题导致链接中断,则退出循环(终止测速)
176-
break
177-
}
178-
179177
}
180178
contentRead += int64(bufferRead)
181179
}

0 commit comments

Comments
 (0)