← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/unreceived-packets into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/unreceived-packets into lp:widelands.

Commit message:
Deliver received network packets even when the TCP connection is already closed.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/unreceived-packets/+merge/327931

Deliver received network packets even when the TCP connection is already closed.
In most cases, this does not matter. However, it means that we will receive the DISCONNECT message from the metaserver when, e.g., the client timed out. With the current code the client sees the closed connection but does not receive the message. The end result is the same in both cases, but it might differ with other messages.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/unreceived-packets into lp:widelands.
=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc	2017-07-01 08:22:54 +0000
+++ src/network/netclient.cc	2017-07-22 17:39:51 +0000
@@ -52,27 +52,27 @@
 }
 
 bool NetClient::try_receive(RecvPacket* packet) {
-	if (!is_connected()) {
-		return false;
-	}
-
-	uint8_t buffer[kNetworkBufferSize];
-	boost::system::error_code ec;
-	size_t length = socket_.read_some(boost::asio::buffer(buffer, kNetworkBufferSize), ec);
-	if (!ec) {
-		assert(length > 0);
-		assert(length <= kNetworkBufferSize);
-		// Has read something
-		deserializer_.read_data(buffer, length);
-	}
-
-	if (ec && ec != boost::asio::error::would_block) {
-		// Connection closed or some error, close the socket
-		log("[NetClient] Error when trying to receive some data: %s.\n", ec.message().c_str());
-		close();
-		return false;
-	}
-	// Get one packet from the deserializer
+	if (is_connected()) {
+		// If we are connected, try to receive some data
+
+		uint8_t buffer[kNetworkBufferSize];
+		boost::system::error_code ec;
+		size_t length = socket_.read_some(boost::asio::buffer(buffer, kNetworkBufferSize), ec);
+		if (!ec) {
+			assert(length > 0);
+			assert(length <= kNetworkBufferSize);
+			// Has read something
+			deserializer_.read_data(buffer, length);
+		}
+
+		if (ec && ec != boost::asio::error::would_block) {
+			// Connection closed or some error, close the socket
+			log("[NetClient] Error when trying to receive some data: %s.\n", ec.message().c_str());
+			close();
+		//	return false;
+		}
+	}
+	// Try to get one packet from the deserializer
 	return deserializer_.write_packet(packet);
 }
 


Follow ups