Skip to content

Commit

Permalink
Mac version
Browse files Browse the repository at this point in the history
  • Loading branch information
samiyrj committed Feb 28, 2021
1 parent b74f02b commit 660a16c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/SwiftyPing/SwiftyPing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public class SwiftyPing: NSObject {
}
}

private var erroredIndices = [Int]()
/// Initializes a pinger.
/// - Parameter destination: Specifies the host.
/// - Parameter configuration: A configuration object which can be used to customize pinging behavior.
Expand Down Expand Up @@ -365,6 +366,8 @@ public class SwiftyPing: NSObject {
error: error,
byteCount: nil,
ipHeader: nil)

self.erroredIndices.append(self.sequenceIndex)
self.isPinging = false
self.informObserver(of: response)

Expand All @@ -384,6 +387,7 @@ public class SwiftyPing: NSObject {
error: pingError,
byteCount: nil,
ipHeader: nil)
self.erroredIndices.append(self.sequenceIndex)
self.isPinging = false
self.informObserver(of: response)

Expand All @@ -408,6 +412,8 @@ public class SwiftyPing: NSObject {
error: error,
byteCount: nil,
ipHeader: nil)

erroredIndices.append(sequenceIndex)
self.isPinging = false
informObserver(of: response)

Expand Down Expand Up @@ -471,6 +477,7 @@ public class SwiftyPing: NSObject {
isPinging = false
if resetSequence {
sequenceIndex = 0
erroredIndices.removeAll()
sequenceStart = nil
}
}
Expand Down Expand Up @@ -618,6 +625,10 @@ public class SwiftyPing: NSObject {
}
let receivedSequenceIndex = CFSwapInt16BigToHost(icmpHeader.sequenceNumber)
guard receivedSequenceIndex == sequenceIndex else {
if erroredIndices.contains(Int(receivedSequenceIndex)) {
// This response either errorred or timed out, ignore it
return false
}
throw PingError.invalidSequenceIndex(received: Int(receivedSequenceIndex), expected: sequenceIndex)
}
return true
Expand Down
Binary file not shown.

0 comments on commit 660a16c

Please sign in to comment.