window 2003 ldap api的问题,求解答
操作系统:windows 2003 server
场景:一个定时程序,连接windows ad server同步数据
错误:运行一段时间后,api 函数ldap_get_next_page_s返回local_error错误,此时循环会结束,等待下一次定时,但从这以后的每一次的定时执行ldap_get_next_page_s总会返回local_other错误,除非重启进程
一下是部分代码:
unsigned long ulErrorCode = LDAP_SUCCESS;
LDAPMessage* pLDAPMessage = NULL;
PLDAPSearch pSearch = NULL;
pSearch = ldap_search_init_page(this->GetLADPHandle(),pszBaseDN,ulScope,
pszFilter,pszAttribs,0,NULL,NULL,this->GetTimeOut(),0,NULL);
if (pSearch == NULL)
{
this->SetLastError(::LdapGetLastError());
this->SetLastFuncName("ldap_search_init_page");
return false;
}
unsigned long ulTotalCount = 0;
l_timeval* pTimeOut = NULL;
l_timeval tTimeOut;
tTimeOut.tv_sec = this->GetTimeOut();
tTimeOut.tv_usec = 0;
if (this->GetTimeOut() > 0)
{
pTimeOut = &tTimeOut;
}
while(ulErrorCode == LDAP_SUCCESS)
{
ulErrorCode = ldap_get_next_page_s(this->GetLADPHandle(),pSearch,pTimeOut,this->GetPageSize(),&ulTotalCount,&pLDAPMessage);
if(ulErrorCode == LDAP_SUCCESS)
{
if(!this->ProcessSearchMessage(pLDAPMessage,vecLDAPEntryList,pLDAPEntryParent))
{
if(pLDAPMessage != NULL)
{
ldap_msgfree(pLDAPMessage);
pLDAPMessage = NULL;
}
ldap_search_abandon_page(this->GetLADPHandle(), pSearch);
//pSearch = NULL;
return false;
}
}
if(pLDAPMessage != NULL)
{
ldap_msgfree(pLDAPMessage);
pLDAPMessage = NULL;
}
}
ldap_search_abandon_page(this->GetLADPHandle(), pSearch);
//pSearch = NULL;
if(ulErrorCode != LDAP_NO_RESULTS_RETURNED)
{
this->SetLastError(ulErrorCode);
this->SetLastFuncName("ldap_get_next_page_s");
return false;
}
}
困扰很久了,就解答