From cb0f89646f065800d38d7cfc10ba1e855563296a Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Thu, 28 Jan 2010 00:31:00 +0000 Subject: simplify AddAddress, readcompactsize limit, fixed a 64-bit compile error in serialize.h, change status "# blocks" to "# confirmations" and widen the column. git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@53 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- util.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'util.cpp') diff --git a/util.cpp b/util.cpp index f5f2797fe..429224676 100644 --- a/util.cpp +++ b/util.cpp @@ -8,8 +8,8 @@ map mapArgs; map > mapMultiArgs; bool fDebug = false; -bool fPrintToDebugger = false; bool fPrintToConsole = false; +bool fPrintToDebugger = false; char pszSetDataDir[MAX_PATH] = ""; bool fShutdown = false; @@ -75,6 +75,8 @@ void RandAddSeed() void RandAddSeedPerfmon() { + RandAddSeed(); + // This can take up to 2 seconds, so only do it every 10 minutes static int64 nLastPerfmon; if (GetTime() < nLastPerfmon + 10 * 60) @@ -129,6 +131,79 @@ uint64 GetRand(uint64 nMax) +inline int OutputDebugStringF(const char* pszFormat, ...) +{ + int ret = 0; + if (fPrintToConsole || wxTheApp == NULL) + { + // print to console + va_list arg_ptr; + va_start(arg_ptr, pszFormat); + ret = vprintf(pszFormat, arg_ptr); + va_end(arg_ptr); + } + else + { + // print to debug.log + char pszFile[MAX_PATH+100]; + GetDataDir(pszFile); + strlcat(pszFile, "/debug.log", sizeof(pszFile)); + FILE* fileout = fopen(pszFile, "a"); + if (fileout) + { + //// Debug print useful for profiling + //fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue()); + va_list arg_ptr; + va_start(arg_ptr, pszFormat); + ret = vfprintf(fileout, pszFormat, arg_ptr); + va_end(arg_ptr); + fclose(fileout); + } + } + +#ifdef __WXMSW__ + if (fPrintToDebugger) + { + // accumulate a line at a time + static CCriticalSection cs_OutputDebugStringF; + CRITICAL_BLOCK(cs_OutputDebugStringF) + { + static char pszBuffer[50000]; + static char* pend; + if (pend == NULL) + pend = pszBuffer; + va_list arg_ptr; + va_start(arg_ptr, pszFormat); + int limit = END(pszBuffer) - pend - 2; + int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr); + va_end(arg_ptr); + if (ret < 0 || ret >= limit) + { + pend = END(pszBuffer) - 2; + *pend++ = '\n'; + } + else + pend += ret; + *pend = '\0'; + char* p1 = pszBuffer; + char* p2; + while (p2 = strchr(p1, '\n')) + { + p2++; + char c = *p2; + *p2 = '\0'; + OutputDebugString(p1); + *p2 = c; + p1 = p2; + } + if (p1 != pszBuffer) + memmove(pszBuffer, p1, pend - p1 + 1); + pend -= (p1 - pszBuffer); + } + } +#endif + return ret; +} // Safer snprintf -- cgit v1.2.3