- fixed a possible infinite loop while receiving network packets on clients for network games (found by titi's stack trace dump)

This commit is contained in:
Mark Vejvoda
2010-08-20 18:06:03 +00:00
parent 31363fd41b
commit 277362a6c7

View File

@@ -532,9 +532,11 @@ void ClientInterface::updateKeyframe(int frameCount)
int waitCount = 0; int waitCount = 0;
//make sure we read the message //make sure we read the message
time_t receiveTimeElapsed = time(NULL);
NetworkMessageCommandList networkMessageCommandList; NetworkMessageCommandList networkMessageCommandList;
while(receiveMessage(&networkMessageCommandList) == false && while(receiveMessage(&networkMessageCommandList) == false &&
isConnected() == true) { isConnected() == true &&
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 1000)) {
//sleep(waitSleepTime); //sleep(waitSleepTime);
sleep(0); sleep(0);
waitCount++; waitCount++;
@@ -582,10 +584,12 @@ void ClientInterface::updateKeyframe(int frameCount)
case nmtQuit: case nmtQuit:
{ {
time_t receiveTimeElapsed = time(NULL);
NetworkMessageQuit networkMessageQuit; NetworkMessageQuit networkMessageQuit;
//if(receiveMessage(&networkMessageQuit)) { //if(receiveMessage(&networkMessageQuit)) {
while(receiveMessage(&networkMessageQuit) == false && while(receiveMessage(&networkMessageQuit) == false &&
isConnected() == true) { isConnected() == true &&
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 1000)) {
sleep(0); sleep(0);
} }
quit= true; quit= true;
@@ -595,15 +599,14 @@ void ClientInterface::updateKeyframe(int frameCount)
case nmtText: case nmtText:
{ {
time_t receiveTimeElapsed = time(NULL);
NetworkMessageText networkMessageText; NetworkMessageText networkMessageText;
while(receiveMessage(&networkMessageText) == false && while(receiveMessage(&networkMessageText) == false &&
isConnected() == true) { isConnected() == true &&
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 1000)) {
sleep(0); sleep(0);
} }
//chatText = networkMessageText.getText();
//chatSender = networkMessageText.getSender();
//chatTeamIndex = networkMessageText.getTeamIndex();
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex()); ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
this->addChatInfo(msg); this->addChatInfo(msg);
} }