naptics / PlainPing

a very plain ping interface in swift
MIT License
58 stars 21 forks source link

No hostname resolve timeout #23

Open Sega-Zero opened 5 years ago

Sega-Zero commented 5 years ago

Since there is no SimplePing instance is cached, any ping call starts with hostname resolving. In a very bad networks (I've tested on Network Link Conditioner with 30% packet loss) there might be pretty big lag between the function call an actual ip address resolved by SimplePing.

Right now I had to workaround it with my own timeout, but it would be much better, if PlainPing could do this kind a stuff, since it declares a timeout ability.

Also, it would be much more effective to cache a resolved ip address (with some cache-control policies, of course), or, at least, return it into a completion, so a caller could use it to perform second ping slightly faster.

WestFlow127 commented 2 years ago

This would be good!

fchen09 commented 1 year ago

Since there is no SimplePing instance is cached, any ping call starts with hostname resolving. In a very bad networks (I've tested on Network Link Conditioner with 30% packet loss) there might be pretty big lag between the function call an actual ip address resolved by SimplePing.

Right now I had to workaround it with my own timeout, but it would be much better, if PlainPing could do this kind a stuff, since it declares a timeout ability.

Also, it would be much more effective to cache a resolved ip address (with some cache-control policies, of course), or, at least, return it into a completion, so a caller could use it to perform second ping slightly faster.

Hi, Sega Could you share how u fix the bid-lag problem? I appreciate it!

Sega-Zero commented 1 year ago

I made my timeout like this:

var timeout: (() -> Void)? = {
    debugPrint("own timeout")
}
DispatchQueue.main.asyncAfter(deadline: .now.advanced(by: .seconds(1))) {
    timeout?()
}
PlainPing.ping(address, withTimeout: 0.95) { (estimatedTime, err, resolvedIp) in
    timeout = nil
    debugPrint(estimatedTime, err, resolvedIp)
}