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;
	}
}
示例#2
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;
    }
}
示例#3
0
bool CClientReConnectManager::ConnectFrame(int nServerID, const char* pIP, int nPort, uint8 u1IPType, const char* pLocalIP, int nLocalPort, uint8 u1LocalIPType, uint32 u4PacketParseID)
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
    CReactorClientInfo* pClientInfo = NULL;

    //连接初始化动作
    if (false == ConnectTcpInit(nServerID, pIP, nPort, u1IPType, pLocalIP, nLocalPort, u1LocalIPType, NULL, pClientInfo, u4PacketParseID))
    {
        return false;
    }

    //开始链接
    if (false == pClientInfo->Run(m_blReactorFinish, SERVER_CONNECT_FIRST))
    {
        OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::ConnectFrame]Run Error.\n"));
        delete pClientInfo;
        pClientInfo = NULL;

        if (false == Close(nServerID))
        {
            OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectFrame]Close Error.\n"));
        }

        return false;
    }

    OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::ConnectFrame]nServerID =(%d) connect is OK.\n", nServerID));
    return true;
}
bool CClientReConnectManager::Connect(int nServerID, const char* pIP, int nPort, uint8 u1IPType, const char* pLocalIP, int nLocalPort, uint8 u1LocalIPType, IClientMessage* pClientMessage)
{
	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::Connect]nServerID =(%d) is exist.\n", nServerID));
		return false;
	}

	//初始化链接信息
	CReactorClientInfo* pClientInfo = new CReactorClientInfo();

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

	//链接已经建立,添加进map
	m_mapConnectInfo[nServerID] = pClientInfo;

	if (false == pClientInfo->Init(nServerID, pIP, nPort, u1IPType, &m_ReactorConnect, pClientMessage, m_pReactor))
	{
		OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Connect]pClientInfo Init Error.\n"));
		delete pClientInfo;
		pClientInfo = NULL;
		Close(nServerID);
		return false;
	}

	//设置本地IP和端口
	pClientInfo->SetLocalAddr(pLocalIP, nLocalPort, u1LocalIPType);

	//开始链接
	if (false == pClientInfo->Run(m_blReactorFinish, SERVER_CONNECT_FIRST))
	{
		OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Connect]Run Error.\n"));
		delete pClientInfo;
		pClientInfo = NULL;
		Close(nServerID);
		return false;
	}

	OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Connect]nServerID =(%d) connect is OK.\n", nServerID));
	return true;
}
示例#5
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;
}