From d69fbc6925f5893ab5d1a2245a8c8a1dc9127932 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 20 Aug 2010 22:42:26 +0000 Subject: [PATCH] - more NULL checking for safer execution - added safer mutex guards in custom game menu --- source/glest_game/menu/menu_state_custom_game.cpp | 11 ++++++----- source/shared_lib/sources/platform/posix/socket.cpp | 13 ++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 4d0bd4e49..57d80f835 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1179,7 +1179,7 @@ void MenuStateCustomGame::simpleTask() { } bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval); - safeMutex.ReleaseLock(true); + safeMutex.ReleaseLock(); if(republish == true) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1226,14 +1226,15 @@ void MenuStateCustomGame::simpleTask() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); GameSettings gameSettings; + + MutexSafeWrapper safeMutex2(&masterServerThreadAccessor); loadGameSettings(&gameSettings); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - safeMutex.Lock(); serverInterface->setGameSettings(&gameSettings); serverInterface->broadcastGameSetup(&gameSettings); - safeMutex.ReleaseLock(true); + safeMutex2.ReleaseLock(); } } @@ -1244,9 +1245,9 @@ void MenuStateCustomGame::simpleTask() { ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL)); - safeMutex.Lock(); + MutexSafeWrapper safeMutex2(&masterServerThreadAccessor); serverInterface->broadcastPing(&msg); - safeMutex.ReleaseLock(true); + safeMutex2.ReleaseLock(); } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 2dec1e63a..5a7a7a95f 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1228,10 +1228,17 @@ bool Socket::isConnected() { } string Socket::getHostName() { - const int strSize= 256; + const int strSize= 257; char hostname[strSize]=""; - gethostname(hostname, strSize); - return (hostname[0] != '\0' ? hostname : ""); + int result = gethostname(hostname, strSize); + string host = ""; + if(result == 0) { + host = (hostname[0] != '\0' ? hostname : ""); + } + else { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] result = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,result,getLastSocketErrorText()); + } + return host; } string Socket::getIp() {