Skip to content

Commit e3d5791

Browse files
committed
fix: 修复丢包计算错误
如果发现丢包时,延迟设置为0
1 parent f86c87a commit e3d5791

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

client/ping.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ func (c *Client) startPing() {
3434
pingHost.Range(func(k, v interface{}) bool {
3535
var lost *lostPacket
3636

37-
host := k.(string)
37+
isp := k.(string)
3838
domain := v.(string)
3939

40-
if host == "cm" {
40+
if isp == "cm" {
4141
lost = &CmLostPacket
42-
} else if host == "cu" {
42+
} else if isp == "cu" {
4343
lost = &CuLostPacket
44-
} else if host == "ct" {
44+
} else if isp == "ct" {
4545
lost = &CtLostPacket
4646
} else {
4747
return false
@@ -73,9 +73,15 @@ func (c *Client) startPing() {
7373
}
7474

7575
stat := pinger.Statistics()
76+
if stat.AvgRtt == 0 {
77+
78+
lost.Push(true)
79+
c.pingTime.Store(isp, uint(time.Duration(0)))
80+
return true
81+
}
7682

7783
lost.Push(false)
78-
c.pingTime.Store(host, uint(stat.AvgRtt/time.Millisecond))
84+
c.pingTime.Store(isp, uint(stat.AvgRtt/time.Millisecond))
7985

8086
return true
8187
})

0 commit comments

Comments
 (0)