Bool HawkGateThread::OnThreadLoop() { if (m_pBase) { //日志记录 HawkFmtPrint("GateThread EventLoop, ThreadId: %u", HawkOSOperator::GetThreadId()); while (m_bRunning) { //设置默认空闲状态 m_bIdle = true; //开始消息循环 event_base_loop((event_base*)m_pBase, EVLOOP_ONCE | EVLOOP_NONBLOCK); //获取网关发送过来的数据消息 OnGatewayEvent(); //空闲状态 OnThreadIdle(); } return true; } return false; }
void CP2PApp::ThreadProcMain(void) { char szSendBuffer[TCP_MAX_BUFFER_LENGTH]; int nSendLen = 0; while ( !m_bWantStop ) { static DWORD dwLastTcpHeartbeatTime = GetTickCount(); CBaseCommand* pSendCmd = m_listTcpCmd.Pop(); // 非连接信令要求已认证后再行发送 while ( pSendCmd ) { nSendLen = 0; pSendCmd->Create( szSendBuffer, nSendLen ); if ( m_pClient ) { if ( m_pClient->sendData( szSendBuffer, nSendLen ) ) { m_transMonitorMgr.SendP2STcpSendMonitor( szSendBuffer, nSendLen); } } delete pSendCmd; dwLastTcpHeartbeatTime = GetTickCount(); pSendCmd = m_listTcpCmd.Pop(); } // 发送TCP心跳 if ( m_bAuthSucceed && (dwLastTcpHeartbeatTime + TCP_HEARTBEAT_INTERVAL) < GetTickCount() ) { dwLastTcpHeartbeatTime = GetTickCount(); //PushRequestCmd( P2S_COMMAND::CCommandFactory::CreateTcpHeartbeatCmd( UserID(), SessionID() , "" )); } OnThreadIdle(); m_evTcpCmd.Wait( 1 ); } }