fixed random dns errors caused by synchronization issues with m_thread_kill
for more details: http://forums.winamp.com/showthread.php?s=&threadid=247723 git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4716 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
4d504e2df8
commit
78b996033a
2 changed files with 21 additions and 14 deletions
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
JNL_AsyncDNS::JNL_AsyncDNS(int max_cache_entries)
|
JNL_AsyncDNS::JNL_AsyncDNS(int max_cache_entries)
|
||||||
{
|
{
|
||||||
m_thread_kill=1;
|
|
||||||
m_thread=0;
|
m_thread=0;
|
||||||
m_addr=0;
|
m_addr=0;
|
||||||
m_hostname[0]=0;
|
m_hostname[0]=0;
|
||||||
|
@ -21,13 +20,7 @@ JNL_AsyncDNS::JNL_AsyncDNS(int max_cache_entries)
|
||||||
|
|
||||||
JNL_AsyncDNS::~JNL_AsyncDNS()
|
JNL_AsyncDNS::~JNL_AsyncDNS()
|
||||||
{
|
{
|
||||||
m_thread_kill=1;
|
wait_for_thread_death();
|
||||||
|
|
||||||
if (m_thread)
|
|
||||||
{
|
|
||||||
WaitForSingleObject(m_thread,INFINITE);
|
|
||||||
CloseHandle(m_thread);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
||||||
|
@ -41,7 +34,6 @@ unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_this->m_addr=INADDR_NONE;
|
_this->m_addr=INADDR_NONE;
|
||||||
_this->m_thread_kill=1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,21 +48,35 @@ int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lstrcmpi(m_hostname,hostname)) m_addr=0;
|
if (lstrcmpi(m_hostname,hostname)) m_addr=0;
|
||||||
else if (m_addr == INADDR_NONE) return -1;
|
else if (m_addr == INADDR_NONE)
|
||||||
|
{
|
||||||
|
wait_for_thread_death();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
else if (m_addr)
|
else if (m_addr)
|
||||||
{
|
{
|
||||||
*addr=m_addr;
|
*addr=m_addr;
|
||||||
|
wait_for_thread_death();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
lstrcpy(m_hostname,hostname);
|
lstrcpy(m_hostname,hostname);
|
||||||
|
|
||||||
if (m_thread_kill)
|
if (!m_thread)
|
||||||
{
|
{
|
||||||
DWORD id;
|
DWORD id;
|
||||||
if (m_thread) return -1;
|
|
||||||
m_thread_kill=0;
|
|
||||||
m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id);
|
m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id);
|
||||||
if (!m_thread) return -1;
|
if (!m_thread) return -1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JNL_AsyncDNS::wait_for_thread_death()
|
||||||
|
{
|
||||||
|
if (m_thread)
|
||||||
|
{
|
||||||
|
WaitForSingleObject(m_thread,INFINITE);
|
||||||
|
CloseHandle(m_thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_thread=0;
|
||||||
|
}
|
||||||
|
|
|
@ -26,10 +26,11 @@ public:
|
||||||
int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable
|
int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void wait_for_thread_death();
|
||||||
|
|
||||||
char m_hostname[256];
|
char m_hostname[256];
|
||||||
unsigned long m_addr;
|
unsigned long m_addr;
|
||||||
|
|
||||||
volatile int m_thread_kill;
|
|
||||||
HANDLE m_thread;
|
HANDLE m_thread;
|
||||||
static unsigned long WINAPI _threadfunc(LPVOID _d);
|
static unsigned long WINAPI _threadfunc(LPVOID _d);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue