Пример #1
0
int CRoleDBThread::Run()
{
	int iRet = 0;
	int iCodeLen = 0;

    SHandleResult stMsgHandleResult;

	while (true)
	{
		//process all msg
		while (true)
		{
			iRet = ReceiveMsg(iCodeLen);
			//receive one msg
			if (0 == iRet)
			{
				iRet = m_stProtocolEngine.Decode((unsigned char*)m_szCodeBuf, iCodeLen, &m_stGameMsg);
				//decode success
				if (0 == iRet)
				{
					DEBUG_THREAD(m_iThreadIdx, "Receive code OK, Uin = %u, Msg = %d\n", 
						m_stGameMsg.m_stmsghead().m_uin(),
						m_stGameMsg.m_stmsghead().m_uimsgid());

					stMsgHandleResult.iNeedResponse = 0;
					stMsgHandleResult.stResponseMsg.Clear();

					iRet = ProcessMsg(stMsgHandleResult);
					if (0 == iRet)
					{					
						// 不需要回复
						if (!stMsgHandleResult.iNeedResponse)
						{
							continue;
						}

						iRet = EncodeAndSendMsg(stMsgHandleResult);
						if (iRet != 0)
						{
							TRACE_THREAD(m_iThreadIdx, "Error: encode and push fail. rt:%d\n", iRet);
						}
					}
				}
			}
			else
			{
				//no msg in
				break;
			}
		}
		
		usleep(APP_ROLEDB_MAX_SLEEP_USEC);
	}

	return 0;
}
Пример #2
0
void CThreadRedis::MyProcess()
{
	int iRet = 0;
	int iLen = 0;
	while (true)
	{
		iLen = 0;
		iRet = 0;
		//每次循环之前都清空之前的记录
		m_stGameMsg.Clear();
		memset(m_szMyCodeBuf,0,sizeof(m_szCodeBuf));

		iRet = m_pMyCodeQueue->GetHeadCode(m_szMyCodeBuf, &iLen);
		if(iRet < 0 || iLen <= (int)sizeof(unsigned short))
		{
			//printf("%d_MyProcess break\n",m_iThreadIdx);
			break;
		}
		else
		{
			//printf("total size:%d\n",iLen);
			iRet = m_ProtoEngine.Decode((unsigned char*)m_szMyCodeBuf,iLen,&m_stGameMsg);
			if(!iRet)
			{
//				Redis_GetUserInfo_Request stRequest = m_stGameMsg.m_stmsgbody().m_stuserkeyrequst();
//				unsigned int uiMsgID = m_stGameMsg.m_stmsghead().m_uimsgid();
//				printf("Receive code OK, idx = %d,Uin = %u, MsgID = %u,strKey=%s,MsgIdx=%u\n"
//						,m_iThreadIdx
//						,m_stGameMsg.m_stmsghead().m_uid()
//						,uiMsgID
//						,stRequest.strkey().c_str()
//						,m_stGameMsg.m_stmsghead().m_msgidx());

//				LPJOB_PROC pJobProc = Singleton<CProtoProcMgr>::GetInstance().FindProc(uiMsgID);
//				Singleton<CProtoProcMgr>::GetInstance().ExeMsg(uiMsgID,&m_RedisClient,&m_stGameMsg);
//				pJobProc(&m_RedisClient,&m_stGameMsg);

				iRet = ProcessMsg();
				if(iRet == 0)
				{
					EncodeAndSendMsg();
				}

			}
			else
			{
				printf("Decode Protocol buf failed %d\n",iRet);
			}
		}

	}
}