From 4ea3f3da1a0c00ea74e85c31a22ea94d18bbdf06 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Fri, 11 Dec 2009 16:49:21 +0000 Subject: retry IRC if name in use, resize to fit ubuntu's giant default font, scroll debug.log, pause gen during initial block download git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@44 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- util.cpp | 55 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'util.cpp') diff --git a/util.cpp b/util.cpp index 305db5cee..f5f2797fe 100644 --- a/util.cpp +++ b/util.cpp @@ -11,6 +11,7 @@ bool fDebug = false; bool fPrintToDebugger = false; bool fPrintToConsole = false; char pszSetDataDir[MAX_PATH] = ""; +bool fShutdown = false; @@ -53,19 +54,6 @@ public: for (int i = 0; i < CRYPTO_num_locks(); i++) delete ppmutexOpenSSL[i]; OPENSSL_free(ppmutexOpenSSL); - - // Close sockets - foreach(CNode* pnode, vNodes) - if (pnode->hSocket != INVALID_SOCKET) - closesocket(pnode->hSocket); - if (hListenSocket != INVALID_SOCKET) - if (closesocket(hListenSocket) == SOCKET_ERROR) - printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError()); - -#ifdef __WXMSW__ - // Shutdown Windows Sockets - WSACleanup(); -#endif } } instance_of_cinit; @@ -416,16 +404,6 @@ void PrintException(std::exception* pex, const char* pszThread) -int GetFilesize(FILE* file) -{ - int nSavePos = ftell(file); - int nFilesize = -1; - if (fseek(file, 0, SEEK_END) == 0) - nFilesize = ftell(file); - fseek(file, nSavePos, SEEK_SET); - return nFilesize; -} - void GetDataDir(char* pszDir) { // pszDir must be at least MAX_PATH length. @@ -465,6 +443,37 @@ string GetDataDir() return pszDir; } +int GetFilesize(FILE* file) +{ + int nSavePos = ftell(file); + int nFilesize = -1; + if (fseek(file, 0, SEEK_END) == 0) + nFilesize = ftell(file); + fseek(file, nSavePos, SEEK_SET); + return nFilesize; +} + +void ShrinkDebugFile() +{ + // Scroll debug.log if it's getting too big + string strFile = GetDataDir() + "/debug.log"; + FILE* file = fopen(strFile.c_str(), "r"); + if (file && GetFilesize(file) > 10 * 1000000) + { + // Restart the file with some of the end + char pch[200000]; + fseek(file, -sizeof(pch), SEEK_END); + int nBytes = fread(pch, 1, sizeof(pch), file); + fclose(file); + if (file = fopen(strFile.c_str(), "w")) + { + fwrite(pch, 1, nBytes, file); + fclose(file); + } + } +} + + -- cgit v1.2.3