Hans Leidekker : wininet: Make resolving hostnames thread-safe.
Alexandre Julliard
julliard at winehq.org
Mon Jun 2 07:24:24 CDT 2008
Module: wine
Branch: master
Commit: 2f99450c49ccfe0e4cf2f8b39ac0e7b350d3dbc6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=2f99450c49ccfe0e4cf2f8b39ac0e7b350d3dbc6
Author: Hans Leidekker <hans at it.vu.nl>
Date: Sat May 31 21:46:07 2008 +0200
wininet: Make resolving hostnames thread-safe.
---
dlls/wininet/http.c | 4 +++-
dlls/wininet/utility.c | 14 ++++++++++++++
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 119b49b..2326a7a 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -1346,6 +1346,8 @@ static BOOL HTTP_ResolveName(LPWININETHTTPREQW lpwhr)
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
INTERNET_STATUS_NAME_RESOLVED,
szaddr, strlen(szaddr)+1);
+
+ TRACE("resolved %s to %s\n", debugstr_w(lpwhs->lpszServerName), szaddr);
return TRUE;
}
@@ -3607,7 +3609,7 @@ static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr)
if (!NETCON_create(&lpwhr->netConnection, lpwhs->socketAddress.sin_family,
SOCK_STREAM, 0))
{
- WARN("Socket creation failed\n");
+ WARN("Socket creation failed: %u\n", INTERNET_GetLastError());
goto lend;
}
diff --git a/dlls/wininet/utility.c b/dlls/wininet/utility.c
index 2597268..b0d9c9c 100644
--- a/dlls/wininet/utility.c
+++ b/dlls/wininet/utility.c
@@ -40,6 +40,16 @@
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
+/* critical section to protect non-reentrant gethostbyname() */
+static CRITICAL_SECTION cs_gethostbyname;
+static CRITICAL_SECTION_DEBUG critsect_debug =
+{
+ 0, 0, &cs_gethostbyname,
+ { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
+ 0, 0, { (DWORD_PTR)(__FILE__ ": cs_gethostbyname") }
+};
+static CRITICAL_SECTION cs_gethostbyname = { &critsect_debug, -1, 0, 0, 0, 0 };
+
#define TIME_STRING_LEN 30
time_t ConvertTimeString(LPCWSTR asctime)
@@ -151,12 +161,15 @@ 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;
+
+ EnterCriticalSection( &cs_gethostbyname );
phe = gethostbyname(name);
HeapFree( GetProcessHeap(), 0, name );
if (NULL == phe)
{
TRACE("Failed to get hostname: (%s)\n", debugstr_w(lpszServerName) );
+ LeaveCriticalSection( &cs_gethostbyname );
return FALSE;
}
@@ -165,6 +178,7 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
psa->sin_family = phe->h_addrtype;
psa->sin_port = htons(nServerPort);
+ LeaveCriticalSection( &cs_gethostbyname );
return TRUE;
}
More information about the wine-cvs
mailing list