Example #1
0
void CClientReConnectManager::GetConnectInfo(vecClientConnectInfo& VecClientConnectInfo)
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
    VecClientConnectInfo.clear();
    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)
        {
            if (NULL != pClientInfo->GetConnectClient())
            {
                _ClientConnectInfo ClientConnectInfo = pClientInfo->GetConnectClient()->GetClientConnectInfo();
                ClientConnectInfo.m_addrRemote = pClientInfo->GetServerAddr();
                VecClientConnectInfo.push_back(ClientConnectInfo);
            }
            else
            {
                _ClientConnectInfo ClientConnectInfo;
                ClientConnectInfo.m_blValid    = false;
                ClientConnectInfo.m_addrRemote = pClientInfo->GetServerAddr();
                VecClientConnectInfo.push_back(ClientConnectInfo);
            }
        }
    }
}
void CClientReConnectManager::GetConnectInfo(vecClientConnectInfo& VecClientConnectInfo)
{
	ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
	VecClientConnectInfo.clear();

	for (mapReactorConnectInfo::iterator b = m_mapConnectInfo.begin(); b != m_mapConnectInfo.end(); b++)
	{
		CReactorClientInfo* pClientInfo = (CReactorClientInfo*)b->second;

		if (NULL != pClientInfo)
		{
			if (NULL != pClientInfo->GetConnectClient())
			{
				_ClientConnectInfo ClientConnectInfo = pClientInfo->GetConnectClient()->GetClientConnectInfo();
				ClientConnectInfo.m_addrRemote = pClientInfo->GetServerAddr();
				VecClientConnectInfo.push_back(ClientConnectInfo);
			}
			else
			{
				_ClientConnectInfo ClientConnectInfo;
				ClientConnectInfo.m_blValid    = false;
				ClientConnectInfo.m_addrRemote = pClientInfo->GetServerAddr();
				VecClientConnectInfo.push_back(ClientConnectInfo);
			}
		}
	}
}
Example #3
0
bool CClientReConnectManager::Close(int nServerID)
{
    //如果是因为服务器断开,则只删除ProConnectClient的指针
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
    //查找已有连接
    char szServerID[10] = {'\0'};
    sprintf_safe(szServerID, 10, "%d", nServerID);
    CReactorClientInfo* pClientInfo = m_objClientTCPList.Get_Hash_Box_Data(szServerID);

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

    //关闭链接对象
    if (NULL != pClientInfo->GetConnectClient())
    {
        pClientInfo->GetConnectClient()->ClientClose();
        SAFE_DELETE(pClientInfo);
    }

    //从Hash里面删除当前存在的对象
    m_objClientTCPList.Del_Hash_Data(szServerID);

    return true;
}
Example #4
0
bool CClientReConnectManager::DeleteIClientMessage(IClientMessage* pClientMessage)
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);

    //将异步回调有效队列中此pClientMessage设置为无效
    App_ServerMessageTask::instance()->DelClientMessage(pClientMessage);

    //一一寻找与之对应的连接以及相关信息并删除之
    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->GetClientMessage() == pClientMessage)
        {
            //关闭连接,并删除对象。
            //关闭链接对象
            if (NULL != pClientInfo->GetConnectClient())
            {
                pClientInfo->GetConnectClient()->ClientClose();
            }

            char szServerID[10] = {'\0'};
            sprintf_safe(szServerID, 10, "%d", pClientInfo->GetServerID());

            SAFE_DELETE(pClientInfo);
            m_objClientTCPList.Del_Hash_Data(szServerID);
            return true;
        }
    }

    return true;
}
bool CClientReConnectManager::ReConnect(int nServerID)
{
	ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
	mapReactorConnectInfo::iterator f = m_mapConnectInfo.find(nServerID);

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

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

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

	if (NULL == pClientInfo->GetConnectClient())
	{
		//如果连接不存在,则重新建立连接
		pClientInfo->Run(m_blReactorFinish);
		return true;
	}
	else
	{
		return true;
	}
}
Example #6
0
bool CClientReConnectManager::ReConnect(int nServerID)
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
    char szServerID[10] = {'\0'};
    sprintf_safe(szServerID, 10, "%d", nServerID);

    CReactorClientInfo* pClientInfo = m_objClientTCPList.Get_Hash_Box_Data(szServerID);

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

    if (NULL == pClientInfo->GetConnectClient())
    {
        //如果连接不存在,则重新建立连接
        if (false == pClientInfo->Run(m_blReactorFinish, SERVER_CONNECT_RECONNECT))
        {
            OUR_DEBUG((LM_INFO, "[CClientReConnectManager::Close]Run error.\n"));
        }

        return true;
    }
    else
    {
        return true;
    }
}
bool CClientReConnectManager::Close(int nServerID, EM_s2s ems2s)
{
	//如果是因为服务器断开,则只删除ProConnectClient的指针
	ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
	mapReactorConnectInfo::iterator f = m_mapConnectInfo.find(nServerID);

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

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

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

	//关闭链接对象
	if (NULL != pClientInfo->GetConnectClient())
	{
		pClientInfo->GetConnectClient()->ClinetClose(ems2s);
	}

	if(S2S_NEED_CALLBACK == ems2s)
	{
		//SAFE_DELETE(pClientInfo);
		//从map里面删除当前存在的对象
		//m_mapConnectInfo.erase(f);
	}
	else
	{
		pClientInfo->Close();
		SAFE_DELETE(pClientInfo);
		//从map里面删除当前存在的对象
		m_mapConnectInfo.erase(f);
	}

	return true;
}
Example #8
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"));
}
Example #9
0
int CClientReConnectManager::handle_timeout(const ACE_Time_Value& tv, const void* arg)
{
    ACE_UNUSED_ARG(arg);
    ACE_UNUSED_ARG(tv);

    m_ThreadWritrLock.acquire();
    vector<CReactorClientInfo*> vecCReactorClientInfo;
    m_objClientTCPList.Get_All_Used(vecCReactorClientInfo);
    m_ThreadWritrLock.release();

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

        if(NULL != pClientInfo)
        {
            if (NULL == pClientInfo->GetConnectClient())
            {
                //如果连接不存在,则重新建立连接
                if (false == pClientInfo->Run(m_blReactorFinish, SERVER_CONNECT_RECONNECT))
                {
                    OUR_DEBUG((LM_INFO, "[CClientReConnectManager::handle_timeout]Run error.\n"));
                }
            }
            else
            {
                //检查当前连接,是否已挂起或死锁
                ACE_Time_Value tvNow = ACE_OS::gettimeofday();

                //如果是异步模式,则需要检查处理线程是否被挂起
                if(GetXmlConfigAttribute(xmlConnectServer)->RunType == 1)
                {
                    App_ServerMessageTask::instance()->CheckServerMessageThread(tvNow);
                }
            }
        }
    }

    return 0;
}
int CClientReConnectManager::handle_timeout(const ACE_Time_Value& tv, const void* arg)
{
	ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);

	if (arg != NULL)
	{
		OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::handle_timeout] arg is not NULL, tv = %d.\n", tv.sec()));
	}

	for (mapReactorConnectInfo::iterator b = m_mapConnectInfo.begin(); b != m_mapConnectInfo.end(); b++)
	{
		//int nServerID = (int)b->first;
		CReactorClientInfo* pClientInfo = (CReactorClientInfo*)b->second;

		if (NULL == pClientInfo->GetConnectClient())
		{
			//如果连接不存在,则重新建立连接
			pClientInfo->Run(m_blReactorFinish);
		}
	}

	return 0;
}