Releases: samiyr/SwiftyPing
v1.2.1
- Fix a crash when sending more than 65535 pings (thanks to @Kususumu)
- Overall better handling of sequence indices. All the functions and result structs now use the appropriate integer types. This may be a breaking change if you depend on those values being
Int
types. - There's a new
trueSequenceNumber
inPingResponse
and a similar private variable inSwiftyPing
, which is now returned bycurrentCount
.trueSequenceNumber
is anUInt64
, which will probably never overflow. This keeps track of the actual number of pings sent, even whensequenceNumber
, which is just anUInt16
, has overflowed and been wrapped back to 0.
v1.2
This release includes a new PingResult
struct that's sent to a new observer finished
when pinging stops. This ping result includes all the responses received, packet loss and also automatically calculates roundtrip statistics (min, max, avg, stddev). Here's an example from the SwiftyPingTest
project:
let host = "1.1.1.1"
ping = try SwiftyPing(host: host, configuration: PingConfiguration(interval: 1.0, with: 1), queue: DispatchQueue.global())
ping?.observer = { (response) in
DispatchQueue.main.async {
var message = "\(response.duration * 1000) ms"
if let error = response.error {
if error == .responseTimeout {
message = "Timeout \(message)"
} else {
print(error)
message = error.localizedDescription
}
}
self.textView.text.append(contentsOf: "\nPing #\(response.sequenceNumber): \(message)")
self.textView.scrollRangeToVisible(NSRange(location: self.textView.text.count - 1, length: 1))
}
}
ping?.finished = { (result) in
DispatchQueue.main.async {
var message = "\n--- \(host) ping statistics ---\n"
message += "\(result.packetsTransmitted) transmitted, \(result.packetsReceived) received"
if let loss = result.packetLoss {
message += String(format: "\n%.1f%% packet loss\n", loss * 100)
} else {
message += "\n"
}
if let roundtrip = result.roundtrip {
message += String(format: "round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms", roundtrip.minimum * 1000, roundtrip.average * 1000, roundtrip.maximum * 1000, roundtrip.standardDeviation * 1000)
}
self.textView.text.append(contentsOf: message)
self.textView.scrollRangeToVisible(NSRange(location: self.textView.text.count - 1, length: 1))
}
}
try ping?.startPinging()
v1.1.14
This version also includes a behavioral change related to the memory leak fix. Starting from this release, when a targetCount
is set and is reached, the ping instance will be halted instead of stopped. This better reflects the nature of such ping instances: they are supposed to be one-time objects and be discarded after use. Halting the ping instance after the target count has been reached means that the socket and associated resources are released immediately, instead of when the application quits. If the same ping instance will be used later, the socket will be recreated from scratch.
This behavior is controlled by the new flag haltAfterTarget
in the PingConfiguration
. This flag defaults to the true
, and the old behavior can be restored by setting this flag to false
.
v1.1.13
v1.1.12
v1.1.11
v1.1.10
v1.1.9
Fixes a memory leak issue (thanks @cgcym1234)