mirror of
https://github.com/go-ping/ping.git
synced 2025-08-31 04:41:24 +00:00
Refactor onTimeout to be (int, *ping.InFlightPacket)
This commit is contained in:
committed by
thatmattlove
parent
58ebcd5b44
commit
46c548aa5a
@@ -77,8 +77,8 @@ func main() {
|
||||
fmt.Printf("%d bytes from %s: icmp_seq=%d time=%v ttl=%v (DUP!)\n",
|
||||
pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt, pkt.Ttl)
|
||||
}
|
||||
pinger.OnTimeout = func(pkt *ping.InFlightPacket) {
|
||||
fmt.Printf("TIMEOUT icmp_seq=%d time=%v\n", pkt.Seq, pkt.DispatchedTime)
|
||||
pinger.OnTimeout = func(seq int, pkt *ping.InFlightPacket) {
|
||||
fmt.Printf("TIMEOUT icmp_seq=%d time=%v\n", seq, pkt.DispatchedTime)
|
||||
}
|
||||
pinger.OnFinish = func(stats *ping.Statistics) {
|
||||
fmt.Printf("\n--- %s ping statistics ---\n", stats.Addr)
|
||||
|
6
ping.go
6
ping.go
@@ -178,7 +178,7 @@ type Pinger struct {
|
||||
OnFinish func(*Statistics)
|
||||
|
||||
// OnTimeout is called when packet timeout
|
||||
OnTimeout func(*InFlightPacket)
|
||||
OnTimeout func(int, *InFlightPacket)
|
||||
|
||||
// OnDuplicateRecv is called when a packet is received that has already been received.
|
||||
OnDuplicateRecv func(*Packet)
|
||||
@@ -219,7 +219,6 @@ type Pinger struct {
|
||||
|
||||
type InFlightPacket struct {
|
||||
DispatchedTime time.Time
|
||||
Seq int
|
||||
}
|
||||
|
||||
type packet struct {
|
||||
@@ -531,7 +530,7 @@ func (p *Pinger) CheckInFlightPackets() {
|
||||
if pkt.DispatchedTime.Add(p.PacketTimeout).Before(currentTime) {
|
||||
delete(p.InFlightPackets, seq)
|
||||
if p.OnTimeout != nil {
|
||||
p.OnTimeout(&pkt)
|
||||
p.OnTimeout(seq, &pkt)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -790,7 +789,6 @@ func (p *Pinger) sendICMP(conn packetConn) error {
|
||||
// mark this sequence as in-flight
|
||||
p.InFlightPackets[currentUUID][p.sequence] = InFlightPacket{
|
||||
DispatchedTime: time.Now(),
|
||||
Seq: p.sequence,
|
||||
}
|
||||
p.PacketsSent++
|
||||
p.sequence++
|
||||
|
Reference in New Issue
Block a user