Open Karthikeyan1108 opened 4 months ago
Please provide additional details about your use of fping
.
Hi @auerswal
Thank you for the reply. Please find the usage of fping in the following code. Passing array of hosts to the ping operation in the background queue async way with arguments as below.
`/// Send ping with completion block. /// /// - Parameters: /// - hosts: hosts /// - backoff: default 1.5 /// - count: number of ping send per host /// - completion: results dictionary, the key is host string, the value is PngResult struct
public static func ping(hosts: [String], backoff: Float = 1.5, count: Int = 1,
progress: ((_ progress: (Float)) -> Void)? = nil,
completion: @escaping (_ results: [String: PngResult]) -> Void) {
let argv:[String?] = ["", "-c\(count)", "-B\(backoff)", "-q"] + hosts + [nil]
var cargs = argv.map { $0.flatMap { UnsafeMutablePointer<Int8>(strdup($0)) } }
let observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "fpingxProgress"), object: nil, queue: OperationQueue()) { (notification) in
if let p = notification.userInfo!["progress"] as? Float {
progress?(p > 1 ? 1 : p)
}
}
DispatchQueue.global(qos: .background).async {
let resultsArrarPtr = fping(Int32(argv.count), &cargs, progressCCallback)!
var hostPtr = resultsArrarPtr.pointee
var results: [String: PngResult] = [:]
while (hostPtr != nil) {
let h = hostPtr!.pointee
let host = String(cString: h.host)
let result = PngResult(host: host, xmt: Int(h.num_sent), rcv: Int(h.num_recv), avg: h.num_recv > 0 ? Float(h.total_time / h.num_recv / 100) : nil, min: h.num_recv > 0 ? Int(h.min_reply / 100) : nil, max: h.num_recv > 0 ? Int(h.max_reply / 100) : nil, jitt: (h.jitter / Float(count)))
results[host] = result
let freeNode = hostPtr
hostPtr = hostPtr?.pointee.ev_next
free(UnsafeMutableRawPointer(freeNode))
}
free(UnsafeMutablePointer(resultsArrarPtr))
completion(results)
NotificationCenter.default.removeObserver(observer)
for ptr in cargs { free(UnsafeMutablePointer(ptr)) }
}
}`
The error looks as if you created a too restrictive environment for fping
to work.
Thank you for the amazing framework.
There is a crash observed in the fping framework. Please help us to resolve the crash.
Crashed Thread: 7
Exception Type: EXC_GUARD Exception Codes: GUARD_TYPE_USER Exception Codes: 0x6000000000000012, 0x0000000000000002
Termination Reason: Namespace LIBSYSTEM, Code 2 Application Triggered Fault
Thread 7 Crashed: 0 libsystem_kernel.dylib 0x199e8ced8 os_fault_with_payload + 8 1 libsystem_kernel.dylib 0x199e94784 __darwin_check_fd_set_overflow + 212 2 pingo 0x1058ec944 socket_can_read + 192 3 pingo 0x1058eb510 wait_for_reply + 124 4 pingo 0x1058eb084 main_loop + 692 5 pingo 0x1058ea0dc mainx + 3384 6 pingo 0x1058e9324 fping + 48 7 Versa SASE Client 0x105012768 0x104e78000 + 1681256 8 Versa SASE Client 0x104ef57ac 0x104e78000 + 513964 9 libdispatch.dylib 0x199d0c750 _dispatch_call_block_and_release + 32 10 libdispatch.dylib 0x199d0e3e8 _dispatch_client_callout + 20 11 libdispatch.dylib 0x199d20080 _dispatch_root_queue_drain + 864 12 libdispatch.dylib 0x199d206b8 _dispatch_worker_thread2 + 156 13 libsystem_pthread.dylib 0x199ebafd0 _pthread_wqthread + 228 14 libsystem_pthread.dylib 0x199eb9d28 start_wqthread + 8