void AFXAPI AfxAssertValidObject( CObject *pObject, LPCSTR lpszFileName, int nLine ) /**********************************************************************************/ { if( pObject == NULL ) { if( AfxAssertFailedLine( lpszFileName, nLine ) ) { AfxDebugBreak(); } return; } if( ::IsBadReadPtr( pObject, sizeof( CObject ) ) || ::IsBadWritePtr( pObject, sizeof( CObject ) ) ) { if( AfxAssertFailedLine( lpszFileName, nLine ) ) { AfxDebugBreak(); } return; } CRuntimeClass *pClass = pObject->GetRuntimeClass(); if( pClass == NULL ) { if( AfxAssertFailedLine( lpszFileName, nLine ) ) { AfxDebugBreak(); } return; } int nObjectSize = pClass->m_nObjectSize; if( ::IsBadReadPtr( pObject, nObjectSize ) || ::IsBadWritePtr( pObject, nObjectSize ) ) { if( AfxAssertFailedLine( lpszFileName, nLine ) ) { AfxDebugBreak(); } return; } pObject->AssertValid(); }
void CListenSocket::Debug_ClientDeleted(CUpDownClient* deleted) { for (POSITION pos = socket_list.GetHeadPosition(); pos != NULL;) { CClientReqSocket* cur_sock = socket_list.GetNext(pos); if (!AfxIsValidAddress(cur_sock, sizeof(CClientReqSocket))) AfxDebugBreak(); if (thePrefs.m_iDbgHeap >= 2) ASSERT_VALID(cur_sock); if (cur_sock->client == deleted) AfxDebugBreak(); } }
void CClientList::Debug_SocketDeleted(CClientReqSocket* deleted) const { for (POSITION pos = list.GetHeadPosition(); pos != NULL;){ CUpDownClient* cur_client = list.GetNext(pos); if (!AfxIsValidAddress(cur_client, sizeof(CUpDownClient))) { AfxDebugBreak(); } if (thePrefs.m_iDbgHeap >= 2) ASSERT_VALID(cur_client); if (cur_client->socket == deleted){ AfxDebugBreak(); } } }
BOOL CRenoCommandFrame::CmdStatus(const CStringPtrArray& commandElements) { switch(m_State) { case RENO_NETWORK_DISCONNECTED: PrintFormat(TEXT("* Not connected\r\n")); break; case RENO_NETWORK_CONNECTING: PrintFormat(TEXT("* Connecting\r\n")); break; case RENO_NETWORK_CONNECTED: PrintFormat(TEXT("* Connected\r\n")); break; case RENO_NETWORK_RESOLVING: PrintFormat(TEXT("* Resolving host address\r\n")); break; case RENO_NETWORK_DISCONNECTING: PrintFormat(TEXT("* Disconnecting\r\n")); break; default: PrintFormat(TEXT("* Unknown state\r\n")); AfxDebugBreak(); break; } return TRUE; }
void XSYSTEM::xDebugBreak( void ) { #ifdef WIN32 #if defined(_SERVER) && !defined(_XNOT_BREAK) #if defined(_AFX) || defined(_AFXDLL) AfxDebugBreak(); #else DebugBreak(); #endif #endif // server && not break; #else volatile int nBreak = 0; nBreak = 1; #endif }
VOID CALLBACK CUploadQueue::UploadTimer(HWND /*hwnd*/, UINT /*uMsg*/, UINT_PTR /*idEvent*/, DWORD /*dwTime*/) { // NOTE: Always handle all type of MFC exceptions in TimerProcs - otherwise we'll get mem leaks try { // Barry - Don't do anything if the app is shutting down - can cause unhandled exceptions if (!theApp.emuledlg->IsRunning()) return; // Elandal:ThreadSafeLogging --> // other threads may have queued up log lines. This prints them. theApp.HandleDebugLogQueue(); theApp.HandleLogQueue(); // Elandal: ThreadSafeLogging <-- // ZZ:UploadSpeedSense --> theApp.lastCommonRouteFinder->SetPrefs(thePrefs.IsDynUpEnabled(), theApp.uploadqueue->GetDatarate(), thePrefs.GetMinUpload()*1024, (thePrefs.GetMaxUpload() != 0) ? thePrefs.GetMaxUpload() * 1024 : thePrefs.GetMaxGraphUploadRate(false) * 1024, thePrefs.IsDynUpUseMillisecondPingTolerance(), (thePrefs.GetDynUpPingTolerance() > 100) ? ((thePrefs.GetDynUpPingTolerance() - 100) / 100.0f) : 0, thePrefs.GetDynUpPingToleranceMilliseconds(), thePrefs.GetDynUpGoingUpDivider(), thePrefs.GetDynUpGoingDownDivider(), thePrefs.GetDynUpNumberOfPings(), 20); // PENDING: Hard coded min pLowestPingAllowed // ZZ:UploadSpeedSense <-- theApp.uploadqueue->Process(); theApp.downloadqueue->Process(); if (thePrefs.ShowOverhead()){ theStats.CompUpDatarateOverhead(); theStats.CompDownDatarateOverhead(); } counter++; // one second if (counter >= 10){ counter=0; // try to use different time intervals here to not create any disk-IO bottle necks by saving all files at once theApp.clientcredits->Process(); // 13 minutes theApp.serverlist->Process(); // 17 minutes theApp.knownfiles->Process(); // 11 minutes theApp.friendlist->Process(); // 19 minutes theApp.clientlist->Process(); theApp.sharedfiles->Process(); if( Kademlia::CKademlia::IsRunning() ) { Kademlia::CKademlia::Process(); if(Kademlia::CKademlia::GetPrefs()->HasLostConnection()) { Kademlia::CKademlia::Stop(); theApp.emuledlg->ShowConnectionState(); } } if( theApp.serverconnect->IsConnecting() && !theApp.serverconnect->IsSingleConnect() ) theApp.serverconnect->TryAnotherConnectionRequest(); theApp.listensocket->UpdateConnectionsStatus(); if (thePrefs.WatchClipboard4ED2KLinks()) { // TODO: Remove this from here. This has to be done with a clipboard chain // and *not* with a timer!! theApp.SearchClipboard(); } if (theApp.serverconnect->IsConnecting()) theApp.serverconnect->CheckForTimeout(); // -khaos--+++> Update connection stats... iupdateconnstats++; // 2 seconds if (iupdateconnstats>=2) { iupdateconnstats=0; theStats.UpdateConnectionStats((float)theApp.uploadqueue->GetDatarate()/1024, (float)theApp.downloadqueue->GetDatarate()/1024); } // <-----khaos- // display graphs if (thePrefs.GetTrafficOMeterInterval()>0) { igraph++; if (igraph >= (uint32)(thePrefs.GetTrafficOMeterInterval()) ) { igraph=0; //theApp.emuledlg->statisticswnd->SetCurrentRate((float)(theApp.uploadqueue->Getavgupload()/theApp.uploadqueue->Getavg())/1024,(float)(theApp.uploadqueue->Getavgdownload()/theApp.uploadqueue->Getavg())/1024); theApp.emuledlg->statisticswnd->SetCurrentRate((float)(theApp.uploadqueue->GetDatarate())/1024,(float)(theApp.downloadqueue->GetDatarate())/1024); //theApp.uploadqueue->Zeroavg(); } } if (theApp.emuledlg->activewnd == theApp.emuledlg->statisticswnd && theApp.emuledlg->IsWindowVisible() ) { // display stats if (thePrefs.GetStatsInterval()>0) { istats++; if (istats >= (uint32)(thePrefs.GetStatsInterval()) ) { istats=0; theApp.emuledlg->statisticswnd->ShowStatistics(); } } } theApp.uploadqueue->UpdateDatarates(); //save rates every second theStats.RecordRate(); // mobilemule sockets #ifdef MobileMule theApp.mmserver->Process(); #endif // ZZ:UploadSpeedSense --> theApp.emuledlg->ShowPing(); bool gotEnoughHosts = theApp.clientlist->GiveClientsForTraceRoute(); if(gotEnoughHosts == false) { theApp.serverlist->GiveServersForTraceRoute(); } // ZZ:UploadSpeedSense <-- if (theApp.emuledlg->IsTrayIconToFlash()) theApp.emuledlg->ShowTransferRate(true); sec++; // *** 5 seconds ********************************************** if (sec >= 5) { #ifdef _DEBUG if (thePrefs.m_iDbgHeap > 0 && !AfxCheckMemory()) AfxDebugBreak(); #endif sec = 0; theApp.listensocket->Process(); theApp.OnlineSig(); // Added By Bouc7 if (!theApp.emuledlg->IsTrayIconToFlash()) theApp.emuledlg->ShowTransferRate(); thePrefs.EstimateMaxUploadCap(theApp.uploadqueue->GetDatarate()/1024); if (!thePrefs.TransferFullChunks()) theApp.uploadqueue->UpdateMaxClientScore(); // update cat-titles with downloadinfos only when needed if (thePrefs.ShowCatTabInfos() && theApp.emuledlg->activewnd == theApp.emuledlg->transferwnd && theApp.emuledlg->IsWindowVisible()) theApp.emuledlg->transferwnd->UpdateCatTabTitles(false); #ifdef Scheduler if (thePrefs.IsSchedulerEnabled()) theApp.scheduler->Check(); #endif theApp.emuledlg->transferwnd->UpdateListCount(CTransferWnd::wnd2Uploading, -1); } statsave++; // *** 60 seconds ********************************************* if (statsave >= 60) { statsave=0; if (thePrefs.GetWSIsEnabled()) theApp.webserver->UpdateSessionCount(); theApp.serverconnect->KeepConnectionAlive(); if (thePrefs.GetPreventStandby()) theApp.ResetStandByIdleTimer(); // Reset Windows idle standby timer if necessary } s_uSaveStatistics++; if (s_uSaveStatistics >= thePrefs.GetStatsSaveInterval()) { s_uSaveStatistics = 0; thePrefs.SaveStats(); } } // need more accuracy here. don't rely on the 'sec' and 'statsave' helpers. thePerfLog.LogSamples(); } CATCH_DFLT_EXCEPTIONS(_T("CUploadQueue::UploadTimer")) }
BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine) { TCHAR szMessage[_MAX_PATH*2]; // handle the (hopefully rare) case of AfxGetAllocState ASSERT if (InterlockedIncrement(&afxAssertReallyBusy) > 0) { // assume the debugger or auxiliary port wsprintf(szMessage, _T("Assertion Failed: File %hs, Line %d\n"), lpszFileName, nLine); OutputDebugString(szMessage); InterlockedDecrement(&afxAssertReallyBusy); // assert w/in assert (examine call stack to determine first one) AfxDebugBreak(); return FALSE; } // check for special hook function (for testing diagnostics) AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); AFX_ALLOC_STATE* pAllocState = AfxGetAllocState(); InterlockedDecrement(&afxAssertReallyBusy); if (pAllocState->m_lpfnAssertFailedLine != NULL) return pAllocState->m_lpfnAssertFailedLine(lpszFileName, nLine); // get app name or NULL if unknown (don't call assert) LPCTSTR lpszAppName = afxCurrentAppName; if (lpszAppName == NULL) lpszAppName = _T("<unknown application>"); // format message into buffer wsprintf(szMessage, _T("%s: File %hs, Line %d"), lpszAppName, lpszFileName, nLine); if (afxTraceEnabled) { // assume the debugger or auxiliary port // output into MacsBug looks better if it's done in one string, // since MacsBug always breaks the line after each output TCHAR szT[_MAX_PATH*2 + 20]; wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage); OutputDebugString(szT); } if (InterlockedIncrement(&afxAssertBusy) > 0) { InterlockedDecrement(&afxAssertBusy); // assert within assert (examine call stack to determine first one) AfxDebugBreak(); return FALSE; } // active popup window for the current thread HWND hWndParent = GetActiveWindow(); if (hWndParent != NULL) hWndParent = GetLastActivePopup(hWndParent); // display the assert int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"), MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND); // cleanup InterlockedDecrement(&afxAssertBusy); if (nCode == IDIGNORE) return FALSE; // ignore if (nCode == IDRETRY) return TRUE; // will cause AfxDebugBreak UNUSED nLine; // unused in release build UNUSED lpszFileName; AfxAbort(); // should not return (but otherwise AfxDebugBreak) return TRUE; }
/** @brief */ int __xLog( int type, LPCTSTR str, ...) { XCheckRecursive checkRecursive; if( checkRecursive.IsRecursive() ) return 1; TCHAR szBuff[1024]; // utf8이 길어서 넉넉하게 잡았다. va_list vl; va_start(vl, str); _vstprintf_s(szBuff, str, vl); va_end(vl); #ifdef _DEBUG #else // 릴리즈 모드에선 로그나 에러모두 파일에 써야 한다 { char szChar[8192]; memset( szChar, 0, sizeof(szChar) ); WideCharToMultiByte(CP_ACP, 0, szBuff, -1, szChar, 1024, NULL, NULL); int len = strlen(szChar); szChar[len] = '\n'; szChar[len+1] = 0; FILE *fp; #ifdef _XTOOL CString str = XE::GetCwd(); str += "error.txt"; fopen_s( &fp, Convert_TCHAR_To_char( str ), "a+" ); #else fopen_s( &fp, "error.txt", "a+" ); #endif //XBREAK( fp == NULL ); if( XASSERT(fp) ) { xPutsTimeString( fp ); fputs( szChar, fp ); int size = ftell( fp ); fclose(fp); } #ifdef _GAME // 게임에서만... // 로그파일이 무한정 쌓이지 않도록 한다. if( size >= 0xffff ) { fopen_s( &fp, "error.txt", "w+" ); if( fp ) { xPutsTimeString( fp ); fputs( szChar, fp ); fclose( fp ); #ifndef _MASTER // 마스터본이 아닐때만 XALERT( "로그파일 삭제" ); #endif } } #endif } #endif TCHAR szTitle[256] = {0,}; if( type == XLOGTYPE_ERROR ) { _tcscpy_s( szTitle, _T("Error!") ); // ::OutputDebugString( szBuff ); // TRACE로 한글출력이 안되서 이걸로 바꿈 #ifdef _XTOOL AfxDebugBreak(); AfxMessageBox( szBuff, MB_OK ); // 툴에선 XERROR를 불러도 exit()시키지 않는다. 데이터를 저장하지 않은상태이기때문에 어떻게 해서든 살리려고 시도해야한다 #else // ::MessageBox( NULL, szBuff, szTitle, MB_OK ); AfxMessageBox( szBuff, MB_OK ); AfxDebugBreak(); exit(1); #endif } else if( type == XLOGTYPE_LOG ) { // LOG _tcscpy_s( szTitle, _T("Message!") ); _tcscat_s( szBuff, _T("\n") ); // ::OutputDebugString( szBuff ); // TRACE로 한글출력이 안되서 이걸로 바꿈 } else if( type == XLOGTYPE_ALERT ) { AfxDebugBreak(); _tcscpy_s( szTitle, _T("Message!") ); // ::OutputDebugString( szBuff ); // TRACE로 한글출력이 안되서 이걸로 바꿈 #ifdef _XTOOL AfxMessageBox( szBuff, MB_OK ); #else // int retv = ::MessageBox( NULL, szBuff, szTitle, MB_OK ); AfxMessageBox( szBuff, MB_OK ); #endif } #ifdef _XCONSOLE CONSOLE( "%s", szBuff ); // 툴에서는 콘솔뷰로도 보낸다 #endif return 1; // XBREAK()같은데서 쓰이므로 항상 1을 리턴해야함 }