From e874738d3de335faacb83d0398cabdff7477bfa0 Mon Sep 17 00:00:00 2001 From: sirius-m Date: Sat, 31 Oct 2009 09:11:43 +0000 Subject: [PATCH] Linux alternatives for the Windows headers and PerformanceCounter. Some typedefs and #defines for the Linux build. Fixed GetDataDir. --- headers.h | 27 ++++++++++++++++++--------- irc.h | 5 +++++ main.cpp | 2 +- net.h | 6 ++++++ util.h | 12 ++++++++++-- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/headers.h b/headers.h index 29b16fb78..16238f89b 100644 --- a/headers.h +++ b/headers.h @@ -25,20 +25,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include #include #include -#include #include #include #include #include -#include #include #include #define BOUNDSCHECK 1 @@ -56,7 +49,23 @@ #include #include #include -#include +#include + +#ifdef __WXMSW__ +#include +#include +#include +#include +#include +#include +#include +#else +#include +#include +#include +#include +#endif + #pragma hdrstop using namespace std; using namespace boost; diff --git a/irc.h b/irc.h index 91c3ffe68..1dc348a8b 100644 --- a/irc.h +++ b/irc.h @@ -1,6 +1,11 @@ // Copyright (c) 2009 Satoshi Nakamoto // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef __WXMSW__ +#define closesocket(s) close(s) +typedef u_int SOCKET; +#endif extern bool RecvLine(SOCKET hSocket, string& strLine); extern void ThreadIRCSeed(void* parg); diff --git a/main.cpp b/main.cpp index b98477b03..156267771 100644 --- a/main.cpp +++ b/main.cpp @@ -1399,7 +1399,7 @@ string GetAppDir() bool CheckDiskSpace(int64 nAdditionalBytes) { wxLongLong nFreeBytesAvailable = 0; - if (!wxGetDiskSpace(GetDataDir(), NULL, &nFreeBytesAvailable)) + if (!wxGetDiskSpace(wxStandardPaths::Get().GetDataDir(), NULL, &nFreeBytesAvailable)) { printf("ERROR: wxGetDiskSpace() failed\n"); return true; diff --git a/net.h b/net.h index 4011a3ef7..2eece2c06 100644 --- a/net.h +++ b/net.h @@ -1,6 +1,12 @@ // Copyright (c) 2009 Satoshi Nakamoto // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef __WXMSW__ +#define closesocket(s) close(s) +#define INVALID_SOCKET (SOCKET)(~0) +typedef u_int SOCKET; +#endif class CMessageHeader; class CAddress; diff --git a/util.h b/util.h index 1c7215d29..5d1877600 100644 --- a/util.h +++ b/util.h @@ -321,11 +321,19 @@ inline void PrintHex(vector vch, const char* pszFormat="%s", bool { printf(pszFormat, HexStr(vch, fSpaces).c_str()); } + inline int64 PerformanceCounter() { - int64 nCounter = 0; - QueryPerformanceCounter((LARGE_INTEGER*)&nCounter); + int64 nCounter = 0; +#ifdef __WXMSW__ + QueryPerformanceCounter((LARGE_INTEGER*)&nCounter); +#else + // this could be changed to reading /dev/urandom + timeval t; + gettimeofday(&t, NULL); + nCounter += t.tv_sec * 1000000 + t.tv_usec; +#endif return nCounter; }