int CBaseCommand::Do_DisConnect(IMessage* pMessage) { //处理连接断开事件 OUR_DEBUG((LM_ERROR, "[CBaseCommand::Do_DisConnect](%d)CLIENT_LINK_CDISCONNET OK.\n", pMessage->GetMessageBase()->m_u4ConnectID)); return 0; }
int CBaseCommand::Do_ClientSendTimeout(IMessage* pMessage) { //处理服务器发送客户端数据连接超过阀值的事件 OUR_DEBUG((LM_ERROR, "[CBaseCommand::Do_DisConnect](%d)CLINET_LINK_SNEDTIMEOUT OK.\n", pMessage->GetMessageBase()->m_u4ConnectID)); return 0; }
void CProConnectClient::Close() { m_ThreadWritrLock.acquire(); if(m_nIOCount > 0) { m_nIOCount--; } m_ThreadWritrLock.release(); if(m_nIOCount == 0) { m_Reader.cancel(); m_Writer.cancel(); if(this->handle() != ACE_INVALID_HANDLE) { ACE_OS::closesocket(this->handle()); this->handle(ACE_INVALID_HANDLE); } App_ClientProConnectManager::instance()->CloseByClient(m_nServerID); OUR_DEBUG((LM_DEBUG, "[CProConnectClient::Close]delete OK[0x%08x], m_ems2s=%d.\n", this, m_ems2s)); delete this; } }
int CAceProactor::open(void* args) { OUR_DEBUG((LM_ERROR, "CAceProactor::Open Begin nProactorID= [%d].\n", m_u4ProactorID)); if(activate(THR_NEW_LWP | THR_BOUND | THR_DETACHED, m_nThreadCount) == -1) { m_blRun = false; OUR_DEBUG((LM_ERROR, "[CAceProactor::Open]activate error ProactorType = [%d] nThreadCount = [%d] Start!\n", m_nProactorType, m_nThreadCount)); return -1; } else { m_blRun = true; OUR_DEBUG((LM_ERROR, "CAceProactor::Open Begin nProactorID= [%d] OK\n", m_u4ProactorID)); return 0; } }
int ConnectAcceptor::make_svc_handler(CConnectHandler*& sh) { //如果正在处理的链接超过了服务器设定的数值,则不允许链接继续链接服务器 if (App_ConnectHandlerPool::instance()->GetUsedCount() > App_MainConfig::instance()->GetMaxHandlerCount()) { OUR_DEBUG((LM_ERROR, "[ConnectAcceptor::make_svc_handler]Connect is more MaxHandlerCount(%d > %d).\n", App_ConnectHandlerPool::instance()->GetUsedCount(), App_MainConfig::instance()->GetMaxHandlerCount())); //不允许链接 return -1; } else { //允许链接 CConnectHandler* pConnectHandler = App_ConnectHandlerPool::instance()->Create(); if (NULL != pConnectHandler) { pConnectHandler->SetLocalIPInfo(m_szListenIP, m_u4Port); pConnectHandler->reactor(this->reactor()); sh = pConnectHandler; return 0; } else { return -1; } } }
int CBaseCommand::DoMessage_HttpData(IMessage* pMessage, bool& bDeleteFlag) { //处理接收到的握手数据,返回握手命令 char szReturnData[MAX_BUFF_500] = {'\0'}; int nLength = ACE_OS::strlen(RETURN_HTTP_HTML); sprintf_safe(szReturnData, MAX_BUFF_500, "HTTP /1.1 200 OK\r\nServer: PSS\r\nContent-Length: %d\r\nContent-Type: text/html\r\n\r\n%s", nLength, RETURN_HTTP_HTML); uint16 u2PostCommandID = COMMAND_RETURN_HTTP_DATA; //返回验证码 if(NULL != m_pServerObject->GetConnectManager()) { //发送全部数据 m_pServerObject->GetConnectManager()->PostMessage(pMessage->GetMessageBase()->m_u4ConnectID, szReturnData, (uint32)ACE_OS::strlen(szReturnData), SENDMESSAGE_JAMPNOMAL, u2PostCommandID, PACKET_SEND_IMMEDIATLY, PACKET_IS_SELF_RECYC); } else { OUR_DEBUG((LM_INFO, "[CBaseCommand::DoMessage_HandIn] m_pConnectManager = NULL.\n")); } return 0; }
void CLSServerManager::ReConnect(int nServerID) { OUR_DEBUG((LM_INFO, "[CLSServerManager::ReConnect]nServerID=%d.\n", nServerID)); //重新发送注册 Send_LG_Login(); return; }
bool CAceProactorManager::AddNewProactor(int nProactorID, int nProactorType, int nThreadCount) { CAceProactor* pAceProactor = new CAceProactor(); if(NULL == pAceProactor) { sprintf_safe(m_szError, MAX_BUFF_500, "[CAceProactorManager::AddNewProactor]New CAceProactor is NULL."); return false; } pAceProactor->SetProactorID((uint32)nProactorID); bool blState = pAceProactor->Init(nProactorType, nThreadCount); if(!blState) { sprintf_safe(m_szError, MAX_BUFF_500, "%s", pAceProactor->GetError()); SAFE_DELETE(pAceProactor); return false; } mapAceProactor::iterator f = m_mapAceProactor.find(nProactorID); if(f != m_mapAceProactor.end()) { sprintf_safe(m_szError, MAX_BUFF_500, "[CAceProactorManager::AddNewProactor]CAceProactor is exist[%d].", nProactorID); SAFE_DELETE(pAceProactor); return false; } m_mapAceProactor.insert(mapAceProactor::value_type(nProactorID, pAceProactor)); OUR_DEBUG((LM_INFO, "[CAceProactorManager::AddNewProactor]New [%d] ProactorType = [%d] nThreadCount = [%d]. pAceProactor=[%@]\n", nProactorID, nProactorType, nThreadCount,pAceProactor)); return true; }
int CAceProactor::svc() { if(NULL == m_pProactor) { OUR_DEBUG((LM_ERROR, "[CAceProactor::Svc]m_pProactor is NULL.\n", m_nProactorType, m_nThreadCount)); return -1; } else { m_blRun = true; m_pProactor->proactor_run_event_loop(); OUR_DEBUG((LM_ERROR, "CAceProactor::Svc] (%P|%t) Begin nProactorID= [%d] end .... \n", m_u4ProactorID)); return 0; } }
void CMakePacket::SetMessage(CPacketParse* pPacketParse, uint32 u4ConnectID, CMessage* pMessage) { //填充数据包头信息 _PacketHeadInfo objPacketHeadInfo; pPacketParse->GetPacketHeadInfo(objPacketHeadInfo); if(NULL != pMessage->GetMessageBase()) { //开始组装数据 pMessage->GetMessageBase()->m_u4ConnectID = u4ConnectID; pMessage->GetMessageBase()->m_u2Cmd = pPacketParse->GetPacketCommandID(); pMessage->GetMessageBase()->m_u4MsgTime = (uint32)ACE_OS::gettimeofday().sec(); pMessage->GetMessageBase()->m_u4HeadSrcSize = pPacketParse->GetPacketHeadSrcLen(); pMessage->GetMessageBase()->m_u4BodySrcSize = pPacketParse->GetPacketBodySrcLen(); //将接受的数据缓冲放入CMessage对象 pMessage->SetPacketHeadInfo(objPacketHeadInfo); pMessage->SetPacketHead(pPacketParse->GetMessageHead()); pMessage->SetPacketBody(pPacketParse->GetMessageBody()); } else { OUR_DEBUG((LM_ERROR, "[CProConnectHandle::SetMessage] ConnectID = %d, pMessage->GetMessageBase() is NULL.\n", u4ConnectID)); } }
bool CClientProConnectManager::ConnectUDP(int nServerID, const char* pIP, int nPort, uint8 u1IPType, IClientUDPMessage* pClientUDPMessage) { ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock); mapProactorUDPClientInfo::iterator f = m_mapProactorUDPClientInfo.find(nServerID); if(f != m_mapProactorUDPClientInfo.end()) { //如果这个链接已经存在,则不创建新的链接 OUR_DEBUG((LM_ERROR, "[CClientProConnectManager::ConnectUDP]nServerID =(%d) is exist.\n", nServerID)); return false; } CProactorUDPClient* pProactorUDPClient = new CProactorUDPClient(); if(NULL == pProactorUDPClient) { OUR_DEBUG((LM_ERROR, "[CClientProConnectManager::ConnectUDP]nServerID =(%d) pProactorUDPClient is NULL.\n", nServerID)); return false; } 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, "[CClientProConnectManager::ConnectUDP](%d)UDP set_address error[%d].\n", nServerID, errno)); SAFE_DELETE(pProactorUDPClient); return false; } if(0 != pProactorUDPClient->OpenAddress(AddrLocal, App_ProactorManager::instance()->GetAce_Proactor(REACTOR_UDPDEFINE), pClientUDPMessage)) { OUR_DEBUG((LM_INFO, "[CClientProConnectManager::ConnectUDP](%d)UDP OpenAddress error.\n", nServerID)); SAFE_DELETE(pProactorUDPClient); return false; } m_mapProactorUDPClientInfo[nServerID] = pProactorUDPClient; return true; }
int CBaseCommand::DoMessage(IMessage* pMessage, bool& bDeleteFlag) { //__ENTER_FUNCTION是自动给你的函数追加try的宏,用于捕捉错误,你可以使用__THROW_FUNCTION()抛出你的错误 //比如__THROW_FUNCTION("hello"); 它会自动在Log文件夹下的assert.log记录文件名,函数名,行数,描述。 //推荐你使用这个宏,记住一定要在函数的结束使用__LEAVE_FUNCTION或者__LEAVE_FUNCTION_WITHRETURN与之配对。 //__LEAVE_FUNCTION_WITHRETURN和__LEAVE_FUNCTION不同是前者可以支持函数退出的时候返回一个变量 //比如这个函数是返回一个int //那么末尾就是__LEAVE_FUNCTION_WITHRETURN(0); 0就是返回的int,当然,也支持别的类型变量,具体看你自己的函数。 //如果函数不返回任何变量,你可以使用__LEAVE_FUNCTION即可。 __ENTER_FUNCTION(); if(m_pServerObject == NULL) { OUR_DEBUG((LM_ERROR, "[CBaseCommand::DoMessage] m_pServerObject is NULL.\n")); return -1; } if(pMessage == NULL) { OUR_DEBUG((LM_ERROR, "[CBaseCommand::DoMessage] pMessage is NULL.\n")); return -1; } //处理链接建立信息 if(pMessage->GetMessageBase()->m_u2Cmd == CLIENT_LINK_CONNECT) { OUR_DEBUG((LM_ERROR, "[CBaseCommand::DoMessage] CLIENT_LINK_CONNECT OK.\n")); return 0; } //处理链接断开信息 if(pMessage->GetMessageBase()->m_u2Cmd == CLIENT_LINK_CDISCONNET) { OUR_DEBUG((LM_ERROR, "[CBaseCommand::DoMessage] CLIENT_LINK_CDISCONNET OK.\n")); return 0; } //处理正常信息 if(pMessage->GetMessageBase()->m_u2Cmd == COMMAND_PLUGA) { Do_PlugA_DATA(pMessage); } return 0; __LEAVE_FUNCTION_WITHRETURN(0); }
bool CBaseCommand::Do_LogData(IMessage* pMessage) { uint32 u4PacketLen = 0; uint16 u2CommandID = 0; uint32 u4Index = 0; //OUR_DEBUG((LM_INFO, "[CBaseCommand::DoMessage] CommandID = %d", COMMAND_BASE)); IBuffPacket* pBodyPacket = m_pServerObject->GetPacketManager()->Create(); if(NULL == pBodyPacket) { OUR_DEBUG((LM_ERROR, "[CBaseCommand::DoMessage] pBodyPacket is NULL.\n")); return false; } _PacketInfo BodyPacket; pMessage->GetPacketBody(BodyPacket); pBodyPacket->WriteStream(BodyPacket.m_pData, BodyPacket.m_nDataLen); (*pBodyPacket) >> u2CommandID; (*pBodyPacket) >> u4Index; m_pServerObject->GetPacketManager()->Delete(pBodyPacket); //写入日志 m_pServerObject->GetLogManager()->WriteLog(LOG_SYSTEM, "[Do_LogData]LogData nIdex=%d.", u4Index); IBuffPacket* pResponsesPacket = m_pServerObject->GetPacketManager()->Create(); uint16 u2PostCommandID = COMMAND_AUTOTEST_RETUEN_LOGDATA; (*pResponsesPacket) << u2PostCommandID; (*pResponsesPacket) << (uint32)0; if(NULL != m_pServerObject->GetConnectManager()) { //发送全部数据 m_pServerObject->GetConnectManager()->PostMessage(pMessage->GetMessageBase()->m_u4ConnectID, pResponsesPacket, SENDMESSAGE_NOMAL, u2PostCommandID, PACKET_SEND_IMMEDIATLY, PACKET_IS_FRAMEWORK_RECYC); } else { OUR_DEBUG((LM_INFO, "[CBaseCommand::DoMessage] m_pConnectManager = NULL")); m_pServerObject->GetPacketManager()->Delete(pResponsesPacket); } return true; }
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")); }
int CMessageService::Close() { m_blRun = false; msg_queue()->deactivate(); msg_queue()->flush(); OUR_DEBUG((LM_INFO, "[CMessageService::close] Close().\n")); return 0; }
bool CClientReConnectManager::SendData(int nServerID, char*& pData, int nSize, bool blIsDelete) { 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, "[CProConnectManager::SendData]nServerID =(%d) is not exist.\n", nServerID)); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } return false; } ACE_Message_Block* pmblk = App_MessageBlockManager::instance()->Create(nSize); if (NULL == pmblk) { OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::SendData]nServerID =(%d) pmblk is NULL.\n", nServerID)); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } return false; } memcpy_safe((char* )pData, (uint32)nSize, pmblk->wr_ptr(), (uint32)nSize); pmblk->wr_ptr(nSize); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } //发送数据 return pClientInfo->SendData(pmblk); }
void CBaseCommand::Do_Ftp_Login( IMessage* pMessage ) { VCHARS_STR strUserName; VCHARS_STR strUserPass; IBuffPacket* pBodyPacket = m_pServerObject->GetPacketManager()->Create(); if(NULL == pBodyPacket) { OUR_DEBUG((LM_ERROR, "[CBaseCommand::DoMessage] pBodyPacket is NULL.\n")); return; } _PacketInfo BodyPacket; pMessage->GetPacketBody(BodyPacket); pBodyPacket->WriteStream(BodyPacket.m_pData, BodyPacket.m_nDataLen); (*pBodyPacket) >> strUserName; (*pBodyPacket) >> strUserPass; //将接收数据转换为字符串 //这里可以添加用户自己的逻辑判定方法 IBuffPacket* pResponsesPacket = m_pServerObject->GetPacketManager()->Create(); uint16 u2PostCommandID = COMMAND_RETURN_LOGIN; //用户密码验证 uint32 u4Ret = CheckFtpUser(strUserName.text, strUserPass.text, pMessage->GetMessageBase()->m_u4ConnectID); //返回验证结果 (*pResponsesPacket) << (uint16)u2PostCommandID; //拼接应答命令ID (*pResponsesPacket) << (uint32)u4Ret; m_pServerObject->GetPacketManager()->Delete(pBodyPacket); if(NULL != m_pServerObject->GetConnectManager()) { //发送全部数据 m_pServerObject->GetConnectManager()->PostMessage(pMessage->GetMessageBase()->m_u4ConnectID, pResponsesPacket, SENDMESSAGE_NOMAL, u2PostCommandID, PACKET_SEND_IMMEDIATLY, PACKET_IS_FRAMEWORK_RECYC); } else { OUR_DEBUG((LM_INFO, "[CBaseCommand::DoMessage] m_pConnectManager = NULL")); m_pServerObject->GetPacketManager()->Delete(pResponsesPacket); } }
int CBaseCommand::Do_Base(IMessage* pMessage) { uint32 u4PacketLen = 0; uint16 u2CommandID = 0; uint64 u8ClientTime = 0; //OUR_DEBUG((LM_INFO, "[CBaseCommand::DoMessage] CommandID = %d", COMMAND_BASE)); //m_pServerObject->GetLogManager()->WriteToMail(LOG_SYSTEM, 1, "测试邮件", "测试"); IBuffPacket* pBodyPacket = m_pServerObject->GetPacketManager()->Create(); if(NULL == pBodyPacket) { OUR_DEBUG((LM_ERROR, "[CBaseCommand::DoMessage] pBodyPacket is NULL.\n")); return -1; } //处理接收数据 _PacketInfo BodyPacket; pMessage->GetPacketBody(BodyPacket); m_pServerObject->GetPacketManager()->Delete(pBodyPacket); IBuffPacket* pResponsesPacket = m_pServerObject->GetPacketManager()->Create(); uint16 u2PostCommandID = COMMAND_BASE; //调用Lua的接口并返回数据 Do_Execute_Lua_Function(pMessage, pResponsesPacket); if(NULL != m_pServerObject->GetConnectManager()) { //发送全部数据 m_pServerObject->GetConnectManager()->PostMessage(pMessage->GetMessageBase()->m_u4ConnectID, pResponsesPacket, SENDMESSAGE_JAMPNOMAL, u2PostCommandID, PACKET_SEND_IMMEDIATLY, PACKET_IS_FRAMEWORK_RECYC); } else { OUR_DEBUG((LM_INFO, "[CBaseCommand::DoMessage] m_pConnectManager = NULL")); m_pServerObject->GetPacketManager()->Delete(pResponsesPacket); } return 0; }
//用于模块间的调用接口 int DoModuleMessage(uint16 u2CommandID, IBuffPacket* pBuffPacket, IBuffPacket* pReturnBuffPacket) { OUR_DEBUG((LM_INFO, "[DoModuleMessage] u2CommandID=%d, size=%d, return=%d.\n", u2CommandID, pBuffPacket->GetPacketLen(), pReturnBuffPacket->GetPacketLen())); return 0; }
bool CClientReConnectManager::Connect(int nServerID, const char* pIP, int nPort, uint8 u1IPType, 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; } //开始链接 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; }
int UnLoadModuleData() { OUR_DEBUG((LM_INFO, "[Base UnLoadModuleData] Begin.\n")); if(g_pServerObject != NULL) { IMessageManager* pMessageManager = g_pServerObject->GetMessageManager(); if(NULL != pMessageManager) { pMessageManager->DelClientCommand(COMMAND_BASE, &g_BaseCommand); pMessageManager->DelClientCommand(CLIENT_LINK_CONNECT, &g_BaseCommand); pMessageManager->DelClientCommand(CLIENT_LINK_CDISCONNET, &g_BaseCommand); pMessageManager = NULL; } } OUR_DEBUG((LM_INFO, "[Base UnLoadModuleData] End.\n")); return 0; }
int CLogManager::open(void* args) { if(args != NULL) { OUR_DEBUG((LM_ERROR,"[CLogManager::open]args is not NULL.\n")); } if(activate(THREAD_PARAM, m_nThreadCount) == -1) { m_blRun = false; OUR_DEBUG((LM_ERROR,"[CLogManager::open] activate is error[%d].", errno)); return -1; } m_blRun = true; return 0; }
void CUnit_ThreadInfo::Test_ThreadInfo(void) { //测试创建指定的反应器 int blRet = false; blRet = m_pThreadInfo->AddThreadInfo(0); if (false == blRet) { OUR_DEBUG((LM_INFO, "[Test_ThreadInfo]m_pThreadInfo->AddThreadInfo() is fail.\n")); CPPUNIT_ASSERT_MESSAGE("[Test_ThreadInfo]m_pThreadInfo->AddThreadInfo() is fail.", true == blRet); return; } _ThreadInfo* pThreadInfo = m_pThreadInfo->GetThreadInfo(0); if (NULL == pThreadInfo) { OUR_DEBUG((LM_INFO, "[Test_ThreadInfo]m_pThreadInfo->GetThreadInfo(0) is fail.\n")); CPPUNIT_ASSERT_MESSAGE("[Test_ThreadInfo]m_pThreadInfo->GetThreadInfo(0) is fail.", true == blRet); return; } blRet = m_pThreadInfo->CloseThread(0); if (false == blRet) { OUR_DEBUG((LM_INFO, "[Test_ThreadInfo]m_pThreadInfo->CloseThread() is fail.\n")); CPPUNIT_ASSERT_MESSAGE("[Test_ThreadInfo]m_pThreadInfo->CloseThread() is fail.", true == blRet); return; } //测试关闭清理对象 blRet = m_pThreadInfo->AddThreadInfo(0); if (false == blRet) { OUR_DEBUG((LM_INFO, "[Test_ThreadInfo]m_pThreadInfo->Close() is fail.\n")); CPPUNIT_ASSERT_MESSAGE("[Test_ThreadInfo]m_pThreadInfo->Close() is fail.", true == blRet); return; } m_pThreadInfo->Close(); }
bool CAceProactorManager::StartProactorDefault() { OUR_DEBUG((LM_INFO, "[CAceProactorManager::StartProactorDefault]..1. .\n")); //启动默认的 Proactor mapAceProactor::iterator f = m_mapAceProactor.find(REACTOR_CLIENTDEFINE); if(f != m_mapAceProactor.end()) { CAceProactor* pAceProactor = (CAceProactor* )f->second; if(NULL != pAceProactor) { pAceProactor->Start(); } OUR_DEBUG((LM_INFO, "[CAceProactorManager::StartProactorDefault]... 2.\n")); } return true; }
int CTimeTask::handle_timeout(const ACE_Time_Value& tv, const void* arg) { ACE_UNUSED_ARG(tv); ACE_UNUSED_ARG(arg); OUR_DEBUG((LM_INFO, "[CTimeTask::handle_timeout]!!!!!!!!!!!!!!!!!!!!!!!!.\n")); return 0; }
//监控信号量线程 void *thread_Monitor(void *arg) { if(NULL != arg) { OUR_DEBUG((LM_INFO, "[thread_Monitor]arg is not NULL.\n")); pthread_exit(0); } bool blFlag = true; while(WaitQuitSignal::wait(blFlag)) { //OUR_DEBUG((LM_INFO, "[thread_Monitor]blFlag=false.\n")); sleep(1); } OUR_DEBUG((LM_INFO, "[thread_Monitor]exit.\n")); pthread_exit(0); }
bool CConsoleHandler::ServerClose() { OUR_DEBUG((LM_ERROR, "[CConsoleHandler::ServerClose]Close(%d) OK.\n", GetConnectID())); //AppLogManager::instance()->WriteLog(LOG_SYSTEM_CONNECT, "Close Connection from [%s:%d] RecvSize = %d, RecvCount = %d, SendSize = %d, SendCount = %d.",m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), m_u4AllRecvSize, m_u4AllRecvCount, m_u4AllSendSize, m_u4AllSendCount); //msg_queue()->deactivate(); shutdown(); m_u1ConnectState = CONNECT_SERVER_CLOSE; return true; }
bool CClientReConnectManager::SendData(int nServerID, const char* pData, int nSize, bool blIsDelete) { 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, "[CProConnectManager::SendData]nServerID =(%d) is not exist.\n", nServerID)); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } return false; } CReactorClientInfo* pClientInfo = (CReactorClientInfo*)f->second; ACE_Message_Block* pmblk = App_MessageBlockManager::instance()->Create(nSize); if (NULL == pmblk) { OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::SendData]nServerID =(%d) pmblk is NULL.\n", nServerID)); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } return false; } memcpy_safe((char* )pData, (uint32)nSize, pmblk->wr_ptr(), (uint32)nSize); pmblk->wr_ptr(nSize); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } //发送数据 return pClientInfo->SendData(pmblk); }
bool CSenceManager::PutMessage(uint32 u4CommandID, _CommandInfo& objCommandInfo) { _QueueMessage* pQueueMessage = m_objMessagePool.Create(); if(NULL == pQueueMessage) { OUR_DEBUG((LM_INFO,"[CSenceManager::PutMessage] m_objMessagePool not enougth!\n")); return false; } pQueueMessage->m_u4CommandID = u4CommandID; pQueueMessage->m_objData = objCommandInfo; ACE_Message_Block* pmb = m_objMessageBlockPool.Create(sizeof(_QueueMessage*)); if(NULL == pmb) { OUR_DEBUG((LM_INFO,"[CSenceManager::PutMessage] m_objMessageBlockPool not enougth!\n")); m_objMessagePool.Delete(pQueueMessage); return false; } _QueueMessage** ppMessage = (_QueueMessage **)pmb->base(); *ppMessage = pQueueMessage; //判断队列是否是已经最大 int nQueueCount = (int)msg_queue()->message_count(); if(nQueueCount >= (int)QUEUE_COUNT) { OUR_DEBUG((LM_ERROR,"[CSenceManager::PutMessage] Queue is Full nQueueCount = [%d].\n", nQueueCount)); m_objMessageBlockPool.Delete(pmb); m_objMessagePool.Delete(pQueueMessage); return false; } ACE_Time_Value xtime = ACE_OS::gettimeofday(); if(this->putq(pmb, &xtime) == -1) { OUR_DEBUG((LM_ERROR,"[CSenceManager::PutMessage] Queue putq error nQueueCount = [%d] errno = [%d].\n", nQueueCount, errno)); m_objMessageBlockPool.Delete(pmb); m_objMessagePool.Delete(pQueueMessage); return false; } 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; }