Skip to content

Commit

Permalink
Merge pull request #725 from supermario1990/master
Browse files Browse the repository at this point in the history
fix invalid Ping() #724
  • Loading branch information
smallnest authored Apr 24, 2022
2 parents f710ebc + efccf69 commit 6b17ab2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/ping_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net"
"strings"
"time"

ping "github.com/go-ping/ping"
)
Expand Down Expand Up @@ -54,8 +55,17 @@ func Ping(host string) (rtt int, err error) {
return rtt, err
}
pinger.Count = 3
pinger.Timeout = 3 * time.Second
err = pinger.Run()
if err != nil {
return rtt, err
}
stats := pinger.Statistics()
rtt = int(stats.AvgRtt)
// ping failed
if len(stats.Rtts) == 0 {
return rtt, err
}
rtt = int(stats.AvgRtt) / 1e6

return rtt, err
}
Expand Down

0 comments on commit 6b17ab2

Please sign in to comment.