问题描述
使用经典的nsswitch.conf配置:
Using a classic nsswitch.conf configuration :
hosts: files dns
如果DNS无法应答(或配置错误),尝试使用 gethostbyname (或 getaddrinfo )解析名称可能需要一段时间.
Trying to resolve a name using gethostbyname (or getaddrinfo) could take a while if the DNS does not answer (or is badly configured).
是否可以在nsswitch.conf中配置超时或使用替代API管理超时?
Is there a way to configure a timeout in nsswitch.conf or use an alternative api that manage a timeout ?
推荐答案
有 getaddrinfo_a ,但是特定于GNU glibc.另外,您可以生成一个线程并在其中调用getaddrinfo.不要在线程中使用gethostbyname,因为它不是线程安全.
There is getaddrinfo_a, but it is GNU glibc specific. Alternatively, you can spawn a thread and call getaddrinfo in it. Don't use gethostbyname in a thread, as it is not thread-safe.
这篇关于非阻塞网络地址解析(gethostbyname或getaddrinfo)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!