From 2423fbf2efa39e28cc348acc11b9269e573dcdef Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 22:15:34 +0200 Subject: Normalized comments. This was mostly done automatically and then visually inspected for obvious errors. All //-style comments should have a 2-space separation from the code, and 1 space after the comment sign. --- src/OSSupport/CriticalSection.cpp | 6 +++--- src/OSSupport/File.cpp | 4 ++-- src/OSSupport/Semaphore.cpp | 8 ++++---- src/OSSupport/Semaphore.h | 2 +- src/OSSupport/Sleep.cpp | 2 +- src/OSSupport/SocketThreads.cpp | 2 +- src/OSSupport/Thread.cpp | 12 ++++++------ 7 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CriticalSection.cpp b/src/OSSupport/CriticalSection.cpp index bda97e3a1..6d4afce55 100644 --- a/src/OSSupport/CriticalSection.cpp +++ b/src/OSSupport/CriticalSection.cpp @@ -6,7 +6,7 @@ -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cCriticalSection: cCriticalSection::cCriticalSection() @@ -105,7 +105,7 @@ bool cCriticalSection::IsLockedByCurrentThread(void) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cCSLock cCSLock::cCSLock(cCriticalSection * a_CS) @@ -165,7 +165,7 @@ void cCSLock::Unlock(void) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cCSUnlock: cCSUnlock::cCSUnlock(cCSLock & a_Lock) : diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index addf8f928..ff6fb5898 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -81,7 +81,7 @@ bool cFile::Open(const AString & iFileName, eMode iMode) m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), Mode, _SH_DENYWR); #else m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), Mode); -#endif // _WIN32 +#endif // _WIN32 if ((m_File == NULL) && (iMode == fmReadWrite)) { @@ -94,7 +94,7 @@ bool cFile::Open(const AString & iFileName, eMode iMode) m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+", _SH_DENYWR); #else m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+"); -#endif // _WIN32 +#endif // _WIN32 } return (m_File != NULL); diff --git a/src/OSSupport/Semaphore.cpp b/src/OSSupport/Semaphore.cpp index 468de6858..60e5564e4 100644 --- a/src/OSSupport/Semaphore.cpp +++ b/src/OSSupport/Semaphore.cpp @@ -36,10 +36,10 @@ cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* } #else m_Handle = CreateSemaphore( - NULL, // security attribute - a_InitialCount, // initial count - a_MaxCount, // maximum count - 0 // name (optional) + NULL, // security attribute + a_InitialCount, // initial count + a_MaxCount, // maximum count + 0 // name (optional) ); #endif } diff --git a/src/OSSupport/Semaphore.h b/src/OSSupport/Semaphore.h index fbe8907f1..ac574e8a1 100644 --- a/src/OSSupport/Semaphore.h +++ b/src/OSSupport/Semaphore.h @@ -9,7 +9,7 @@ public: void Wait(); void Signal(); private: - void* m_Handle; // HANDLE pointer + void* m_Handle; // HANDLE pointer #ifndef _WIN32 bool m_bNamed; diff --git a/src/OSSupport/Sleep.cpp b/src/OSSupport/Sleep.cpp index 70fb06b40..b18d918fa 100644 --- a/src/OSSupport/Sleep.cpp +++ b/src/OSSupport/Sleep.cpp @@ -12,7 +12,7 @@ void cSleep::MilliSleep( unsigned int a_MilliSeconds ) { #ifdef _WIN32 - Sleep(a_MilliSeconds); // Don't tick too much + Sleep(a_MilliSeconds); // Don't tick too much #else usleep(a_MilliSeconds*1000); #endif diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index ca8b8438d..f436318a5 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -13,7 +13,7 @@ -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cSocketThreads: cSocketThreads::cSocketThreads(void) diff --git a/src/OSSupport/Thread.cpp b/src/OSSupport/Thread.cpp index 535784613..674e37757 100644 --- a/src/OSSupport/Thread.cpp +++ b/src/OSSupport/Thread.cpp @@ -91,12 +91,12 @@ void cThread::Start( bool a_bWaitOnDelete /* = true */ ) LOGERROR("ERROR: Could not create thread!"); #else DWORD ThreadID = 0; - HANDLE hThread = CreateThread( 0 // security - ,0 // stack size - , (LPTHREAD_START_ROUTINE) MyThread // function name - ,this // parameters - ,0 // flags - ,&ThreadID ); // thread id + HANDLE hThread = CreateThread( 0 // security + ,0 // stack size + , (LPTHREAD_START_ROUTINE) MyThread // function name + ,this // parameters + ,0 // flags + ,&ThreadID ); // thread id CloseHandle( hThread ); #ifdef _MSC_VER -- cgit v1.2.3 From 5e198c673009cf8ca9d92cf59848999bc96bbc37 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 22:50:58 +0200 Subject: Basic style fixes. --- src/OSSupport/CriticalSection.cpp | 4 ++-- src/OSSupport/CriticalSection.h | 2 +- src/OSSupport/Queue.h | 4 ++-- src/OSSupport/Socket.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CriticalSection.cpp b/src/OSSupport/CriticalSection.cpp index 6d4afce55..5dfc8b5f9 100644 --- a/src/OSSupport/CriticalSection.cpp +++ b/src/OSSupport/CriticalSection.cpp @@ -108,7 +108,7 @@ bool cCriticalSection::IsLockedByCurrentThread(void) //////////////////////////////////////////////////////////////////////////////// // cCSLock -cCSLock::cCSLock(cCriticalSection * a_CS) +cCSLock::cCSLock(cCriticalSection * a_CS) : m_CS(a_CS) , m_IsLocked(false) { @@ -119,7 +119,7 @@ cCSLock::cCSLock(cCriticalSection * a_CS) -cCSLock::cCSLock(cCriticalSection & a_CS) +cCSLock::cCSLock(cCriticalSection & a_CS) : m_CS(&a_CS) , m_IsLocked(false) { diff --git a/src/OSSupport/CriticalSection.h b/src/OSSupport/CriticalSection.h index 73a71f5e1..c3c6e57f0 100644 --- a/src/OSSupport/CriticalSection.h +++ b/src/OSSupport/CriticalSection.h @@ -47,7 +47,7 @@ class cCSLock cCriticalSection * m_CS; // Unlike a cCriticalSection, this object should be used from a single thread, therefore access to m_IsLocked is not threadsafe - // In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held, + // In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held, // therefore we need to check this value whether we are locked or not. bool m_IsLocked; diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index beb6a63f1..269f9db41 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -21,7 +21,7 @@ cQueueFuncs and is used as the default behavior. /// This empty struct allows for the callback functions to be inlined template -struct cQueueFuncs +struct cQueueFuncs { public: @@ -88,7 +88,7 @@ public: cCSLock Lock(m_CS); if (m_Contents.size() == 0) { - return false; + return false; } item = m_Contents.front(); m_Contents.pop_front(); diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 56835b518..7d4d9e598 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -244,7 +244,7 @@ cSocket cSocket::AcceptIPv6(void) // Windows XP doesn't have inet_ntop, so we need to improvise. And MSVC has different headers than GCC #ifdef _MSC_VER // MSVC version - Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", + Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", from.sin6_addr.u.Word[0], from.sin6_addr.u.Word[1], from.sin6_addr.u.Word[2], @@ -256,7 +256,7 @@ cSocket cSocket::AcceptIPv6(void) ); #else // _MSC_VER // MinGW - Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", + Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x", from.sin6_addr.s6_addr16[0], from.sin6_addr.s6_addr16[1], from.sin6_addr.s6_addr16[2], -- cgit v1.2.3 From c03161f75d22a7965aea20fb9843ae580a07079a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 23:15:53 +0200 Subject: Fixed tabs used for alignment. --- src/OSSupport/Semaphore.cpp | 50 ++++++++++++++++++++++++++++++--------------- src/OSSupport/Sleep.cpp | 2 +- src/OSSupport/Thread.cpp | 2 +- 3 files changed, 35 insertions(+), 19 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/Semaphore.cpp b/src/OSSupport/Semaphore.cpp index 60e5564e4..d919c4744 100644 --- a/src/OSSupport/Semaphore.cpp +++ b/src/OSSupport/Semaphore.cpp @@ -44,48 +44,64 @@ cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* #endif } + + + + cSemaphore::~cSemaphore() { #ifdef _WIN32 CloseHandle( m_Handle ); #else - if( m_bNamed ) - { - if( sem_close( (sem_t*)m_Handle ) != 0 ) - { - LOG("ERROR: Could not close cSemaphore. (%i)", errno); - } - } - else - { - sem_destroy( (sem_t*)m_Handle ); - delete (sem_t*)m_Handle; - } + if( m_bNamed ) + { + if( sem_close( (sem_t*)m_Handle ) != 0 ) + { + LOG("ERROR: Could not close cSemaphore. (%i)", errno); + } + } + else + { + sem_destroy( (sem_t*)m_Handle ); + delete (sem_t*)m_Handle; + } m_Handle = 0; #endif } + + + + void cSemaphore::Wait() { #ifndef _WIN32 - if( sem_wait( (sem_t*)m_Handle ) != 0) - { - LOG("ERROR: Could not wait for cSemaphore. (%i)", errno); - } + if( sem_wait( (sem_t*)m_Handle ) != 0) + { + LOG("ERROR: Could not wait for cSemaphore. (%i)", errno); + } #else WaitForSingleObject( m_Handle, INFINITE); #endif } + + + + void cSemaphore::Signal() { #ifndef _WIN32 if( sem_post( (sem_t*)m_Handle ) != 0 ) { - LOG("ERROR: Could not signal cSemaphore. (%i)", errno); + LOG("ERROR: Could not signal cSemaphore. (%i)", errno); } #else ReleaseSemaphore( m_Handle, 1, NULL ); #endif } + + + + diff --git a/src/OSSupport/Sleep.cpp b/src/OSSupport/Sleep.cpp index b18d918fa..223a8b855 100644 --- a/src/OSSupport/Sleep.cpp +++ b/src/OSSupport/Sleep.cpp @@ -14,6 +14,6 @@ void cSleep::MilliSleep( unsigned int a_MilliSeconds ) #ifdef _WIN32 Sleep(a_MilliSeconds); // Don't tick too much #else - usleep(a_MilliSeconds*1000); + usleep(a_MilliSeconds*1000); #endif } diff --git a/src/OSSupport/Thread.cpp b/src/OSSupport/Thread.cpp index 674e37757..084e0810e 100644 --- a/src/OSSupport/Thread.cpp +++ b/src/OSSupport/Thread.cpp @@ -91,7 +91,7 @@ void cThread::Start( bool a_bWaitOnDelete /* = true */ ) LOGERROR("ERROR: Could not create thread!"); #else DWORD ThreadID = 0; - HANDLE hThread = CreateThread( 0 // security + HANDLE hThread = CreateThread(NULL // security ,0 // stack size , (LPTHREAD_START_ROUTINE) MyThread // function name ,this // parameters -- cgit v1.2.3 From dcaa3262a2b085fa3ea9769c7eee21d3cd48c834 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 18 Jul 2014 00:48:22 -0700 Subject: OSSupport/CMakeLists.txt: Replaced glob with list of files --- src/OSSupport/CMakeLists.txt | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index dee60b450..8004d4094 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -3,12 +3,39 @@ 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) + +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) + +add_library(OSSupport ${SRCS} ${HDRS}) if(UNIX) target_link_libraries(OSSupport pthread) -- cgit v1.2.3 From 725d1fd1e2995b1720673c280fea1125ac338b3c Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 18 Jul 2014 13:26:43 -0700 Subject: Subdirs: Only add_library if not using MSVC --- src/OSSupport/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 8004d4094..a42fcbed4 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -35,8 +35,10 @@ SET (HDRS Thread.h Timer.h) -add_library(OSSupport ${SRCS} ${HDRS}) +if(NOT MSVC) + add_library(OSSupport ${SRCS} ${HDRS}) -if(UNIX) - target_link_libraries(OSSupport pthread) + if(UNIX) + target_link_libraries(OSSupport pthread) + endif() endif() -- cgit v1.2.3 From 00c524519ef6c7ceaf4ac91307617cfd65d7cf21 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 19 Jul 2014 14:53:41 +0200 Subject: Fixed style: spaces after commas. --- src/OSSupport/Socket.cpp | 2 +- src/OSSupport/Thread.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 7d4d9e598..47d9f331d 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -138,7 +138,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/Thread.cpp b/src/OSSupport/Thread.cpp index 084e0810e..163c9b0c9 100644 --- a/src/OSSupport/Thread.cpp +++ b/src/OSSupport/Thread.cpp @@ -92,11 +92,11 @@ void cThread::Start( bool a_bWaitOnDelete /* = true */ ) #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 + , this // parameters + , 0 // flags + , &ThreadID ); // thread id CloseHandle( hThread ); #ifdef _MSC_VER -- cgit v1.2.3 From 1831c2e652a3cbcfb13a72cd1334d0959cb607a3 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 19 Jul 2014 14:50:31 -0700 Subject: Socket: removed unused Socket destructor --- src/OSSupport/Socket.cpp | 9 --------- src/OSSupport/Socket.h | 1 - 2 files changed, 10 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 47d9f331d..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; 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); -- cgit v1.2.3