8

There's getaddrinfo() for blocking host resolution, but is there a non blocking method?

Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
Plumenator
  • 1,682
  • 3
  • 20
  • 49

4 Answers4

3

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.)

Community
  • 1
  • 1
Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
3

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...

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
shimpossible
  • 356
  • 2
  • 5
  • And to add further insult, [WSAConnectByName](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaconnectbynamea) (the function Microsoft [recommends be used](https://learn.microsoft.com/en-us/windows/win32/winsock/function-calls-2) to establish protocol agnostic outgoing connections) has an `OVERLAPPED` parameter, but it is *"Reserved for future implementation. This parameter must be set to **NULL**."* – Ian Boyd Mar 06 '20 at 03:48
3

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.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
0

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.

Steve
  • 7,171
  • 2
  • 30
  • 52