From 40cb30b6a576ecdcf446377b755ed70a87b9be28 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 20 Aug 2013 19:29:29 +0200 Subject: Small Linux fixes. --- source/OSSupport/IsThread.cpp | 1 + source/OSSupport/ListenThread.cpp | 2 +- source/OSSupport/Socket.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'source/OSSupport') diff --git a/source/OSSupport/IsThread.cpp b/source/OSSupport/IsThread.cpp index 45e329a68..1fadb3769 100644 --- a/source/OSSupport/IsThread.cpp +++ b/source/OSSupport/IsThread.cpp @@ -147,6 +147,7 @@ bool cIsThread::Wait(void) int res = pthread_join(m_Handle, NULL); m_Handle = NULL; LOGD("Thread %s finished", m_ThreadName.c_str()); + m_HasStarted = false; return (res == 0); #endif // else _WIN32 } diff --git a/source/OSSupport/ListenThread.cpp b/source/OSSupport/ListenThread.cpp index c586227df..0890aabc8 100644 --- a/source/OSSupport/ListenThread.cpp +++ b/source/OSSupport/ListenThread.cpp @@ -80,7 +80,7 @@ void cListenThread::Stop(void) super::Wait(); // Close all the listening sockets: - for (cSockets::iterator itr = m_Sockets.begin(), end = m_Sockets.end(); itr != end; ++itr) + for (cSockets::iterator itr = m_Sockets.begin() + 1, end = m_Sockets.end(); itr != end; ++itr) { itr->CloseSocket(); } // for itr - m_Sockets[] diff --git a/source/OSSupport/Socket.cpp b/source/OSSupport/Socket.cpp index f79bdbf47..48b5d704d 100644 --- a/source/OSSupport/Socket.cpp +++ b/source/OSSupport/Socket.cpp @@ -74,11 +74,11 @@ void cSocket::CloseSocket() if (shutdown(m_Socket, SHUT_RDWR) != 0)//SD_BOTH); { - LOGWARN("Error on shutting down socket (%s): %s", m_IPString.c_str(), GetLastErrorString().c_str()); + LOGWARN("Error on shutting down socket %d (%s): %s", m_Socket, m_IPString.c_str(), GetLastErrorString().c_str()); } if (close(m_Socket) != 0) { - LOGWARN("Error closing socket (%s): %s", m_IPString.c_str(), GetLastErrorString().c_str()); + LOGWARN("Error closing socket %d (%s): %s", m_Socket, m_IPString.c_str(), GetLastErrorString().c_str()); } #endif // else _WIN32 -- cgit v1.2.3 From ebc076e8b2abc6b33ebd6fb872c8edf6b6af7089 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 25 Aug 2013 21:57:12 +0200 Subject: Fixed ProtoProxy compilation, added client Kick handling. --- source/OSSupport/IsThread.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source/OSSupport') diff --git a/source/OSSupport/IsThread.cpp b/source/OSSupport/IsThread.cpp index 1fadb3769..d5fbfcf19 100644 --- a/source/OSSupport/IsThread.cpp +++ b/source/OSSupport/IsThread.cpp @@ -136,17 +136,28 @@ bool cIsThread::Wait(void) { return true; } - LOGD("Waiting for thread %s to finish", m_ThreadName.c_str()); + + #ifdef LOGD // ProtoProxy doesn't have LOGD + LOGD("Waiting for thread %s to finish", m_ThreadName.c_str()); + #endif // LOGD #ifdef _WIN32 int res = WaitForSingleObject(m_Handle, INFINITE); m_Handle = NULL; - LOGD("Thread %s finished", m_ThreadName.c_str()); + + #ifdef LOGD // ProtoProxy doesn't have LOGD + LOGD("Thread %s finished", m_ThreadName.c_str()); + #endif // LOGD + return (res == WAIT_OBJECT_0); #else // _WIN32 int res = pthread_join(m_Handle, NULL); m_Handle = NULL; - LOGD("Thread %s finished", m_ThreadName.c_str()); + + #ifdef LOGD // ProtoProxy doesn't have LOGD + LOGD("Thread %s finished", m_ThreadName.c_str()); + #endif // LOGD + m_HasStarted = false; return (res == 0); #endif // else _WIN32 -- cgit v1.2.3 From 86eb71868bc1c809d69a628c8e0fe51318453695 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 Aug 2013 10:06:41 +0200 Subject: Rewritten cTimer not to use heap allocation. --- source/OSSupport/Timer.cpp | 45 +++++++++++++++++++++------------------------ source/OSSupport/Timer.h | 31 ++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 31 deletions(-) (limited to 'source/OSSupport') diff --git a/source/OSSupport/Timer.cpp b/source/OSSupport/Timer.cpp index ab7325b5e..ed16f9e3a 100644 --- a/source/OSSupport/Timer.cpp +++ b/source/OSSupport/Timer.cpp @@ -8,33 +8,30 @@ -cTimer::cTimer() -#ifdef _WIN32 - : m_TicksPerSecond( new LARGE_INTEGER ) -#endif +cTimer::cTimer(void) { -#ifdef _WIN32 - QueryPerformanceFrequency( (LARGE_INTEGER*)m_TicksPerSecond ); -#endif + #ifdef _WIN32 + QueryPerformanceFrequency(&m_TicksPerSecond); + #endif } -cTimer::~cTimer() + + + + +long long cTimer::GetNowTime(void) { -#ifdef _WIN32 - delete (LARGE_INTEGER*)m_TicksPerSecond; -#endif + #ifdef _WIN32 + LARGE_INTEGER now; + QueryPerformanceCounter(&now); + return ((now.QuadPart * 1000) / m_TicksPerSecond.QuadPart); + #else + struct timeval now; + gettimeofday(&now, NULL); + return (long long)(now.tv_sec * 1000 + now.tv_usec / 1000); + #endif } -long long cTimer::GetNowTime() -{ -#ifdef _WIN32 - LARGE_INTEGER now; - QueryPerformanceCounter( &now ); - LARGE_INTEGER & tps = *((LARGE_INTEGER*)m_TicksPerSecond); - return ((now.QuadPart*1000) / tps.QuadPart ); -#else - struct timeval now; - gettimeofday(&now, NULL); - return (long long)(now.tv_sec*1000 + now.tv_usec/1000); -#endif -} \ No newline at end of file + + + diff --git a/source/OSSupport/Timer.h b/source/OSSupport/Timer.h index 5969d0fc9..a059daa41 100644 --- a/source/OSSupport/Timer.h +++ b/source/OSSupport/Timer.h @@ -1,15 +1,32 @@ + +// Timer.h + +// Declares the cTimer class representing an OS-independent of retrieving current time with msec accuracy + + + + + #pragma once + + + + class cTimer { public: - cTimer(); - ~cTimer(); + cTimer(void); - long long GetNowTime(); + // Returns the current time expressed in milliseconds + long long GetNowTime(void); private: -#ifdef _WIN32 - void* m_TicksPerSecond; // LARGE_INTEGER* -#endif -}; \ No newline at end of file + #ifdef _WIN32 + LARGE_INTEGER m_TicksPerSecond; + #endif +} ; + + + + -- cgit v1.2.3