summaryrefslogtreecommitdiffstats
path: root/source/OSSupport
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2013-09-02 15:15:28 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2013-09-02 15:15:28 +0200
commit20b64e18e49550e7a105899045fd51be192e86bc (patch)
treec261c71ea2feb99bc5d4b058da5811c6b80db70c /source/OSSupport
parentMinecart enhancements [SEE DESC] (diff)
parentExported BroadcastSoundEffect and BroadcastSoundParticleEffect to the Lua API (diff)
downloadcuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar
cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.gz
cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.bz2
cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.lz
cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.xz
cuberite-20b64e18e49550e7a105899045fd51be192e86bc.tar.zst
cuberite-20b64e18e49550e7a105899045fd51be192e86bc.zip
Diffstat (limited to 'source/OSSupport')
-rw-r--r--source/OSSupport/IsThread.cpp18
-rw-r--r--source/OSSupport/ListenThread.cpp2
-rw-r--r--source/OSSupport/Socket.cpp4
-rw-r--r--source/OSSupport/Timer.cpp45
-rw-r--r--source/OSSupport/Timer.h31
5 files changed, 63 insertions, 37 deletions
diff --git a/source/OSSupport/IsThread.cpp b/source/OSSupport/IsThread.cpp
index 45e329a68..d5fbfcf19 100644
--- a/source/OSSupport/IsThread.cpp
+++ b/source/OSSupport/IsThread.cpp
@@ -136,17 +136,29 @@ 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
}
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
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
+} ;
+
+
+
+