From 0069fbf4f0e5fe79dced03bc0f0e9d39d2dddab7 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 31 May 2010 06:11:31 +0000 Subject: [PATCH] - added more debug code and fixed a server bug where client connecting at the same time a server opens a slot would result in a crash sometimes. --- source/glest_game/game/commander.cpp | 6 +- .../menu/menu_state_connected_game.cpp | 10 +- .../menu/menu_state_custom_game.cpp | 7 ++ source/glest_game/network/network_message.cpp | 14 +-- source/glest_game/type_instances/command.cpp | 9 +- source/glest_game/type_instances/command.h | 2 +- source/glest_game/type_instances/unit.cpp | 25 ++--- .../sources/graphics/gl/context_gl.cpp | 15 +-- .../platform/common/platform_common.cpp | 14 +-- .../sources/platform/posix/socket.cpp | 105 ++++++------------ .../sources/platform/sdl/gl_wrap.cpp | 10 +- source/shared_lib/sources/util/checksum.cpp | 2 +- 12 files changed, 97 insertions(+), 122 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index b8a3ac42..6c63d1a8 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -233,9 +233,9 @@ CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand CommandResult cr= crSuccess; //validate unit - if(unit==NULL){ + if(unit == NULL) { char szBuf[1024]=""; - sprintf(szBuf,"In [%s::%s - %d] Command refers to non existant unit id = %d. Game out of synch.", + sprintf(szBuf,"In [%s::%s - %d] Command refers to non existent unit id = %d. Game out of synch.", __FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId()); throw runtime_error(szBuf); } @@ -244,7 +244,7 @@ CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand gameNetworkInterface->requestCommand(networkCommand); //calculate the result of the command - if(networkCommand->getNetworkCommandType()==nctGiveCommand){ + if(networkCommand->getNetworkCommandType() == nctGiveCommand) { Command* command= buildCommand(networkCommand); cr= unit->checkCommand(command); delete command; diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index b1f1add8..c1c6b6d1 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -509,7 +509,7 @@ void MenuStateConnectedGame::update() hasFactions = loadFactions(gameSettings); } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] hasFactions = %d\n",__FILE__,__FUNCTION__,__LINE__,hasFactions); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] hasFactions = %d\n",__FILE__,__FUNCTION__,__LINE__,hasFactions); // map maps.push_back(formatString(gameSettings->getMap())); @@ -519,7 +519,7 @@ void MenuStateConnectedGame::update() currentMap = gameSettings->getMap(); } - 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__); // FogOfWar if(gameSettings->getFogOfWar()){ @@ -530,7 +530,7 @@ void MenuStateConnectedGame::update() listBoxFogOfWar.setSelectedItemIndex(1); } - 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__); // Control for(int i=0; igetFactionCount(); ++i){ int slot=gameSettings->getStartLocationIndex(i); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 3fcd261b..2ac655bf 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -221,6 +221,13 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b updateControlers(); updateNetworkSlots(); + // Esnure we have set the gamesettings at least once + GameSettings gameSettings; + loadGameSettings(&gameSettings); + + ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); + serverInterface->setGameSettings(&gameSettings,true); + //chatManager.init(&console, world.getThisTeamIndex()); chatManager.init(&console, -1); diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 80dc7c50..54650f65 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -243,17 +243,17 @@ bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand) bool NetworkMessageCommandList::receive(Socket* socket){ // _peek_ type, commandCount & frame num first. if (!NetworkMessage::peek(socket, &data, commandListHeaderSize)) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] WARNING!!! NetworkMessage::peek failed!\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING!!! NetworkMessage::peek failed!\n",__FILE__,__FUNCTION__,__LINE__); return false; } - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", __FILE__,__FUNCTION__,__LINE__,data.messageType,data.frameCount,data.commandCount); // read header + data.commandCount commands. int totalMsgSize = commandListHeaderSize + sizeof(NetworkCommand) * data.commandCount; if (socket->getDataToRead() < totalMsgSize) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] WARNING!!! Insufficient data to read entire command list [need %d bytes, only %d available].\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING!!! Insufficient data to read entire command list [need %d bytes, only %d available].\n", __FILE__,__FUNCTION__,__LINE__, totalMsgSize, socket->getDataToRead()); return false; } @@ -262,7 +262,7 @@ bool NetworkMessageCommandList::receive(Socket* socket){ for(int idx = 0 ; idx < data.commandCount; ++idx) { const NetworkCommand &cmd = data.commands[idx]; - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] index = %d, received networkCommand [%s]\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] index = %d, received networkCommand [%s]\n", __FILE__,__FUNCTION__,__LINE__,idx, cmd.toString().c_str()); } } @@ -274,14 +274,14 @@ void NetworkMessageCommandList::send(Socket* socket) const{ NetworkMessage::send(socket, &data, commandListHeaderSize + sizeof(NetworkCommand) * data.commandCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", __FILE__,__FUNCTION__,__LINE__,data.messageType,data.frameCount,data.commandCount); - if (data.commandCount) { + if (data.commandCount > 0) { for(int idx = 0 ; idx < data.commandCount; ++idx) { const NetworkCommand &cmd = data.commands[idx]; - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] index = %d, sent networkCommand [%s]\n", + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] index = %d, sent networkCommand [%s]\n", __FILE__,__FUNCTION__,__LINE__,idx, cmd.toString().c_str()); } } diff --git a/source/glest_game/type_instances/command.cpp b/source/glest_game/type_instances/command.cpp index 6ba6ae00..1601fa1d 100644 --- a/source/glest_game/type_instances/command.cpp +++ b/source/glest_game/type_instances/command.cpp @@ -71,9 +71,14 @@ void Command::setUnit(Unit *unit){ std::string Command::toString() const { std::string result = ""; - result = "commandType = " + commandType->toString() + " pos = " + pos.getString() + " facing = " + intToStr(facing.asInt()); + result = "commandType id = " + intToStr(commandType->getId()) + ", desc = " + commandType->toString() + ", pos = " + pos.getString() + ", facing = " + intToStr(facing.asInt()); + + if(unitRef.getUnit() != NULL) { + result += ", unitRef.getUnit() = " + unitRef.getUnit()->toString(); + } + if(unitType != NULL) { - result += " unitTypeId = " + intToStr(unitType->getId()) + " unitTypeDesc = " + unitType->getReqDesc(); + result += ", unitTypeId = " + intToStr(unitType->getId()) + ", unitTypeDesc = " + unitType->getReqDesc(); } return result; } diff --git a/source/glest_game/type_instances/command.h b/source/glest_game/type_instances/command.h index 84521f69..268de2e0 100644 --- a/source/glest_game/type_instances/command.h +++ b/source/glest_game/type_instances/command.h @@ -34,7 +34,7 @@ class Command{ private: const CommandType *commandType; Vec2i pos; - UnitReference unitRef; //target unit, used to move and attack optinally + UnitReference unitRef; //target unit, used to move and attack optionally CardinalDir facing; // facing, for build command const UnitType *unitType; //used for build diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 36931f61..5fdcce60 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -506,19 +506,15 @@ unsigned int Unit::getCommandSize() const{ } //give one command (clear, and push back) -CommandResult Unit::giveCommand(Command *command, bool tryQueue){ +CommandResult Unit::giveCommand(Command *command, bool tryQueue) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit id = %d name = %s, Command [%s] tryQueue = %d\n",__FILE__,__FUNCTION__, __LINE__,this->id,this->type->getName().c_str(), command->toString().c_str(),tryQueue); assert(command != NULL); assert(command->getCommandType() != NULL); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,command->getCommandType()->getId()); - - 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__); const int command_priority = command->getCommandType()->getPriority(); @@ -528,7 +524,8 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue){ if ((*i)->getCommandType()->getPriority() < command_priority) { deleteSingleCommand(*i); i = commands.erase(i); - } else { + } + else { ++i; } } @@ -540,7 +537,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue){ cancelCommand(); } } - else{ + else { //empty command queue SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); clearCommands(); @@ -552,7 +549,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue){ //check command SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); CommandResult result= checkCommand(command); - if(result==crSuccess){ + if(result == crSuccess) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); applyCommand(command); } @@ -560,16 +557,16 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B\n",__FILE__,__FUNCTION__); //push back command - if(result== crSuccess){ + if(result == crSuccess) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); commands.push_back(command); } - else{ + else { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); delete command; } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] result = %d\n",__FILE__,__FUNCTION__,__LINE__,result); return result; } @@ -1280,7 +1277,7 @@ std::string Unit::toString() const { } if(this->faction != NULL) { - result = "FactionIndex = " + intToStr(this->faction->getIndex()) + "\n"; + result += "\nFactionIndex = " + intToStr(this->faction->getIndex()) + "\n"; result += "teamIndex = " + intToStr(this->faction->getTeam()) + "\n"; result += "startLocationIndex = " + intToStr(this->faction->getStartLocationIndex()) + "\n"; result += "thisFaction = " + intToStr(this->faction->getThisFaction()) + "\n"; diff --git a/source/shared_lib/sources/graphics/gl/context_gl.cpp b/source/shared_lib/sources/graphics/gl/context_gl.cpp index 15a4d3d2..0d4e8193 100644 --- a/source/shared_lib/sources/graphics/gl/context_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/context_gl.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -28,12 +28,9 @@ namespace Shared{ namespace Graphics{ namespace Gl{ // ===================================================== void ContextGl::init(){ - - 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__); pcgl.init(colorBits, depthBits, stencilBits); - - 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__); } void ContextGl::end(){ @@ -41,11 +38,9 @@ void ContextGl::end(){ } void ContextGl::makeCurrent(){ - 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__); pcgl.makeCurrent(); - - 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__); } void ContextGl::swapBuffers(){ diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 6d675b33..7e00679c 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -286,7 +286,7 @@ bool EndsWith(const string &str, const string& key) //finds all filenames like path and gets their checksum of all files combined int32 getFolderTreeContentsCheckSumRecursively(vector paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum) { - 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__); // !!! OLD local CACHE //static std::map crcTreeCache; @@ -309,7 +309,7 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path for(size_t idx = 0; idx < count; ++idx) { string path = paths[idx] + pathSearchString; - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s], filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s], filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); getFolderTreeContentsCheckSumRecursively(path, filterFileExt, &checksum); } @@ -326,7 +326,7 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path //finds all filenames like path and gets their checksum of all files combined int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); // !!! OLD local CACHE //static std::map crcTreeCache; @@ -377,7 +377,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string } if(addFile) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); checksum.addFile(p); fileMatchCount++; @@ -445,7 +445,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(ve getFolderTreeContentsCheckSumListRecursively(path, filterFileExt, &checksumFiles); } - 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__); crcTreeCache[cacheKey] = checksumFiles; return crcTreeCache[cacheKey]; @@ -453,7 +453,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(ve //finds all filenames like path and gets the checksum of each file vector > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector > *recursiveMap) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); //static std::map > > crcTreeCache; string cacheLookupId = string(__FILE__) + intToStr(__LINE__); @@ -467,7 +467,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(co vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); std::string mypath = path; /** Stupid win32 is searching for all files without extension when *. is diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 998e2459..aed5c8f4 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -872,32 +872,26 @@ int Socket::getDataToRead(){ int Socket::send(const void *data, int dataSize) { ssize_t bytesSent= 0; - if(isSocketValid() == true) - { + if(isSocketValid() == true) { bytesSent = ::send(sock, reinterpret_cast(data), dataSize, 0); } - if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) - { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] ERROR WRITING SOCKET DATA, err = %d error = %s\n",__FILE__,__FUNCTION__,bytesSent,getLastSocketErrorFormattedText().c_str()); + if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR WRITING SOCKET DATA, err = %d error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesSent,getLastSocketErrorFormattedText().c_str()); //throwException(szBuf); } - else if(bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) - { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 EAGAIN during send, trying again...\n",__FILE__,__FUNCTION__); + else if(bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 EAGAIN during send, trying again...\n",__FILE__,__FUNCTION__,__LINE__); time_t tStartTimer = time(NULL); - while((bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) - { - if(Socket::isWritable(true) == true) - { + while((bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) { + if(Socket::isWritable(true) == true) { bytesSent = ::send(sock, reinterpret_cast(data), dataSize, 0); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesSent); } } } - if(bytesSent <= 0) - { + if(bytesSent <= 0) { int iErr = getLastSocketError(); disconnectSocket(); @@ -914,24 +908,19 @@ int Socket::receive(void *data, int dataSize) { ssize_t bytesReceived = 0; - if(isSocketValid() == true) - { + if(isSocketValid() == true) { bytesReceived = recv(sock, reinterpret_cast(data), dataSize, 0); } - if(bytesReceived < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) - { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,bytesReceived,getLastSocketErrorFormattedText().c_str()); + if(bytesReceived < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText().c_str()); //throwException(szBuf); } - else if(bytesReceived < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) - { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 EAGAIN during receive, trying again...\n",__FILE__,__FUNCTION__); + else if(bytesReceived < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 EAGAIN during receive, trying again...\n",__FILE__,__FUNCTION__,__LINE__); time_t tStartTimer = time(NULL); - while((bytesReceived < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) - { - if(Socket::isReadable() == true) - { + while((bytesReceived < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) { + if(Socket::isReadable() == true) { bytesReceived = recv(sock, reinterpret_cast(data), dataSize, 0); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesReceived); @@ -939,8 +928,7 @@ int Socket::receive(void *data, int dataSize) } } - if(bytesReceived <= 0) - { + if(bytesReceived <= 0) { int iErr = getLastSocketError(); disconnectSocket(); @@ -952,26 +940,21 @@ int Socket::receive(void *data, int dataSize) int Socket::peek(void *data, int dataSize){ ssize_t err = 0; - if(isSocketValid() == true) - { + if(isSocketValid() == true) { err = recv(sock, reinterpret_cast(data), dataSize, MSG_PEEK); } - if(err < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) - { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] ERROR PEEKING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,err,getLastSocketErrorFormattedText().c_str()); + if(err < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR PEEKING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str()); //throwException(szBuf); disconnectSocket(); } - else if(err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) - { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__); + 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__); time_t tStartTimer = time(NULL); - while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) - { - if(Socket::isReadable() == true) - { + while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) { + if(Socket::isReadable() == true) { err = recv(sock, reinterpret_cast(data), dataSize, MSG_PEEK); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,err); @@ -979,8 +962,7 @@ int Socket::peek(void *data, int dataSize){ } } - if(err <= 0) - { + if(err <= 0) { int iErr = getLastSocketError(); disconnectSocket(); @@ -1007,8 +989,7 @@ void Socket::setBlock(bool block, PLATFORM_SOCKET socket){ } } -bool Socket::isReadable() -{ +bool Socket::isReadable() { if(isSocketValid() == false) return false; #ifndef WIN32 struct timeval tv; @@ -1023,10 +1004,8 @@ bool Socket::isReadable() FD_SET(sock, &set); int i= select(sock+1, &set, NULL, NULL, &tv); - if(i < 0) - { - if(difftime(time(NULL),lastDebugEvent) >= 1) - { + if(i < 0) { + if(difftime(time(NULL),lastDebugEvent) >= 1) { lastDebugEvent = time(NULL); //throwException("Error selecting socket"); @@ -1037,8 +1016,7 @@ bool Socket::isReadable() return (i == 1); } -bool Socket::isWritable(bool waitOnDelayedResponse) -{ +bool Socket::isWritable(bool waitOnDelayedResponse) { if(isSocketValid() == false) return false; #ifndef WIN32 @@ -1057,10 +1035,8 @@ bool Socket::isWritable(bool waitOnDelayedResponse) do { int i = select(sock+1, NULL, &set, NULL, &tv); - if(i < 0 ) - { - if(difftime(time(NULL),lastDebugEvent) >= 1) - { + if(i < 0 ) { + if(difftime(time(NULL),lastDebugEvent) >= 1) { lastDebugEvent = time(NULL); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,i,getLastSocketErrorFormattedText().c_str()); @@ -1069,21 +1045,17 @@ bool Socket::isWritable(bool waitOnDelayedResponse) //throwException("Error selecting socket"); } - else if(i == 0) - { - if(difftime(time(NULL),lastDebugEvent) >= 1) - { + else if(i == 0) { + if(difftime(time(NULL),lastDebugEvent) >= 1) { lastDebugEvent = time(NULL); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] TIMEOUT while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,i,getLastSocketErrorFormattedText().c_str()); } - if(waitOnDelayedResponse == false) - { + if(waitOnDelayedResponse == false) { result = true; } } - else - { + else { result = true; } } while(waitOnDelayedResponse == true && result == false); @@ -1092,17 +1064,14 @@ bool Socket::isWritable(bool waitOnDelayedResponse) return result; } -bool Socket::isConnected() -{ +bool Socket::isConnected() { //if the socket is not writable then it is not conencted - if(isWritable(false) == false) - { + if(isWritable(false) == false) { return false; } //if the socket is readable it is connected if we can read a byte from it - if(isReadable()) - { + if(isReadable()) { char tmp; int err = peek(&tmp, sizeof(tmp)); return (err > 0); diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index d03f14aa..c4ea41db 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -103,7 +103,9 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, if(display == 0) { throw std::runtime_error("Couldn't create font: display is 0"); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] trying to load font %s\n",__FILE__,__FUNCTION__,__LINE__,type.c_str()); + XFontStruct* fontInfo = XLoadQueryFont(display, type.c_str()); if(!fontInfo) { fontInfo = XLoadQueryFont(display, "fixed"); @@ -121,7 +123,7 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, } metrics.setHeight(height); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] height = %f\n",__FILE__,__FUNCTION__,__LINE__,height); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] height = %f\n",__FILE__,__FUNCTION__,__LINE__,height); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -171,15 +173,15 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, //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__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); glXUseXFont(fontInfo->fid, 0, charCount, base); - 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__); GLenum glerror = ::glGetError(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] glerror = %d\n",__FILE__,__FUNCTION__,__LINE__,glerror); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] glerror = %d\n",__FILE__,__FUNCTION__,__LINE__,glerror); XFreeFont(display, fontInfo); diff --git a/source/shared_lib/sources/util/checksum.cpp b/source/shared_lib/sources/util/checksum.cpp index 345cf950..1f54612e 100644 --- a/source/shared_lib/sources/util/checksum.cpp +++ b/source/shared_lib/sources/util/checksum.cpp @@ -89,7 +89,7 @@ int32 Checksum::getSum() { fileResult.addFileToSum(iterMap->first); Checksum::fileListCache[iterMap->first] = fileResult.getSum(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] iterMap->first [%s] has CRC [%d]\n",__FILE__,__FUNCTION__,__LINE__,iterMap->first.c_str(),Checksum::fileListCache[iterMap->first]); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] iterMap->first [%s] has CRC [%d]\n",__FILE__,__FUNCTION__,__LINE__,iterMap->first.c_str(),Checksum::fileListCache[iterMap->first]); } newResult.addSum(Checksum::fileListCache[iterMap->first]); }