summaryrefslogtreecommitdiffstats
path: root/src/OSSupport
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/OSSupport/CMakeLists.txt43
-rw-r--r--src/OSSupport/Errors.cpp12
-rw-r--r--src/OSSupport/Event.cpp4
-rw-r--r--src/OSSupport/Queue.h4
-rw-r--r--src/OSSupport/Semaphore.cpp26
-rw-r--r--src/OSSupport/Semaphore.h2
-rw-r--r--src/OSSupport/Sleep.cpp2
-rw-r--r--src/OSSupport/Sleep.h2
-rw-r--r--src/OSSupport/Socket.cpp11
-rw-r--r--src/OSSupport/Socket.h1
-rw-r--r--src/OSSupport/Thread.cpp38
-rw-r--r--src/OSSupport/Thread.h8
12 files changed, 86 insertions, 67 deletions
diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt
index dee60b450..a42fcbed4 100644
--- a/src/OSSupport/CMakeLists.txt
+++ b/src/OSSupport/CMakeLists.txt
@@ -3,13 +3,42 @@ cmake_minimum_required (VERSION 2.6)
project (MCServer)
include_directories ("${PROJECT_SOURCE_DIR}/../")
-file(GLOB SOURCE
- "*.cpp"
- "*.h"
-)
-add_library(OSSupport ${SOURCE})
+SET (SRCS
+ CriticalSection.cpp
+ Errors.cpp
+ Event.cpp
+ File.cpp
+ GZipFile.cpp
+ IsThread.cpp
+ ListenThread.cpp
+ Semaphore.cpp
+ Sleep.cpp
+ Socket.cpp
+ SocketThreads.cpp
+ Thread.cpp
+ Timer.cpp)
-if(UNIX)
- target_link_libraries(OSSupport pthread)
+SET (HDRS
+ CriticalSection.h
+ Errors.h
+ Event.h
+ File.h
+ GZipFile.h
+ IsThread.h
+ ListenThread.h
+ Queue.h
+ Semaphore.h
+ Sleep.h
+ Socket.h
+ SocketThreads.h
+ Thread.h
+ Timer.h)
+
+if(NOT MSVC)
+ add_library(OSSupport ${SRCS} ${HDRS})
+
+ if(UNIX)
+ target_link_libraries(OSSupport pthread)
+ endif()
endif()
diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp
index 6072b6ac6..9401ec257 100644
--- a/src/OSSupport/Errors.cpp
+++ b/src/OSSupport/Errors.cpp
@@ -3,7 +3,7 @@
#include "Errors.h"
-AString GetOSErrorString( int a_ErrNo )
+AString GetOSErrorString( int a_ErrNo)
{
char buffer[ 1024 ];
AString Out;
@@ -22,10 +22,10 @@ AString GetOSErrorString( int a_ErrNo )
// According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r():
- #if !defined(__APPLE__) && ( _GNU_SOURCE ) && !defined(ANDROID_NDK) // GNU version of strerror_r()
+ #if !defined(__APPLE__) && ( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r()
- char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) );
- if( res != NULL )
+ char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
+ if (res != NULL)
{
Printf(Out, "%d: %s", a_ErrNo, res);
return Out;
@@ -33,8 +33,8 @@ AString GetOSErrorString( int a_ErrNo )
#else // XSI version of strerror_r():
- int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer) );
- if( res == 0 )
+ int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
+ if (res == 0)
{
Printf(Out, "%d: %s", a_ErrNo, buffer);
return Out;
diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp
index 72bce4c3c..74f823216 100644
--- a/src/OSSupport/Event.cpp
+++ b/src/OSSupport/Event.cpp
@@ -32,7 +32,7 @@ cEvent::cEvent(void)
AString EventName;
Printf(EventName, "cEvent%p", this);
- m_Event = sem_open(EventName.c_str(), O_CREAT, 777, 0 );
+ m_Event = sem_open(EventName.c_str(), O_CREAT, 777, 0);
if (m_Event == SEM_FAILED)
{
AString error = GetOSErrorString(errno);
@@ -90,7 +90,7 @@ void cEvent::Wait(void)
}
#else
int res = sem_wait(m_Event);
- if (res != 0 )
+ if (res != 0)
{
AString error = GetOSErrorString(errno);
LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, error.c_str());
diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h
index 269f9db41..bf4d7f004 100644
--- a/src/OSSupport/Queue.h
+++ b/src/OSSupport/Queue.h
@@ -26,14 +26,14 @@ struct cQueueFuncs
public:
/// Called when an Item is deleted from the queue without being returned
- static void Delete(T) {};
+ static void Delete(T) {}
/// Called when an Item is inserted with EnqueueItemIfNotPresent and there is another equal value already inserted
static void Combine(T & a_existing, const T & a_new)
{
UNUSED(a_existing);
UNUSED(a_new);
- };
+ }
};
diff --git a/src/OSSupport/Semaphore.cpp b/src/OSSupport/Semaphore.cpp
index d919c4744..c1fc7d9c7 100644
--- a/src/OSSupport/Semaphore.cpp
+++ b/src/OSSupport/Semaphore.cpp
@@ -5,9 +5,9 @@
-cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* = 0 */ )
+cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* = 0 */)
#ifndef _WIN32
- : m_bNamed( false )
+ : m_bNamed( false)
#endif
{
#ifndef _WIN32
@@ -20,15 +20,15 @@ cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /*
m_bNamed = true;
AString Name;
- Printf(Name, "cSemaphore%p", this );
+ Printf(Name, "cSemaphore%p", this);
m_Handle = sem_open(Name.c_str(), O_CREAT, 777, a_InitialCount);
- if( m_Handle == SEM_FAILED )
+ if (m_Handle == SEM_FAILED)
{
- LOG("ERROR: Could not create Semaphore. (%i)", errno );
+ LOG("ERROR: Could not create Semaphore. (%i)", errno);
}
else
{
- if( sem_unlink(Name.c_str()) != 0 )
+ if (sem_unlink(Name.c_str()) != 0)
{
LOG("ERROR: Could not unlink cSemaphore. (%i)", errno);
}
@@ -51,18 +51,18 @@ cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /*
cSemaphore::~cSemaphore()
{
#ifdef _WIN32
- CloseHandle( m_Handle );
+ CloseHandle( m_Handle);
#else
- if( m_bNamed )
+ if (m_bNamed)
{
- if( sem_close( (sem_t*)m_Handle ) != 0 )
+ if (sem_close( (sem_t*)m_Handle) != 0)
{
LOG("ERROR: Could not close cSemaphore. (%i)", errno);
}
}
else
{
- sem_destroy( (sem_t*)m_Handle );
+ sem_destroy( (sem_t*)m_Handle);
delete (sem_t*)m_Handle;
}
m_Handle = 0;
@@ -77,7 +77,7 @@ cSemaphore::~cSemaphore()
void cSemaphore::Wait()
{
#ifndef _WIN32
- if( sem_wait( (sem_t*)m_Handle ) != 0)
+ if (sem_wait( (sem_t*)m_Handle) != 0)
{
LOG("ERROR: Could not wait for cSemaphore. (%i)", errno);
}
@@ -93,12 +93,12 @@ void cSemaphore::Wait()
void cSemaphore::Signal()
{
#ifndef _WIN32
- if( sem_post( (sem_t*)m_Handle ) != 0 )
+ if (sem_post( (sem_t*)m_Handle) != 0)
{
LOG("ERROR: Could not signal cSemaphore. (%i)", errno);
}
#else
- ReleaseSemaphore( m_Handle, 1, NULL );
+ ReleaseSemaphore( m_Handle, 1, NULL);
#endif
}
diff --git a/src/OSSupport/Semaphore.h b/src/OSSupport/Semaphore.h
index ac574e8a1..adc531ed8 100644
--- a/src/OSSupport/Semaphore.h
+++ b/src/OSSupport/Semaphore.h
@@ -3,7 +3,7 @@
class cSemaphore
{
public:
- cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount = 0 );
+ cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount = 0);
~cSemaphore();
void Wait();
diff --git a/src/OSSupport/Sleep.cpp b/src/OSSupport/Sleep.cpp
index 223a8b855..297d668d7 100644
--- a/src/OSSupport/Sleep.cpp
+++ b/src/OSSupport/Sleep.cpp
@@ -9,7 +9,7 @@
-void cSleep::MilliSleep( unsigned int a_MilliSeconds )
+void cSleep::MilliSleep( unsigned int a_MilliSeconds)
{
#ifdef _WIN32
Sleep(a_MilliSeconds); // Don't tick too much
diff --git a/src/OSSupport/Sleep.h b/src/OSSupport/Sleep.h
index 0ec0adf9d..57d29682c 100644
--- a/src/OSSupport/Sleep.h
+++ b/src/OSSupport/Sleep.h
@@ -3,5 +3,5 @@
class cSleep
{
public:
- static void MilliSleep( unsigned int a_MilliSeconds );
+ static void MilliSleep( unsigned int a_MilliSeconds);
};
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
index 7d4d9e598..c07d31c8b 100644
--- a/src/OSSupport/Socket.cpp
+++ b/src/OSSupport/Socket.cpp
@@ -25,15 +25,6 @@ cSocket::cSocket(xSocket a_Socket)
-cSocket::~cSocket()
-{
- // Do NOT close the socket; this class is an API wrapper, not a RAII!
-}
-
-
-
-
-
cSocket::operator cSocket::xSocket() const
{
return m_Socket;
@@ -138,7 +129,7 @@ int cSocket::WSAStartup(void)
#ifdef _WIN32
WSADATA wsaData;
memset(&wsaData, 0, sizeof(wsaData));
- return ::WSAStartup(MAKEWORD(2, 2),&wsaData);
+ return ::WSAStartup(MAKEWORD(2, 2), &wsaData);
#else
return 0;
#endif
diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h
index 35ecadfa0..e4ec895cb 100644
--- a/src/OSSupport/Socket.h
+++ b/src/OSSupport/Socket.h
@@ -41,7 +41,6 @@ public:
cSocket(void) : m_Socket(INVALID_SOCKET) {}
cSocket(xSocket a_Socket);
- ~cSocket();
bool IsValid(void) const { return IsValidSocket(m_Socket); }
void CloseSocket(void);
diff --git a/src/OSSupport/Thread.cpp b/src/OSSupport/Thread.cpp
index 084e0810e..faaccce96 100644
--- a/src/OSSupport/Thread.cpp
+++ b/src/OSSupport/Thread.cpp
@@ -47,13 +47,13 @@ static void SetThreadName(DWORD dwThreadID, const char * threadName)
-cThread::cThread( ThreadFunc a_ThreadFunction, void* a_Param, const char* a_ThreadName /* = 0 */ )
- : m_ThreadFunction( a_ThreadFunction )
- , m_Param( a_Param )
- , m_Event( new cEvent() )
- , m_StopEvent( 0 )
+cThread::cThread( ThreadFunc a_ThreadFunction, void* a_Param, const char* a_ThreadName /* = 0 */)
+ : m_ThreadFunction( a_ThreadFunction)
+ , m_Param( a_Param)
+ , m_Event( new cEvent())
+ , m_StopEvent( 0)
{
- if( a_ThreadName )
+ if (a_ThreadName)
{
m_ThreadName.assign(a_ThreadName);
}
@@ -68,7 +68,7 @@ cThread::~cThread()
delete m_Event;
m_Event = NULL;
- if( m_StopEvent )
+ if (m_StopEvent)
{
m_StopEvent->Wait();
delete m_StopEvent;
@@ -80,24 +80,24 @@ cThread::~cThread()
-void cThread::Start( bool a_bWaitOnDelete /* = true */ )
+void cThread::Start( bool a_bWaitOnDelete /* = true */)
{
- if( a_bWaitOnDelete )
+ if (a_bWaitOnDelete)
m_StopEvent = new cEvent();
#ifndef _WIN32
pthread_t SndThread;
- if( pthread_create( &SndThread, NULL, MyThread, this) )
+ if (pthread_create( &SndThread, NULL, MyThread, this))
LOGERROR("ERROR: Could not create thread!");
#else
DWORD ThreadID = 0;
HANDLE hThread = CreateThread(NULL // security
- ,0 // stack size
+ , 0 // stack size
, (LPTHREAD_START_ROUTINE) MyThread // function name
- ,this // parameters
- ,0 // flags
- ,&ThreadID ); // thread id
- CloseHandle( hThread );
+ , this // parameters
+ , 0 // flags
+ , &ThreadID); // thread id
+ CloseHandle( hThread);
#ifdef _MSC_VER
if (!m_ThreadName.empty())
@@ -116,9 +116,9 @@ void cThread::Start( bool a_bWaitOnDelete /* = true */ )
#ifdef _WIN32
-unsigned long cThread::MyThread(void* a_Param )
+unsigned long cThread::MyThread(void* a_Param)
#else
-void *cThread::MyThread( void *a_Param )
+void *cThread::MyThread( void *a_Param)
#endif
{
cThread* self = (cThread*)a_Param;
@@ -130,8 +130,8 @@ void *cThread::MyThread( void *a_Param )
// Set event to let other thread know this thread has been created and it's safe to delete the cThread object
self->m_Event->Set();
- ThreadFunction( ThreadParam );
+ ThreadFunction( ThreadParam);
- if( StopEvent ) StopEvent->Set();
+ if (StopEvent) StopEvent->Set();
return 0;
}
diff --git a/src/OSSupport/Thread.h b/src/OSSupport/Thread.h
index 4153b2427..7ee352c82 100644
--- a/src/OSSupport/Thread.h
+++ b/src/OSSupport/Thread.h
@@ -4,18 +4,18 @@ class cThread
{
public:
typedef void (ThreadFunc)(void*);
- cThread( ThreadFunc a_ThreadFunction, void* a_Param, const char* a_ThreadName = 0 );
+ cThread( ThreadFunc a_ThreadFunction, void* a_Param, const char* a_ThreadName = 0);
~cThread();
- void Start( bool a_bWaitOnDelete = true );
+ void Start( bool a_bWaitOnDelete = true);
void WaitForThread();
private:
ThreadFunc* m_ThreadFunction;
#ifdef _WIN32
- static unsigned long MyThread(void* a_Param );
+ static unsigned long MyThread(void* a_Param);
#else
- static void *MyThread( void *lpParam );
+ static void *MyThread( void *lpParam);
#endif
void* m_Param;