Changeset - r17613:a9b2554a5d79
[Not reviewed]
master
0 1 0
rubidium - 13 years ago 2011-04-30 17:41:14
rubidium@openttd.org
(svn r22387) -Fix-ish [FS#4601]: Windows' recv seems to return "graceful closed" before having passed the remaining buffer which causes OpenTTD to think all connections are "incorrectly" terminated, i.e. without the "I'm leaving" packet from the client. So let the client wait a tiny bit after sending the "I'm leaving" packet and before gracefully closing the connection
1 file changed with 7 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/network/network_client.cpp
Show inline comments
 
@@ -16,24 +16,25 @@
 
#include "network_gui.h"
 
#include "../saveload/saveload.h"
 
#include "../saveload/saveload_filter.h"
 
#include "../command_func.h"
 
#include "../console_func.h"
 
#include "../strings_func.h"
 
#include "../window_func.h"
 
#include "../company_func.h"
 
#include "../company_base.h"
 
#include "../company_gui.h"
 
#include "../core/random_func.hpp"
 
#include "../date_func.h"
 
#include "../gfx_func.h"
 
#include "../gui.h"
 
#include "../rev.h"
 
#include "network.h"
 
#include "network_base.h"
 
#include "network_client.h"
 
#include "../core/backup_type.hpp"
 

	
 
#include "table/strings.h"
 

	
 
/* This file handles all the client-commands */
 

	
 

	
 
@@ -143,24 +144,30 @@ NetworkRecvStatus ClientNetworkGameSocke
 
	 * Sending a message just before leaving the game calls cs->SendPackets.
 
	 * This might invoke this function, which means that when we close the
 
	 * connection after cs->SendPackets we will close an already closed
 
	 * connection. This handles that case gracefully without having to make
 
	 * that code any more complex or more aware of the validity of the socket.
 
	 */
 
	if (this->sock == INVALID_SOCKET) return status;
 

	
 
	DEBUG(net, 1, "Closed client connection %d", this->client_id);
 

	
 
	this->SendPackets(true);
 

	
 
	/* Wait a number of ticks so our leave message can reach the server.
 
	 * This is especially needed for Windows servers as they seem to get
 
	 * the "socket is closed" message before receiving our leave message,
 
	 * which would trigger the server to close the connection as well. */
 
	CSleep(3 * MILLISECONDS_PER_TICK);
 

	
 
	delete this->GetInfo();
 
	delete this;
 

	
 
	return status;
 
}
 

	
 
/**
 
 * Handle an error coming from the client side.
 
 * @param res The "error" that happened.
 
 */
 
void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
 
{
0 comments (0 inline, 0 general)