There's getaddrinfo()
for blocking host resolution, but is there a non blocking meth开发者_如何学JAVAod?
I don't think there is such a thing but you can always wrap it in a thread and use a semaphore to signal completion.
Linux has getaddrinfo_a()
. See the StackOverflow tag getaddrinfo-a, such as this question "How to use getaddrinfo_a to do async resolve with glibc". But I guess this isn't applicable for Windows.
There is a cross-platform library c-ares for asynchronous DNS requests, which says it runs on Windows. (I haven't tried it myself.)
From the MSDN page on GetAddrInfoEx the OVERLAPPED
parameter says:
On Windows 7 and Windows Server 2008 R2 or earlier, this parameter is currently reserved and must be set to NULL since asynchronous operations are not supported.
This means you can only use the OVERLAPPED
function in Windows 8 and newer. Unless steve can show otherwise that it works in older version of windows...
From Windows Vista and Windows Server 2008 you can use GetAddrInfoEx with an OVERLAPPED structure.
Once the hEvent
event is set in the OVERLAPPED
structure use GetAddrInfoExOverlappedResult.
精彩评论