Changeset - r25454:212b1b5e83b5
[Not reviewed]
master
0 7 0
Rubidium - 3 years ago 2021-05-12 21:06:35
rubidium@openttd.org
Codechange: remove pointless close call due to resolving virtual functions statically in destructors

In the destructors of many of the network related classes Close() is called, just like the
top class in that hierarchy. However, due to virtual functions getting resolved statically
in the destructor it would always call the empty Close() of the top class.
Document the other cases where a virtual call is resolved statically.
7 files changed with 18 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/network/core/core.h
Show inline comments
 
@@ -46,10 +46,7 @@ public:
 
	NetworkSocketHandler() { this->has_quit = false; }
 

	
 
	/** Close the socket when destructing the socket handler */
 
	virtual ~NetworkSocketHandler() { this->Close(); }
 

	
 
	/** Really close the socket */
 
	virtual void Close() {}
 
	virtual ~NetworkSocketHandler() {}
 

	
 
	/**
 
	 * Close the current connection; for TCP this will be mostly equivalent
src/network/core/tcp.cpp
Show inline comments
 
@@ -29,7 +29,8 @@ NetworkTCPSocketHandler::NetworkTCPSocke
 

	
 
NetworkTCPSocketHandler::~NetworkTCPSocketHandler()
 
{
 
	this->CloseConnection();
 
	/* Virtual functions get called statically in destructors, so make it explicit to remove any confusion. */
 
	this->NetworkTCPSocketHandler::CloseConnection();
 

	
 
	if (this->sock != INVALID_SOCKET) closesocket(this->sock);
 
	this->sock = INVALID_SOCKET;
src/network/core/tcp_content.cpp
Show inline comments
 
@@ -137,9 +137,11 @@ const char *ContentInfo::GetTextfile(Tex
 
	return ::GetTextfile(type, GetContentInfoSubDir(this->type), tmp);
 
}
 

	
 
void NetworkContentSocketHandler::Close()
 
/**
 
 * Close the actual socket.
 
 */
 
void NetworkContentSocketHandler::CloseSocket()
 
{
 
	CloseConnection();
 
	if (this->sock == INVALID_SOCKET) return;
 

	
 
	closesocket(this->sock);
src/network/core/tcp_content.h
Show inline comments
 
@@ -21,7 +21,7 @@
 
/** Base socket handler for all Content TCP sockets */
 
class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
 
protected:
 
	void Close() override;
 
	void CloseSocket();
 

	
 
	bool ReceiveInvalidPacket(PacketContentType type);
 

	
 
@@ -124,7 +124,11 @@ public:
 
	}
 

	
 
	/** On destructing of this class, the socket needs to be closed */
 
	virtual ~NetworkContentSocketHandler() { this->Close(); }
 
	virtual ~NetworkContentSocketHandler()
 
	{
 
		/* Virtual functions get called statically in destructors, so make it explicit to remove any confusion. */
 
		this->CloseSocket();
 
	}
 

	
 
	bool ReceivePackets();
 
};
src/network/core/udp.h
Show inline comments
 
@@ -190,7 +190,7 @@ public:
 
	virtual ~NetworkUDPSocketHandler() { this->Close(); }
 

	
 
	bool Listen();
 
	void Close() override;
 
	void Close();
 

	
 
	void SendPacket(Packet *p, NetworkAddress *recv, bool all = false, bool broadcast = false);
 
	void ReceivePackets();
src/network/network_content.cpp
Show inline comments
 
@@ -784,7 +784,9 @@ void ClientNetworkContentSocketHandler::
 
void ClientNetworkContentSocketHandler::Close()
 
{
 
	if (this->sock == INVALID_SOCKET) return;
 
	NetworkContentSocketHandler::Close();
 

	
 
	this->CloseConnection();
 
	this->CloseSocket();
 

	
 
	this->OnDisconnect();
 
}
src/network/network_content.h
Show inline comments
 
@@ -107,7 +107,7 @@ public:
 

	
 
	void Connect();
 
	void SendReceive();
 
	void Close() override;
 
	void Close();
 

	
 
	void RequestContentList(ContentType type);
 
	void RequestContentList(uint count, const ContentID *content_ids);
0 comments (0 inline, 0 general)