Commit a1dbdea5 authored by Adphi's avatar Adphi

fix rtt on windows: set to 1 if pong received but rtt is 0

parent 01b6297a
......@@ -35,6 +35,16 @@ func (u *destination) ping(pinger *ping.Pinger, timeout time.Duration) {
func (s *history) addResult(rtt time.Duration, err error) {
s.mtx.Lock()
// TODO : What if we reach max of int
if err == nil {
s.received++
// On windows there may be rtt 0 caused by bad time resolution
if rtt == 0 {
rtt = 1
}
} else {
s.lost++
}
switch len(s.results) {
case 0:
case 1:
......@@ -42,12 +52,6 @@ func (s *history) addResult(rtt time.Duration, err error) {
default:
s.results = append([]time.Duration{rtt}, s.results[:len(s.results)-1]...)
}
// TODO : What if we reach max of int
if err == nil {
s.received++
} else {
s.lost++
}
s.mtx.Unlock()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment