Re: wininet: Make resolving hostnames thread safe.
2008/5/19 Hans Leidekker <hans(a)it.vu.nl>:
@@ -151,7 +158,21 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort, name = HeapAlloc(GetProcessHeap(), 0, sz+1); WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, name, sz, NULL, NULL ); name[sz] = 0; + +#ifdef HAVE_LINUX_GETHOSTBYNAME_R_6 + phe = NULL; + buf = HeapAlloc(GetProcessHeap(), 0, bufsize); + while (buf) + { + int res = gethostbyname_r(name, &hostentry, buf, bufsize, &phe, &locerr); + if (res != ERANGE) break; + bufsize *= 2; + buf = HeapReAlloc(GetProcessHeap(), 0, buf, bufsize); + } + HeapFree(GetProcessHeap(), 0, buf); +#else phe = gethostbyname(name); +#endif
In the long term it would be better to use getaddrinfo instead of gethostbyname/gethostbyname_r, but that's too big a change for 1.0. Rob
On Saturday 24 May 2008 20:04:14 Rob Shearman wrote:
In the long term it would be better to use getaddrinfo instead of gethostbyname/gethostbyname_r, but that's too big a change for 1.0.
My thoughts exactly. I looked at getaddrinfo first but realized that using it means writing new code, so I opted for copying a tried solution from winsock. -Hans
participants (2)
-
Hans Leidekker -
Rob Shearman