From a64fa69d0288b5a591c87a7c1d368d0519ab8ca0 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 26 Aug 2010 03:15:36 +0000 Subject: [PATCH] - bugfixes for experimental game data synch check in lobby - added a fix for socket sending when the send buffer is full and we have more data to send --- source/glest_game/network/connection_slot.cpp | 4 ++-- source/glest_game/network/network_message.cpp | 6 +++--- source/glest_game/network/network_message.h | 2 +- .../sources/platform/posix/socket.cpp | 21 +++++++++++-------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index d0e60f9e6..a6a8913a5 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -508,7 +508,7 @@ void ConnectionSlot::update(bool checkForNewClients) { vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList); } - string report = networkMessageSynchNetworkGameDataStatus.getTechCRCFileMismatchReport(vctFileList); + string report = networkMessageSynchNetworkGameDataStatus.getTechCRCFileMismatchReport(serverInterface->getGameSettings()->getTech(),vctFileList); this->setNetworkGameDataSynchCheckTechMismatchReport(report); } if(networkGameDataSynchCheckOkMap == false) { @@ -532,7 +532,7 @@ void ConnectionSlot::update(bool checkForNewClients) { vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", NULL); //} - string report = networkMessageSynchNetworkGameDataStatus.getTechCRCFileMismatchReport(vctFileList); + string report = networkMessageSynchNetworkGameDataStatus.getTechCRCFileMismatchReport(serverInterface->getGameSettings()->getTech(),vctFileList); this->setNetworkGameDataSynchCheckTechMismatchReport(report); } } diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 8df8d4608..4efe3ad0a 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -504,7 +504,7 @@ NetworkMessageSynchNetworkGameData::NetworkMessageSynchNetworkGameData(const Gam } string NetworkMessageSynchNetworkGameData::getTechCRCFileMismatchReport(vector > &vctFileList) { - string result = "Filecount local: " + intToStr(vctFileList.size()) + " remote: " + intToStr(data.header.techCRCFileCount) + "\n"; + string result = "Techtree: [" + data.header.tech.getString() + "] Filecount local: " + intToStr(vctFileList.size()) + " remote: " + intToStr(data.header.techCRCFileCount) + "\n"; for(int idx = 0; idx < vctFileList.size(); ++idx) { std::pair &fileInfo = vctFileList[idx]; bool fileFound = false; @@ -683,8 +683,8 @@ NetworkMessageSynchNetworkGameDataStatus::NetworkMessageSynchNetworkGameDataStat } } -string NetworkMessageSynchNetworkGameDataStatus::getTechCRCFileMismatchReport(vector > &vctFileList) { - string result = "Filecount local: " + intToStr(vctFileList.size()) + " remote: " + intToStr(data.header.techCRCFileCount) + "\n"; +string NetworkMessageSynchNetworkGameDataStatus::getTechCRCFileMismatchReport(string techtree, vector > &vctFileList) { + string result = "Techtree: [" + techtree + "] Filecount local: " + intToStr(vctFileList.size()) + " remote: " + intToStr(data.header.techCRCFileCount) + "\n"; for(int idx = 0; idx < vctFileList.size(); ++idx) { std::pair &fileInfo = vctFileList[idx]; bool fileFound = false; diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index b28438a42..cad489fc4 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -464,7 +464,7 @@ public: const NetworkString * getTechCRCFileList() const {return &data.detail.techCRCFileList[0];} const int32 * getTechCRCFileCRCList() const {return data.detail.techCRCFileCRCList;} - string getTechCRCFileMismatchReport(vector > &vctFileList); + string getTechCRCFileMismatchReport(string techtree, vector > &vctFileList); }; #pragma pack(pop) diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index c8346941f..229b0d27f 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1001,20 +1001,21 @@ int Socket::send(const void *data, int dataSize) { 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__); + MutexSafeWrapper safeMutex(&dataSynchAccessor); int attemptCount = 0; time_t tStartTimer = time(NULL); - while((bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= 5)) { + while((bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && + (difftime(time(NULL),tStartTimer) <= 5)) { attemptCount++; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount); - if(Socket::isWritable(true) == true) { + //if(Socket::isWritable(true) == true) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d, sock = %d, dataSize = %d, data = %p\n",__FILE__,__FUNCTION__,__LINE__,attemptCount,sock,dataSize,data); - MutexSafeWrapper safeMutex(&dataSynchAccessor); bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesSent); - } + //} SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount); } } @@ -1022,6 +1023,7 @@ int Socket::send(const void *data, int dataSize) { if(bytesSent > 0 && bytesSent < dataSize) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] need to send more data, trying again getLastSocketError() = %d, bytesSent = %d, dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,getLastSocketError(),bytesSent,dataSize); + MutexSafeWrapper safeMutex(&dataSynchAccessor); int totalBytesSent = bytesSent; int attemptCount = 0; time_t tStartTimer = time(NULL); @@ -1031,10 +1033,9 @@ int Socket::send(const void *data, int dataSize) { attemptCount++; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d, totalBytesSent = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount,totalBytesSent); - if(bytesSent > 0 || Socket::isWritable(true) == true) { + //if(bytesSent > 0 || Socket::isWritable(true) == true) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d, sock = %d, dataSize = %d, data = %p\n",__FILE__,__FUNCTION__,__LINE__,attemptCount,sock,dataSize,data); - MutexSafeWrapper safeMutex(&dataSynchAccessor); const char *sendBuf = (const char *)data; bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, MSG_NOSIGNAL); @@ -1042,10 +1043,12 @@ int Socket::send(const void *data, int dataSize) { totalBytesSent += bytesSent; } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent); - } + //} SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount); } + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] bytesSent = %d, totalBytesSent = %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent,totalBytesSent); + if(bytesSent > 0) { bytesSent = totalBytesSent; } @@ -1173,7 +1176,7 @@ bool Socket::isReadable() { int i = 0; { - MutexSafeWrapper safeMutex(&dataSynchAccessor); + //MutexSafeWrapper safeMutex(&dataSynchAccessor); i= select(sock+1, &set, NULL, NULL, &tv); } if(i < 0) { @@ -1208,7 +1211,7 @@ bool Socket::isWritable(bool waitOnDelayedResponse) { { int i = 0; { - MutexSafeWrapper safeMutex(&dataSynchAccessor); + //MutexSafeWrapper safeMutex(&dataSynchAccessor); i = select(sock+1, NULL, &set, NULL, &tv); } if(i < 0 ) {