summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-05-12 23:06:35 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-13 10:03:26 +0200
commit187a3f20bfd7578362f666b869580bafe25ffd0b (patch)
tree5fcc3ca99b265880771c083252cd2eb2c3ed559a /src/network
parent7755f81bb8ba1c6a47e3a528acbbc462e56adaff (diff)
downloadopenttd-187a3f20bfd7578362f666b869580bafe25ffd0b.tar.xz
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.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/core.h5
-rw-r--r--src/network/core/tcp.cpp3
-rw-r--r--src/network/core/tcp_content.cpp6
-rw-r--r--src/network/core/tcp_content.h8
-rw-r--r--src/network/core/udp.h2
-rw-r--r--src/network/network_content.cpp4
-rw-r--r--src/network/network_content.h2
7 files changed, 18 insertions, 12 deletions
diff --git a/src/network/core/core.h b/src/network/core/core.h
index 37948ad52..a16ed9f23 100644
--- a/src/network/core/core.h
+++ b/src/network/core/core.h
@@ -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
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 3bba291c7..5c436edf0 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -29,7 +29,8 @@ NetworkTCPSocketHandler::NetworkTCPSocketHandler(SOCKET s) :
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;
diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp
index 0371b7621..3abf1c29c 100644
--- a/src/network/core/tcp_content.cpp
+++ b/src/network/core/tcp_content.cpp
@@ -137,9 +137,11 @@ const char *ContentInfo::GetTextfile(TextfileType type) const
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);
diff --git a/src/network/core/tcp_content.h b/src/network/core/tcp_content.h
index 52cae1e0e..b1bde4817 100644
--- a/src/network/core/tcp_content.h
+++ b/src/network/core/tcp_content.h
@@ -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();
};
diff --git a/src/network/core/udp.h b/src/network/core/udp.h
index 881fb0a61..ab898eeee 100644
--- a/src/network/core/udp.h
+++ b/src/network/core/udp.h
@@ -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();
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index e4f368618..26d220b6a 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -784,7 +784,9 @@ void ClientNetworkContentSocketHandler::Connect()
void ClientNetworkContentSocketHandler::Close()
{
if (this->sock == INVALID_SOCKET) return;
- NetworkContentSocketHandler::Close();
+
+ this->CloseConnection();
+ this->CloseSocket();
this->OnDisconnect();
}
diff --git a/src/network/network_content.h b/src/network/network_content.h
index f28821a0b..13b93417c 100644
--- a/src/network/network_content.h
+++ b/src/network/network_content.h
@@ -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);