// 빌링에 관련된 윈도우 메세지가 처리되게 한다. BOOL CBillingMgrJP::PreTranslateMessage( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_CONNENT_BILLING: if( Connect() ) KillTimer( hWnd, IDT_RECONNECT ); else SetTimer( hWnd, IDT_RECONNECT, 2000, NULL ); return TRUE; case WM_TIMER: { switch( wParam ) { case IDT_RECONNECT: ::PostMessage( hWnd, WM_CONNENT_BILLING, 0, 0 ); return TRUE; case IDT_KEEPALIVE: SendKeepAlive(); return TRUE; case IDT_KICKOUT: g_AccountMng.KickOutCheck(); return TRUE; } } break; } return FALSE; }
void phddns_stop(PHGlobal *phglobal) { SendKeepAlive(phglobal, UDP_OPCODE_LOGOUT); phglobal->tmLastSend = time(0); sleep(1); //ensure data sent DestroySockets(phglobal); }
void DirClient::OnTimer() { if( ++m_beatCount >= KEEPALIVE_INTERVAL/PROC_TIMER_INTERVAL ) { SendKeepAlive(); m_beatCount = 0; } }
OutgoingDataCreator::OutgoingDataCreator(Application* app) : app_(app), ultimate_reader_(new UltimateLyricsReader(this)), fetcher_(new SongInfoFetcher(this)) { // Create Keep Alive Timer keep_alive_timer_ = new QTimer(this); connect(keep_alive_timer_, SIGNAL(timeout()), this, SLOT(SendKeepAlive())); keep_alive_timeout_ = 10000; }
void GameControllerServer::execute(void* arg) { char networkBuffer[GAMECONTROLLER_BUFFER_LENGTH]; struct timeval timeout; // timeout for socket access timeout.tv_sec = 0; timeout.tv_usec = 100000; uint64_t lastSendTime = 0; uint64_t currentTime = 0; do { if (mNetwork == NULL) { break; } if (mNetwork->receiveData(networkBuffer, (size_t)GAMECONTROLLER_BUFFER_LENGTH, &timeout, NULL, NULL) > 0) { // Check header if ( networkBuffer[0] == 'R' && networkBuffer[1] == 'G' && networkBuffer[2] == 'm' && networkBuffer[3] == 'e') { HandlePacket(&networkBuffer[0]); } } currentTime = getCurrentTime(); if (mWaitingForKickOffDelay) { if (currentTime >= mKickOffUnparalyzeTime) { Debugger::INFO("GameControllerServer", "Kick-off keepout over"); mGame->setBotAllowedToMove(true); mGame->setGameState(Game::PLAYING); mWaitingForKickOffDelay = false; } } if ((currentTime - lastSendTime) >= KEEPALIVE_INTERVAL) { SendKeepAlive(); lastSendTime = currentTime; } if (mLastMsgReceived != 0) { if (currentTime - mLastMsgReceived >= GAMECONTROLER_LOST_TIMEOUT) { Debugger::WARN("GameControllerServer", "No game controller messages received for %d ms, allowing robot to move", GAMECONTROLER_LOST_TIMEOUT); mGame->setBotAllowedToMove(true); mGame->setGameState(Game::PLAYING); mLastMsgReceived = 0; } } } while (IsRunning()); }
int ModemGSM::Dispatch() { int res = 0; int level; int ind; static int state=0; EvalNetworkLedStatus(); #ifdef REGISTRATION_DELAYED if(FNetworkRegDelayActive && FNetworkRegDelayTS.IsExpired()) { DEBUG_P(PSTR("Network Registration Delay Expired --> Now Registered To Network"LB)); FNetworkRegDelayActive = false; FRegisteredToNetwork = true; } #endif if(FLastKeepAliveTS.IsExpired()) { #if SIMULATION if(FPBReady) { int idx; char temp[30]; // switch(state % 3) //repeat commands switch(state) { case 0: { DEBUG_P(PSTR("---- Posting Fake SMS"LB)); WriteSMS("+390000000000", "ON 0000,22", &idx); sprintf_P(temp, PSTR("+CMTI: \"SM\",%d"), idx); break; } case 1: { DEBUG_P(PSTR("---- Posting Fake SMS"LB)); WriteSMS("+390000000000", "ON 0000,22", &idx); sprintf_P(temp, PSTR("+CMTI: \"SM\",%d"), idx); break; } default: { temp[0] = 0; if(!SendKeepAlive()) { FKeepAliveFailedCount++; //if the modem is not answering try the hard way ... if(FKeepAliveFailedCount > 5) { //Try to power off the modem SendCommand("AT+CPWROFF"); delay(1000); //Signal Error condition FError = true; return res; } } else { FError = false; FKeepAliveFailedCount = 0; } } } state++; if(temp[0]) { FURCQueue.Enqueue(temp); DEBUG_P(PSTR("---- Posted Fake SMS"LB)); } } else #endif if(!SendKeepAlive()) { FKeepAliveFailedCount++; //if the modem is not answering try the hard way ... if(FKeepAliveFailedCount > 5) { //Try to power off the modem SendCommand("AT+CPWROFF"); delay(1000); //Signal Error condition FError = true; return res; } } else { FError = false; FKeepAliveFailedCount = 0; } FLastKeepAliveTS.Reset(); }; int idx; //Check for Queued URC or Data from Modem SerialLine if((FURCQueue.Count() ? FURCQueue.Dequeue(FRXBuff, sizeof(FRXBuff)) : false) || (Readln(100, false) != TIMEOUT)) { if(sscanf_P(FRXBuff, PSTR("+CMTI: \"%*[^\"]\",%d"), &idx) == 1) { DEBUG_P(PSTR("SMS Received at -> %d"LB), idx); //Save SMS position in SM Memory, the SMS is stored by the Modem FSMSInQueue.Enqueue(idx); } else if((sscanf_P(FRXBuff,PSTR("+CMGS: %d"), &level) == 1) || (sscanf_P(FRXBuff,PSTR("+CMSS: %d"), &level) == 1)) { DEBUG_P(PSTR("Last Message Sent Successfully"LB)); } else if(sscanf_P(FRXBuff,PSTR("+CIEV: %d,%d"), &ind, &level) == 2) { if(ind == 2) { if((level >= 1) && (level <= 5)) { FSignalLevel = level; DEBUG_P(PSTR("Signal Strength --> %d"LB), level); } else { FSignalLevel = UNKNOWN_LEVEL; DEBUG_P(PSTR("**BAD Signal Strength --> %d"LB), level); } } } else if(sscanf_P(FRXBuff,PSTR("+CREG: %d"), &level) == 1) { if((level == 1) || (level == 5)) { #ifdef REGISTRATION_DELAYED DEBUG_P(PSTR("Registered to Network Indication --> Starting Delay"LB)); FNetworkRegDelayActive = true; //Wait for a while to be sure that SMS will work FNetworkRegDelayTS.Reset(); #else FRegisteredToNetwork = true; DEBUGLN_P(PSTR("Registered to Network"LB)); #endif } else { DEBUG_P(PSTR("NOT Registered to Network"LB)); FRegisteredToNetwork = false; #ifdef REGISTRATION_DELAYED FNetworkRegDelayActive = false; #endif } FLastBlinkTS.Reset(); EvalNetworkLedStatus(); } else if(strncmp(FRXBuff,"+XDRVI: ", 8) == 0) { resetCount++; DEBUG_P(PSTR("Module RESET"LB)); DiscardSerialInput(5000); InnerSetup(); } else if(strcmp_P(FRXBuff,PSTR("+PBREADY")) == 0) { FPBReady = true; for(int i = 0; i < 10; i++) if(ClearSMSMemory()) break; else { delay(1000); DEBUG_P(PSTR("Retrying .... "LB)); } FLastKeepAliveTS.Reset(); } else { DEBUG_P(PSTR("** Unhandled -> ")); DEBUGLN(FRXBuff); } } //Do not fire SMS retries if the network is not available if((FSMSOutQueue.Count() && FRegisteredToNetwork) && !(FSMSResendPending && !FSMSResendTS.IsExpired())) { int idx; FSMSOutQueue.Peek(&idx); if(SendSMSAtIndex(idx)) { SMSDequeue(qOut, NULL); FSMSResendPending = false; } else { //A retry failed ? if(FSMSResendPending) { //some other retry available ? if(FSMSRetry) { FSMSRetry--; FSMSResendTS.Reset(); DEBUG_P(PSTR("Retrying SMS Send. Retry Count --> %d"LB), (int)FSMSRetry); } else { //discard SMS FSMSResendPending = false; FSMSOutQueue.Dequeue(NULL); DEBUG_P(PSTR("** Too Many Retries SMS Send Aborted"LB)); } } else { //Start a delay and retry sequence FSMSRetry = SMS_RETRY_COUNT; FSMSResendPending = true; FSMSResendTS.Reset(); DEBUG_P(PSTR("Retrying SMS Send. Retry Count --> %d"LB), (int)FSMSRetry); } } } return res; }
int phddns_step(PHGlobal *phglobal) { int ret = 0; if (phglobal->bNeed_connect) { strcpy(phglobal->szActiveDomains[0],"."); phglobal->cLastResult = okConnecting; if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, 0); if (!InitializeSockets(phglobal)) { LOG(1) ("InitializeSockets failed, waiting for 5 seconds to retry...\n"); phglobal->cLastResult = errorConnectFailed; if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, 0); return 5; } ret = ExecuteUpdate(phglobal); phglobal->cLastResult = ret; if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, ret == okDomainsRegistered ? phglobal->nUserType : 0); if (ret == okDomainsRegistered) { //OnUserInfo(phglobal->szUserInfo); //OnAccountDomainInfo(phglobal->szDomainInfo); LOG(1) ("ExecuteUpdate OK, BeginKeepAlive!\n"); phglobal->bTcpUpdateSuccessed = TRUE; phglobal->tmLastResponse = time(0); phglobal->bNeed_connect = FALSE; BeginKeepAlive(phglobal); phglobal->lasttcptime = phglobal->tmLastSend = time(0); } else { if (ret == okRedirecting) { phglobal->bTcpUpdateSuccessed = FALSE; phglobal->bNeed_connect = TRUE; LOG(1) ("Need redirect, waiting for 5 seconds...\n"); return 5; } LOG(1) ("ExecuteUpdate failed, waiting for 30 seconds to retry...\n"); return 30; } phglobal->nLastResponseID = -1; } else { if (time(0) - phglobal->tmLastSend > (phglobal->nUserType >= 1 ? 30 : 60)) { SendKeepAlive(phglobal, UDP_OPCODE_UPDATE_VER2); phglobal->tmLastSend = time(0); } ret = RecvKeepaliveResponse(phglobal); if (ret != okNormal && ret != okNoData) phglobal->cLastResult = ret; if (ret == errorOccupyReconnect) { LOG(1) ("RecvKeepaliveResponse failed, waiting for 30 seconds to reconnect...\n"); phglobal->bNeed_connect = TRUE; phglobal->bTcpUpdateSuccessed = FALSE; return 30; } else { if (ret == okKeepAliveRecved) { struct in_addr t; t.s_addr = phglobal->ip; LOG(1) ("Keepalive response received, client ip: %s\n",inet_ntoa(t)); if (phglobal->cbOnStatusChanged) phglobal->cbOnStatusChanged(phglobal->cLastResult, phglobal->ip); } } if (time(0) - phglobal->tmLastResponse > (phglobal->nUserType >= 1 ? 160 : 320) && phglobal->tmLastResponse != -1) { LOG(1) ("No response from server for %d seconds, reconnect immediately...\n", (phglobal->nUserType == 1 ? 160 : 320)); phglobal->bTcpUpdateSuccessed = FALSE; phglobal->bNeed_connect = TRUE; return 1; } } return 1; }
BOOL CNatThread::Run() { RefreshServerIp(); bool bBeginWork = false; DWORD tmBeginWork= time(NULL); DWORD tmCheckKad = tmBeginWork; //while (theApp.emuledlg != NULL && theApp.emuledlg->IsRunning()) while(CGlobalVariable::IsRunning()) { if(m_bRegister) bBeginWork=true; else if(time(NULL) - tmBeginWork > 90) bBeginWork=true; if(m_bRegister && time(NULL)- m_dwSvrRetTime>200 ) { //失去NAT服务器连接 AddLogLine(false, _T("Lost connection with NAT traversal server\n")); m_dwSvrRetTime = time(NULL); m_bRegister = false; // 也许需要重新获取一下服务器的地址 RefreshServerIp(); } else if(bBeginWork) { CSingleLock locker(&m_Mutex, TRUE); try { CheckConnection(); SendKeepAlive(); SendConnBuffer(! m_bRegister); } catch(...) { TRACE("Exception: %s\n", __FUNCTION__); } } if(!m_bRegister && time(NULL)-m_RegisterTime > m_dwRegNextAttempInterval) { if(time(NULL) > m_tmNextRefreshSvr) RefreshServerIp(); RegisterMe(m_dwSvrIp, m_wSvrPort); //VC-fengwen on 2007/12/28 <begin> : 对服务器的注册重试改为指数退避。 m_dwRegAttemptTimes++; int iReminder = m_dwRegAttemptTimes % 12; if (0 == iReminder) // 尝试12后,过5分钟后再试。 m_dwRegNextAttempInterval = 300; else m_dwRegNextAttempInterval = min(64, ExpoBackoff(INIT_ATTEMPT_INTERVAL, iReminder)); //VC-fengwen on 2007/12/28 <end> : 对服务器的注册重试改为指数退避。 } if(m_bRegister && time(NULL)-m_RegisterTime>90) { RegisterMe(m_dwSvrIp, m_wSvrPort); } Sleep(100); } return false; }