From f9d7e79153535d266416bdc2cfb286aa276f6f18 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Wed, 20 May 2020 15:22:06 +0000 Subject: [PATCH] Make connections atomic. Disconnect before trying to connect. Fixes an issue where a demo freezes in place if you try to connect while one is running. This also has the side effect of eliminating a duplicate call to CL_StopPlayback, which is called by both CL_EstablishConnection and CL_Disconnect (which is itself called by NetConn_ConnectionEstablished). git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12544 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_main.c | 8 +++----- netconn.c | 2 -- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cl_main.c b/cl_main.c index 7af224e0..b0c913d0 100644 --- a/cl_main.c +++ b/cl_main.c @@ -427,15 +427,13 @@ void CL_EstablishConnection(const char *host, int firstarg) #ifdef CONFIG_MENU M_Update_Return_Reason(""); #endif - cls.demonum = -1; - - // stop demo loop in case this fails - if (cls.demoplayback) - CL_StopPlayback(); // if downloads are running, cancel their finishing action Curl_Clear_forthismap(); + // Disconnect from the current server, or stop a running demo. + CL_Disconnect(); + // make sure the client ports are open before attempting to connect NetConn_UpdateSockets(); diff --git a/netconn.c b/netconn.c index 28b9a575..95b6a8a3 100755 --- a/netconn.c +++ b/netconn.c @@ -1513,8 +1513,6 @@ static void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_ #ifdef CONFIG_MENU M_Update_Return_Reason(""); #endif - // the connection request succeeded, stop current connection and set up a new connection - CL_Disconnect(); // if we're connecting to a remote server, shut down any local server if (LHNETADDRESS_GetAddressType(peeraddress) != LHNETADDRESSTYPE_LOOP && sv.active) { -- 2.39.2