bool CClientReConnectManager::SendDataUDP(int nServerID, const char* pIP, int nPort, const char* pMessage, uint32 u4Len, bool blIsDelete)
{
	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, "[CProConnectManager::Close]nServerID =(%d) is not exist.\n", nServerID));

		if (true == blIsDelete)
		{
			SAFE_DELETE_ARRAY(pMessage);
		}

		return false;
	}

	CReactorUDPClient* pClientInfo = (CReactorUDPClient*)f->second;
	//发送数据
	bool blSendRet = pClientInfo->SendMessage(pMessage, u4Len, pIP, nPort);

	if (true == blIsDelete)
	{
		SAFE_DELETE_ARRAY(pMessage);
	}

	return blSendRet;
}
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"));
}
Esempio n. 3
0
bool CClientReConnectManager::SendDataUDP(int nServerID, const char* pIP, int nPort, char*& pMessage, uint32 u4Len, bool blIsDelete)
{
    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, "[CProConnectManager::Close]nServerID =(%d) is not exist.\n", nServerID));

        if (true == blIsDelete)
        {
            SAFE_DELETE_ARRAY(pMessage);
        }

        return false;
    }

    //发送数据
    bool blSendRet = pClientInfo->SendMessage(pMessage, u4Len, pIP, nPort);

    if (true == blIsDelete)
    {
        SAFE_DELETE_ARRAY(pMessage);
    }

    return blSendRet;
}
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;
}
bool CClientReConnectManager::ConnectUDP(int nServerID, const char* pIP, int nPort, uint8 u1IPType, IClientUDPMessage* pClientUDPMessage)
{
	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::ConnectUDP]nServerID =(%d) is exist.\n", nServerID));
		return false;
	}

	CReactorUDPClient* pReactorUDPClient = new CReactorUDPClient();

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

	m_mapReactorUDPConnectInfo[nServerID] = pReactorUDPClient;
	ACE_INET_Addr AddrLocal;
	int nErr = 0;

	if (u1IPType == TYPE_IPV4)
	{
		nErr = AddrLocal.set(nPort, pIP);
	}
	else
	{
		nErr = AddrLocal.set(nPort, pIP, 1, PF_INET6);
	}

	if (nErr != 0)
	{
		OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP set_address error[%d].\n", nServerID, errno));
		SAFE_DELETE(pReactorUDPClient);
		return false;
	}

	if (0 != pReactorUDPClient->OpenAddress(AddrLocal, App_ReactorManager::instance()->GetAce_Reactor(REACTOR_UDPDEFINE), pClientUDPMessage))
	{
		OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP OpenAddress error.\n", nServerID));
		SAFE_DELETE(pReactorUDPClient);
		return false;
	}

	return true;
}
Esempio n. 6
0
bool CClientReConnectManager::ConnectUDP(int nServerID, const char* pIP, int nPort, uint8 u1IPType, EM_UDP_TYPE emType, IClientUDPMessage* pClientUDPMessage)
{
    ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
    CReactorUDPClient* pReactorUDPClient = NULL;

    //初始化连接动作
    if (false == ConnectUdpInit(nServerID, pReactorUDPClient))
    {
        return false;
    }

    //初始化连接地址
    ACE_INET_Addr AddrLocal;
    int nErr = 0;

    if (emType != UDP_BROADCAST)
    {
        if (u1IPType == TYPE_IPV4)
        {
            nErr = AddrLocal.set(nPort, pIP);
        }
        else
        {
            nErr = AddrLocal.set(nPort, pIP, 1, PF_INET6);
        }
    }
    else
    {
        //如果是UDP广播
        AddrLocal.set(nPort, (uint32)INADDR_ANY);
    }

    if (nErr != 0)
    {
        OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP set_address error[%d].\n", nServerID, errno));
        SAFE_DELETE(pReactorUDPClient);
        return false;
    }

    //开始连接
    if (0 != pReactorUDPClient->OpenAddress(AddrLocal, emType, App_ReactorManager::instance()->GetAce_Reactor(REACTOR_UDPDEFINE), pClientUDPMessage))
    {
        OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP OpenAddress error.\n", nServerID));
        SAFE_DELETE(pReactorUDPClient);
        return false;
    }

    return true;
}
void CClientReConnectManager::GetUDPConnectInfo(vecClientConnectInfo& VecClientConnectInfo)
{
	VecClientConnectInfo.clear();

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

		if (NULL != pClientInfo)
		{
			_ClientConnectInfo ClientConnectInfo = pClientInfo->GetClientConnectInfo();
			VecClientConnectInfo.push_back(ClientConnectInfo);
		}
	}
}
Esempio n. 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"));
}
Esempio n. 9
0
void CClientReConnectManager::GetUDPConnectInfo(vecClientConnectInfo& VecClientConnectInfo)
{
    VecClientConnectInfo.clear();
    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)
        {
            _ClientConnectInfo ClientConnectInfo = pClientInfo->GetClientConnectInfo();
            VecClientConnectInfo.push_back(ClientConnectInfo);
        }
    }
}
Esempio n. 10
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;
}