void CClientReConnectManager::Close()
{
	ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
	OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Close]Begin.\n"));
	//如果有定时器,则删除定时器
	CancelConnectTask();

	//关闭所有已存在的链接
	for (mapReactorConnectInfo::iterator b = m_mapConnectInfo.begin(); b != m_mapConnectInfo.end(); b++)
	{
		CReactorClientInfo* pClientInfo = (CReactorClientInfo*)b->second;
		pClientInfo->Close();
		SAFE_DELETE(pClientInfo);
	}

	for (mapReactorUDPConnectInfo::iterator ub = m_mapReactorUDPConnectInfo.begin(); ub != m_mapReactorUDPConnectInfo.end(); ub++)
	{
		CReactorUDPClient* pClientInfo = (CReactorUDPClient*)ub->second;
		pClientInfo->Close();
		SAFE_DELETE(pClientInfo);
	}

	m_mapConnectInfo.clear();
	m_mapReactorUDPConnectInfo.clear();
	m_ActiveTimer.deactivate();
	OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Close]End.\n"));
}
bool CClientReConnectManager::CloseUDP(int nServerID)
{
	//如果是因为服务器断开,则只删除ProConnectClient的指针
	ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
	mapReactorUDPConnectInfo::iterator f = m_mapReactorUDPConnectInfo.find(nServerID);

	if (f == m_mapReactorUDPConnectInfo.end())
	{
		//如果这个链接已经存在,则不创建新的链接
		OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::CloseUDP]nServerID =(%d) is not exist.\n", nServerID));
		return false;
	}

	CReactorUDPClient* pClientInfo = (CReactorUDPClient*)f->second;

	if (NULL == pClientInfo)
	{
		OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::CloseUDP]nServerID =(%d) pClientInfo is NULL.\n", nServerID));
		return false;
	}

	pClientInfo->Close();
	SAFE_DELETE(pClientInfo);
	//从map里面删除当前存在的对象
	return true;
}
Esempio n. 3
0
void CClientReConnectManager::Close()
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
    OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Close]Begin.\n"));
    //如果有定时器,则删除定时器
    CancelConnectTask();

    //关闭所有已存在的链接
    vector<CReactorClientInfo*> vecReactorClientInfo;
    m_objClientTCPList.Get_All_Used(vecReactorClientInfo);

    for(int i = 0; i < (int)vecReactorClientInfo.size(); i++)
    {
        CReactorClientInfo* pClientInfo = vecReactorClientInfo[i];

        if(NULL != pClientInfo)
        {
            pClientInfo->GetConnectClient()->ClientClose();
            SAFE_DELETE(pClientInfo);
        }
    }

    m_objClientTCPList.Close();

    vector<CReactorUDPClient*> vecReactorUDPClient;
    m_objClientUDPList.Get_All_Used(vecReactorUDPClient);

    for(int i = 0; i < (int)vecReactorUDPClient.size(); i++)
    {
        CReactorUDPClient* pClientInfo = vecReactorUDPClient[i];

        if(NULL != pClientInfo)
        {
            pClientInfo->Close();
            SAFE_DELETE(pClientInfo);
        }
    }

    m_objClientUDPList.Close();
    m_u4MaxPoolCount = 0;

    //等待各自的连接对象自己关闭,因为不是在当前线程关闭,所以这里要等一下。
    ACE_Time_Value tvSleep(0, 10000);
    ACE_OS::sleep(tvSleep);

    OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Close]End.\n"));
}
Esempio n. 4
0
bool CClientReConnectManager::CloseUDP(int nServerID)
{
    //如果是因为服务器断开,则只删除ProConnectClient的指针
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
    //查找已有连接
    char szServerID[10] = {'\0'};
    sprintf_safe(szServerID, 10, "%d", nServerID);
    CReactorUDPClient* pClientInfo = m_objClientUDPList.Get_Hash_Box_Data(szServerID);

    if (NULL == pClientInfo)
    {
        OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::CloseUDP]nServerID =(%d) pClientInfo is NULL.\n", nServerID));
        return false;
    }

    pClientInfo->Close();
    SAFE_DELETE(pClientInfo);
    //从hash里面删除当前存在的对象
    m_objClientUDPList.Del_Hash_Data(szServerID);
    return true;
}