mirror of
https://github.com/go-ping/ping.git
synced 2025-06-25 21:51:46 +00:00
refactor CheckInFlightPackets
to use packet UUID
This commit is contained in:
parent
46c548aa5a
commit
ccc75a38ee
15
ping.go
15
ping.go
@ -97,7 +97,6 @@ func New(addr string) *Pinger {
|
||||
RecordRtts: true,
|
||||
Size: timeSliceLength + trackerLength,
|
||||
Timeout: time.Duration(math.MaxInt64),
|
||||
PacketTimeout: time.Duration(math.MaxInt64),
|
||||
Tracker: r.Uint64(),
|
||||
|
||||
addr: addr,
|
||||
@ -129,10 +128,6 @@ type Pinger struct {
|
||||
// packets have been received.
|
||||
Timeout time.Duration
|
||||
|
||||
// PacketTimeout specifies a timeout before the OnTimeout function is called
|
||||
// for a packet not being received
|
||||
PacketTimeout time.Duration
|
||||
|
||||
// Count tells pinger to stop after sending (and receiving) Count echo
|
||||
// packets. If this option is not specified, pinger will operate until
|
||||
// interrupted.
|
||||
@ -522,19 +517,21 @@ func (p *Pinger) runLoop(
|
||||
|
||||
func (p *Pinger) CheckInFlightPackets() {
|
||||
// Loop through each item in map
|
||||
if p.PacketTimeout == maxPacketTimeout {
|
||||
if time.Duration(p.TTL) == maxPacketTimeout {
|
||||
return
|
||||
}
|
||||
currentTime := time.Now()
|
||||
for seq, pkt := range p.InFlightPackets {
|
||||
if pkt.DispatchedTime.Add(p.PacketTimeout).Before(currentTime) {
|
||||
delete(p.InFlightPackets, seq)
|
||||
for id, inflight := range p.InFlightPackets {
|
||||
for seq, pkt := range inflight {
|
||||
if pkt.DispatchedTime.Add(time.Duration(p.TTL)).Before(currentTime) {
|
||||
delete(p.InFlightPackets[id], seq)
|
||||
if p.OnTimeout != nil {
|
||||
p.OnTimeout(seq, &pkt)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pinger) Stop() {
|
||||
p.lock.Lock()
|
||||
|
Loading…
Reference in New Issue
Block a user