summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-12-04 18:32:06 +0100
committerGitHub <noreply@github.com>2021-12-04 18:32:06 +0100
commit9c36c12c85ede5a187263d3dda1ed067a6875852 (patch)
treefeda52ced1f4ae3218c7f2c91aadcd931e3521de /src
parent802ca4e72231895e9f043a7b380c59dfbba366cd (diff)
downloadopenttd-9c36c12c85ede5a187263d3dda1ed067a6875852.tar.xz
Codechange: ensure OnConnect() always gets called with a valid socket (#9729)
This should already be the case, but now assert()s will tell us if this isn't.
Diffstat (limited to 'src')
-rw-r--r--src/network/core/tcp.cpp2
-rw-r--r--src/network/core/tcp_connect.cpp2
-rw-r--r--src/network/network_coordinator.cpp2
-rw-r--r--src/network/network_turn.cpp2
4 files changed, 7 insertions, 1 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index a2e31b53d..3dc2a3fac 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -217,6 +217,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
*/
bool NetworkTCPSocketHandler::CanSendReceive()
{
+ assert(this->sock != INVALID_SOCKET);
+
fd_set read_fd, write_fd;
struct timeval tv;
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp
index 73c6aa90d..f9c40c202 100644
--- a/src/network/core/tcp_connect.cpp
+++ b/src/network/core/tcp_connect.cpp
@@ -451,6 +451,8 @@ bool TCPServerConnecter::CheckActivity()
*/
void TCPServerConnecter::SetConnected(SOCKET sock)
{
+ assert(sock != INVALID_SOCKET);
+
this->socket = sock;
this->status = Status::CONNECTED;
}
diff --git a/src/network/network_coordinator.cpp b/src/network/network_coordinator.cpp
index c3fa2b5ce..a52ac638e 100644
--- a/src/network/network_coordinator.cpp
+++ b/src/network/network_coordinator.cpp
@@ -566,6 +566,8 @@ void ClientNetworkCoordinatorSocketHandler::ConnectFailure(const std::string &to
*/
void ClientNetworkCoordinatorSocketHandler::ConnectSuccess(const std::string &token, SOCKET sock, NetworkAddress &address)
{
+ assert(sock != INVALID_SOCKET);
+
/* Connecter will destroy itself. */
this->game_connecter = nullptr;
diff --git a/src/network/network_turn.cpp b/src/network/network_turn.cpp
index ae82f3094..bfc4919e5 100644
--- a/src/network/network_turn.cpp
+++ b/src/network/network_turn.cpp
@@ -41,7 +41,7 @@ public:
{
this->handler->connecter = nullptr;
- handler->sock = s;
+ this->handler->sock = s;
}
};