mirror of https://github.com/OpenTTD/OpenTTD
(svn r25597) -Fix [FS#5635]: [Content] When the server closed the connection, the client would for eternity try to read a packet and never timeout making it impossible to reconnect
parent
8f89cd6dd3
commit
5eac3a77d2
|
@ -183,8 +183,9 @@ bool NetworkContentSocketHandler::HandlePacket(Packet *p)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receive a packet at TCP level
|
* Receive a packet at TCP level
|
||||||
|
* @return Whether at least one packet was received.
|
||||||
*/
|
*/
|
||||||
void NetworkContentSocketHandler::ReceivePackets()
|
bool NetworkContentSocketHandler::ReceivePackets()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We read only a few of the packets. This as receiving packets can be expensive
|
* We read only a few of the packets. This as receiving packets can be expensive
|
||||||
|
@ -206,12 +207,15 @@ void NetworkContentSocketHandler::ReceivePackets()
|
||||||
* What arbitrary number to choose is the ultimate question though.
|
* What arbitrary number to choose is the ultimate question though.
|
||||||
*/
|
*/
|
||||||
Packet *p;
|
Packet *p;
|
||||||
int i = 42;
|
static const int MAX_PACKETS_TO_RECEIVE = 42;
|
||||||
|
int i = MAX_PACKETS_TO_RECEIVE;
|
||||||
while (--i != 0 && (p = this->ReceivePacket()) != NULL) {
|
while (--i != 0 && (p = this->ReceivePacket()) != NULL) {
|
||||||
bool cont = this->HandlePacket(p);
|
bool cont = this->HandlePacket(p);
|
||||||
delete p;
|
delete p;
|
||||||
if (!cont) return;
|
if (!cont) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return i != MAX_PACKETS_TO_RECEIVE - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ public:
|
||||||
/** On destructing of this class, the socket needs to be closed */
|
/** On destructing of this class, the socket needs to be closed */
|
||||||
virtual ~NetworkContentSocketHandler() { this->Close(); }
|
virtual ~NetworkContentSocketHandler() { this->Close(); }
|
||||||
|
|
||||||
void ReceivePackets();
|
bool ReceivePackets();
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef OPENTTD_MSU
|
#ifndef OPENTTD_MSU
|
||||||
|
|
|
@ -778,8 +778,10 @@ void ClientNetworkContentSocketHandler::SendReceive()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->CanSendReceive()) {
|
if (this->CanSendReceive()) {
|
||||||
this->ReceivePackets();
|
if (this->ReceivePackets()) {
|
||||||
this->lastActivity = _realtime_tick;
|
/* Only update activity once a packet is received, instead of everytime we try it. */
|
||||||
|
this->lastActivity = _realtime_tick;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->SendPackets();
|
this->SendPackets();
|
||||||
|
|
Loading…
Reference in New Issue