6

Looking into asynchronous address resolution in winsock it seems that the only two options are either to use the blocking gethostbyname on a seperate thread, or use WSAAsyncGetHostByName. The latter is designed for some reason to work with window messages, instead of overlapped operations and completion ports/routines.

Is there any version of gethostbyname that works asynchronously with overlapped operations in a similiar manner to the rest of the winsock API?

sold
  • 2,041
  • 5
  • 25
  • 32
  • 1
    The "some reason" it was designed that way is that Winsock was created in the Win16 world, where there were no threads or console-mode programs. (There were DOS programs, but they had no access to Winsock, except by trickery.) All Windows programs had a GUI, or at least a message loop, by which the OS told the program of things that have happened. Notifying of finished name lookups through this mechanism makes sense, in that world. – Warren Young Nov 13 '09 at 21:54

2 Answers2

4

Unfortunately there isn't at present, although GetAddrInfoEx() has placeholders for all the right things for async operation via all of the 'usual' routes (including IOCP) so I expect there will be eventually... Unfortunately, at this time, the docs say that all of these must be set to NULL and are marked as 'reserved'. :(

I'm just about to write one (have been for a while)... It's unfortunate that WSAAsyncGetHostByName doesn't even allow concurrent name resolution, so it's pretty useless as a base for what I want; but, then again, since it doesn't handle IPv6 that also makes it pretty useless to me. I expect I'll start from scratch; possibly using something like this (beerware) as a base.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
1

Sorry, there is no overlapped version of gethostbyname().

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770