From d643992c459d7e3bb9e708b74073ee4e6bee3df3 Mon Sep 17 00:00:00 2001 From: charSLee <735365895@qq.com> Date: Fri, 10 Feb 2023 15:56:38 +0800 Subject: [PATCH] fix break when err == io.EOF --- task/download.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/task/download.go b/task/download.go index c056cb6..65ddfd8 100644 --- a/task/download.go +++ b/task/download.go @@ -167,14 +167,15 @@ func downloadHandler(ip *net.IPAddr) float64 { } bufferRead, err := response.Body.Read(buffer) if err != nil { - if err != io.EOF { // 文件下载完了,或因网络等问题导致链接中断,则退出循环(终止测速) - break - } // 获取上个时间片 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 + } + } contentRead += int64(bufferRead) }