1
0
Fork 0

Switched cEvent to GetOSErrorString

This commit is contained in:
Tycho 2014-01-25 06:02:20 -08:00
parent 59b8205f02
commit 977e277094
3 changed files with 14 additions and 18 deletions

View File

@ -50,3 +50,4 @@ AString GetOSErrorString( int a_ErrNo )
#endif // else _WIN32 #endif // else _WIN32
} }

View File

@ -1,3 +1,5 @@
#pragma once
AString GetOSErrorString(int a_ErrNo); AString GetOSErrorString(int a_ErrNo);

View File

@ -7,9 +7,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Event.h" #include "Event.h"
#if not defined(_WIN32) #include "Errors.h"
#include <string.h>
#endif
@ -37,18 +35,16 @@ cEvent::cEvent(void)
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) if (m_Event == SEM_FAILED)
{ {
char buffer[1024]; AString error = GetOSErrorString(errno);
strerror_r(errno,buffer,1024); LOGERROR("cEvent: Cannot create event, err = %s. Aborting server.", error.c_str());
LOGERROR("cEvent: Cannot create event, err = %s. Aborting server.", buffer);
abort(); abort();
} }
// Unlink the semaphore immediately - it will continue to function but will not pollute the namespace // Unlink the semaphore immediately - it will continue to function but will not pollute the namespace
// We don't store the name, so can't call this in the destructor // We don't store the name, so can't call this in the destructor
if (sem_unlink(EventName.c_str()) != 0) if (sem_unlink(EventName.c_str()) != 0)
{ {
char buffer[1024]; AString error = GetOSErrorString(errno);
strerror_r(errno,buffer,1024); LOGWARN("ERROR: Could not unlink cEvent. (%s)", error.c_str());
LOGWARN("ERROR: Could not unlink cEvent. (%s)", buffer);
} }
} }
#endif // *nix #endif // *nix
@ -67,9 +63,8 @@ cEvent::~cEvent()
{ {
if (sem_close(m_Event) != 0) if (sem_close(m_Event) != 0)
{ {
char buffer[1024]; AString error = GetOSErrorString(errno);
strerror_r(errno,buffer,1024); LOGERROR("ERROR: Could not close cEvent. (%s)", error.c_str());
LOGERROR("ERROR: Could not close cEvent. (%s)", buffer);
} }
} }
else else
@ -96,9 +91,8 @@ void cEvent::Wait(void)
int res = sem_wait(m_Event); int res = sem_wait(m_Event);
if (res != 0 ) if (res != 0 )
{ {
char buffer[1024]; AString error = GetOSErrorString(errno);
strerror_r(errno,buffer,1024); LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, error.c_str());
LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, buffer);
} }
#endif #endif
} }
@ -118,9 +112,8 @@ void cEvent::Set(void)
int res = sem_post(m_Event); int res = sem_post(m_Event);
if (res != 0) if (res != 0)
{ {
char buffer[1024]; AString error = GetOSErrorString(errno);
strerror_r(errno,buffer,1024); LOGWARN("cEvent: Could not set cEvent: %i, err = %s", res, error.c_str());
LOGWARN("cEvent: Could not set cEvent: %i, err = %s", res, buffer);
} }
#endif #endif
} }