- more NULL checking for safer execution

- added safer mutex guards in custom game menu
This commit is contained in:
Mark Vejvoda
2010-08-20 22:42:26 +00:00
parent 0e82836e01
commit d69fbc6925
2 changed files with 16 additions and 8 deletions

View File

@@ -1179,7 +1179,7 @@ void MenuStateCustomGame::simpleTask() {
} }
bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval); bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval);
safeMutex.ReleaseLock(true); safeMutex.ReleaseLock();
if(republish == true) { if(republish == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); 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__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
GameSettings gameSettings; GameSettings gameSettings;
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
loadGameSettings(&gameSettings); loadGameSettings(&gameSettings);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutex.Lock();
serverInterface->setGameSettings(&gameSettings); serverInterface->setGameSettings(&gameSettings);
serverInterface->broadcastGameSetup(&gameSettings); serverInterface->broadcastGameSetup(&gameSettings);
safeMutex.ReleaseLock(true); safeMutex2.ReleaseLock();
} }
} }
@@ -1244,9 +1245,9 @@ void MenuStateCustomGame::simpleTask() {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL)); NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL));
safeMutex.Lock(); MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
serverInterface->broadcastPing(&msg); serverInterface->broadcastPing(&msg);
safeMutex.ReleaseLock(true); safeMutex2.ReleaseLock();
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@@ -1228,10 +1228,17 @@ bool Socket::isConnected() {
} }
string Socket::getHostName() { string Socket::getHostName() {
const int strSize= 256; const int strSize= 257;
char hostname[strSize]=""; char hostname[strSize]="";
gethostname(hostname, strSize); int result = gethostname(hostname, strSize);
return (hostname[0] != '\0' ? hostname : ""); 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() { string Socket::getIp() {