- 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.

This commit is contained in:
Mark Vejvoda 2010-05-31 06:11:31 +00:00
parent e8cc925a8b
commit 0069fbf4f0
12 changed files with 97 additions and 122 deletions

View File

@ -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;

View File

@ -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; i<GameConstants::maxPlayers; ++i){
@ -539,10 +539,10 @@ void MenuStateConnectedGame::update()
listBoxTeams[i].setEditable(false);
}
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__);
if(hasFactions == 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__);
for(int i=0; i<gameSettings->getFactionCount(); ++i){
int slot=gameSettings->getStartLocationIndex(i);

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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;
}

View File

@ -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

View File

@ -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";

View File

@ -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(){

View File

@ -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<string> 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<string,int32> crcTreeCache;
@ -309,7 +309,7 @@ int32 getFolderTreeContentsCheckSumRecursively(vector<string> 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<string> 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<string,int32> 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<std::pair<string,int32> > 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<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(ve
//finds all filenames like path and gets the checksum of each file
vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector<std::pair<string,int32> > *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<string,vector<std::pair<string,int32> > > crcTreeCache;
string cacheLookupId = string(__FILE__) + intToStr(__LINE__);
@ -467,7 +467,7 @@ vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(co
vector<std::pair<string,int32> > checksumFiles = (recursiveMap == NULL ? vector<std::pair<string,int32> >() : *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

View File

@ -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<const char*>(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<const char*>(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<char*>(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<char*>(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<char*>(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<char*>(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);

View File

@ -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);

View File

@ -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]);
}