453jerry/NetDiagnosis

IPAddr resolve error

Closed this issue · 3 comments

IPAddr func resolve(domainName: String,
addressFamily: IPAddr.AddressFamily = .ipv4) throws -> [IPAddr]
When connecting to a WI-FI network without a network, it blocks the main thread

This is the test code
NetDemo.zip

Hi Loveying :
Yes the resolve function will block current thread, it's not a bug.
It call getaddrinfo() to resolve host name, and the getaddrinfo() is synchronous. So if DNS not work, the getaddrinfo() will block current thread and try to resolve host name until an error code is returned.
So if you want to avoid blocking the mian thread, The best way it not to call the reslove function on the main thread.

OK