[Common-cvs] netio iresolv.cpp,1.18,1.19
jzeng at helixcommunity.org jzeng at helixcommunity.orgUpdate of /cvsroot/common/netio
In directory cvs-new:/tmp/cvs-serv26465
Modified Files:
iresolv.cpp
Log Message:
Synopsis
=====================
The resolver doesn't work at the current time. A call to resolve name will end up with a CA.
Branch: head
Suggested reviewer: Tom Marshall
Description
=====================
The CA is caused by incorrect reference counting inside the resolver class. In addition, the resolver timeout code is not working.
In these fixes I make the timeout code work, and fix the CA.
Index: iresolv.cpp
===================================================================
RCS file: /cvsroot/common/netio/iresolv.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- iresolv.cpp 11 Nov 2004 20:54:54 -0000 1.18
+++ iresolv.cpp 12 Nov 2004 22:34:12 -0000 1.19
@@ -237,9 +237,11 @@
m_nRefCount(0),
m_pOwner(NULL),
m_pCCF(NULL),
+ m_pScheduler(NULL),
m_pSock(NULL),
m_qidIN4(0),
- m_qidIN6(0)
+ m_qidIN6(0),
+ m_CallbackHandle(0)
{
m_family = f;
strcpy(m_szNode, pNode);
@@ -251,30 +253,33 @@
{
HX_RELEASE(m_pSock);
HX_RELEASE(m_pCCF);
+ HX_RELEASE(m_pScheduler);
HX_RELEASE(m_pOwner);
}
void
-CNodeQuery::Init(CIntResolver* pOwner, IHXCommonClassFactory* pCCF, IHXSocket* pSock)
+CNodeQuery::Init(CIntResolver* pOwner, IUnknown* punkContext, IHXSocket* pSock)
{
m_pOwner = pOwner;
m_pOwner->AddRef();
- m_pCCF = pCCF;
- m_pCCF->AddRef();
m_pSock = pSock;
m_pSock->AddRef();
+ punkContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&m_pCCF);
+ HX_ASSERT(m_pCCF != NULL);
+
+ punkContext->QueryInterface(IID_IHXScheduler, (void**)&m_pScheduler);
+ HX_ASSERT(m_pScheduler != NULL);
+
// Initial query delta in milliseconds
- UINT32 nDelta = 4000/g_nNameservers;
+ m_nDelta = 4000/g_nNameservers;
- gettimeofday(&m_tvExpire, NULL);
- m_tvDelta.tv_sec = nDelta/1000;
- m_tvDelta.tv_usec = nDelta%1000;
- tv_add(m_tvExpire, m_tvDelta);
m_nRetries = 0;
m_nCurDomain = -1;
m_nCurServer = 0;
+ m_CallbackHandle = m_pScheduler->RelativeEnter(this, m_nDelta);
+
if (m_family == HX_SOCK_FAMILY_INANY || m_family == HX_SOCK_FAMILY_IN6)
{
SendRequest(HX_SOCK_FAMILY_IN6);
@@ -374,12 +379,10 @@
return;
}
- HXTime tvnow;
dns_qr_hdr qrhdr;
dns_rr_hdr rrhdr;
char szHost[MAX_HOST_LEN];
- gettimeofday(&tvnow, NULL);
while (hdr.qdcnt--)
{
if (!ParseQuestionHeader(&qrhdr, buf, len, pos))
@@ -467,6 +470,10 @@
if (m_qidIN4 == 0 && m_qidIN6 == 0)
{
m_pOwner->QueryDone(HXR_OK, m_szNode);
+ if (m_CallbackHandle)
+ {
+ m_pScheduler->Remove(m_CallbackHandle);
+ }
}
}
else
@@ -491,14 +498,14 @@
{
// We exhausted the search list
m_pOwner->QueryDone(HXR_FAIL, m_szNode);
+ if (m_CallbackHandle)
+ {
+ m_pScheduler->Remove(m_CallbackHandle);
+ }
}
else
{
- UINT32 nDelta = 4000/g_nNameservers;
- m_tvDelta.tv_sec = nDelta/1000;
- m_tvDelta.tv_usec = nDelta%1000;
- m_tvExpire = tvnow;
- tv_add(m_tvExpire, m_tvDelta);
+ m_nDelta = 4000/g_nNameservers;
m_nRetries = 0;
strcpy(szHost, m_szNode);
@@ -560,57 +567,50 @@
STDMETHODIMP
CNodeQuery::Func(void)
{
- HXTime tvNow;
- gettimeofday(&tvNow, NULL);
-
// XXXTDM: if we sent multiple queries and got at least one response,
// we should call m_pOwner->QueryDone(HXR_OK, m_szNode) here
- if (m_tvExpire.tv_sec < tvNow.tv_sec ||
- (m_tvExpire.tv_sec == tvNow.tv_sec &&
- m_tvExpire.tv_usec < tvNow.tv_usec))
+ AddRef();
+ // Query timed out -- next nameserver
+ m_nCurServer++;
+ if(m_nCurServer >= g_nNameservers)
{
- // Query timed out -- next nameserver
- m_nCurServer++;
- if(m_nCurServer >= g_nNameservers)
+ // Nameserver list exhausted, bump timeout
+ m_nCurServer = 0;
+ m_nRetries++;
+ if(m_nRetries >= 3)
{
- // Nameserver list exhausted, bump timeout
- m_nCurServer = 0;
- m_nRetries++;
- if(m_nRetries >= 4)
- {
- // Absolute timeout -- fail the query
- m_pOwner->QueryDone(HXR_FAIL, m_szNode);
- return HXR_OK;
- }
-
- tv_add(m_tvDelta, m_tvDelta);
-
- m_tvExpire = tvNow;
- tv_add(m_tvExpire, m_tvDelta);
+ // Absolute timeout -- fail the query
+ m_pOwner->QueryDone(HXR_FAIL, m_szNode);
+ Release();
+ return HXR_OK;
}
+ m_nDelta *= 2;
+ }
- char szHost[MAX_HOST_LEN];
- strcpy(szHost, m_szNode);
- if(m_nCurDomain >= 0)
- {
- strcat(szHost, ".");
- strcat(szHost, g_szSearchDomains[m_nCurDomain]);
- }
+ char szHost[MAX_HOST_LEN];
+ strcpy(szHost, m_szNode);
+ if(m_nCurDomain >= 0)
+ {
+ strcat(szHost, ".");
+ strcat(szHost, g_szSearchDomains[m_nCurDomain]);
+ }
- if (m_family == HX_SOCK_FAMILY_INANY || m_family == HX_SOCK_FAMILY_IN4)
- {
- m_pOwner->DelQuery(m_qidIN4, this);
- m_qidIN4 = 0;
- SendRequest(HX_SOCK_FAMILY_IN4);
- }
- if (m_family == HX_SOCK_FAMILY_INANY || m_family == HX_SOCK_FAMILY_IN6)
- {
- m_pOwner->DelQuery(m_qidIN6, this);
- m_qidIN6 = 0;
- SendRequest(HX_SOCK_FAMILY_IN6);
- }
+ m_CallbackHandle = m_pScheduler->RelativeEnter(this, m_nDelta);
+
+ if (m_family == HX_SOCK_FAMILY_INANY || m_family == HX_SOCK_FAMILY_IN4)
+ {
+ m_pOwner->DelQuery(m_qidIN4, this);
+ m_qidIN4 = 0;
+ SendRequest(HX_SOCK_FAMILY_IN4);
+ }
+ if (m_family == HX_SOCK_FAMILY_INANY || m_family == HX_SOCK_FAMILY_IN6)
+ {
+ m_pOwner->DelQuery(m_qidIN6, this);
+ m_qidIN6 = 0;
+ SendRequest(HX_SOCK_FAMILY_IN6);
}
+ Release();
return HXR_OK;
}
@@ -1036,6 +1036,7 @@
m_mapHostQueries.GetNextAssoc(pos, lQueryID, (void*&)pQuery);
HX_RELEASE(pQuery);
}
+ m_mapHostQueries.RemoveAll();
if (m_pSock)
{
@@ -1200,7 +1201,7 @@
// Looks like we have to send a query
CNodeQuery* pQuery = new CNodeQuery(f, pNode);
pQuery->AddRef();
- pQuery->Init(this, m_pCCF, m_pSock);
+ pQuery->Init(this, m_punkContext, m_pSock);
pQuery->Release();
return HXR_OK;