summaryrefslogtreecommitdiff
path: root/src/network/core/tcp_content.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-07-13 09:26:11 +0000
committerrubidium <rubidium@openttd.org>2013-07-13 09:26:11 +0000
commit5eac3a77d20c3a838203bd261b05601fa0c7b6ee (patch)
treee28365da85a6103365d043717c56e2d1da088b37 /src/network/core/tcp_content.cpp
parent8f89cd6dd3dff7c36c6080de03b4ffc102f1b771 (diff)
downloadopenttd-5eac3a77d20c3a838203bd261b05601fa0c7b6ee.tar.xz
(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
Diffstat (limited to 'src/network/core/tcp_content.cpp')
-rw-r--r--src/network/core/tcp_content.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp
index ecef92a4f..8a4604feb 100644
--- a/src/network/core/tcp_content.cpp
+++ b/src/network/core/tcp_content.cpp
@@ -183,8 +183,9 @@ bool NetworkContentSocketHandler::HandlePacket(Packet *p)
/**
* 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
@@ -206,12 +207,15 @@ void NetworkContentSocketHandler::ReceivePackets()
* What arbitrary number to choose is the ultimate question though.
*/
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) {
bool cont = this->HandlePacket(p);
delete p;
- if (!cont) return;
+ if (!cont) return true;
}
+
+ return i != MAX_PACKETS_TO_RECEIVE - 1;
}