- attempt to improve issues in the custom menu related to freezing

- modified debug UI display to support multi levels of UI debug info
- added more validations to mutexes
- improved client sockets to properly be setup as non blocking
This commit is contained in:
Mark Vejvoda
2011-02-06 07:01:54 +00:00
parent 0380bcdb5d
commit c58e893047
11 changed files with 96 additions and 19 deletions

View File

@@ -1072,6 +1072,7 @@ int Socket::send(const void *data, int dataSize) {
#else
bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT);
#endif
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
@@ -1113,6 +1114,8 @@ int Socket::send(const void *data, int dataSize) {
#else
bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, MSG_NOSIGNAL | MSG_DONTWAIT);
#endif
safeMutex.ReleaseLock();
if(bytesSent > 0) {
totalBytesSent += bytesSent;
}
@@ -1186,6 +1189,7 @@ int Socket::receive(void *data, int dataSize) {
else if(Socket::isReadable() == true) {
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived);
}
@@ -1207,7 +1211,7 @@ int Socket::peek(void *data, int dataSize) {
ssize_t err = 0;
if(isSocketValid() == true) {
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize));
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
}
if(err < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
@@ -1217,7 +1221,7 @@ int Socket::peek(void *data, int dataSize) {
disconnectSocket();
}
else if(err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 ERROR EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__,__LINE__);
time_t tStartTimer = time(NULL);
while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
@@ -1232,6 +1236,7 @@ int Socket::peek(void *data, int dataSize) {
else if(Socket::isReadable() == true) {
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,err);
}

View File

@@ -77,8 +77,9 @@ void Thread::resume() {
// Mutex
// =====================================
Mutex::Mutex() {
Mutex::Mutex(string ownerId) {
refCount=0;
this->ownerId = ownerId;
mutex = SDL_CreateMutex();
assert(mutex != NULL);
if(mutex == NULL) {
@@ -91,9 +92,15 @@ Mutex::Mutex() {
Mutex::~Mutex() {
if(mutex == NULL) {
char szBuf[1024]="";
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__);
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str());
throw runtime_error(szBuf);
}
else if(refCount >= 1) {
char szBuf[1024]="";
snprintf(szBuf,1023,"In [%s::%s Line: %d] about to destroy mutex refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str());
throw runtime_error(szBuf);
}
SDL_DestroyMutex(mutex);
mutex=NULL;
}
@@ -101,7 +108,7 @@ Mutex::~Mutex() {
void Mutex::p() {
if(mutex == NULL) {
char szBuf[1024]="";
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__);
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str());
throw runtime_error(szBuf);
}
SDL_mutexP(mutex);
@@ -111,7 +118,7 @@ void Mutex::p() {
void Mutex::v() {
if(mutex == NULL) {
char szBuf[1024]="";
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__);
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str());
throw runtime_error(szBuf);
}
refCount--;