Skip to content

Commit

Permalink
Merge pull request #835 from beyond-all-reason/revert-827-fix-unsafe-…
Browse files Browse the repository at this point in the history
…socket-usage

Revert "Fix not closing sockets and bad timeout error condition checks."
  • Loading branch information
AntlerForce authored Nov 30, 2024
2 parents c324709 + 264e041 commit 5b31a0a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
12 changes: 3 additions & 9 deletions LuaMenu/widgets/api_analytics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,11 @@ end


local function SocketConnect(host, port)
if client then
client:close()
end
client=socket.tcp()
client:settimeout(0)
res, err = client:connect(host, port)
if not res and err ~= "timeout" then
if not res and not res=="timeout" then
if PRINT_DEBUG then Spring.Echo("Error in connection to Analytics server: "..err) end
client:close()
client = nil
return false
end
if PRINT_DEBUG then Spring.Echo("Analytics connected") end
Expand Down Expand Up @@ -657,8 +652,8 @@ local function LobbyInfo()
local message = "c.telemetry.log_client_event lobby:info " .. Spring.Utilities.Base64Encode(Spring.Utilities.json.encode(t)).." ".. machineHash .. "\n"
local client=socket.tcp()
local res, err = client:connect(host, port)
if not res and err ~= "timeout" then Spring.Echo("Lobby:Info Error", res, err) else client:send(message) end
client:close()
if not res and not res=="timeout" then Spring.Echo("Lobby:Info Error", res, err) else client:send(message) end
if client ~= nil then client:close() end
end
end

Expand Down Expand Up @@ -740,7 +735,6 @@ function widget:Initialize()
isConnected = true
if client ~= nil then
client:close()
client = nil
end
ACTIVE = false
-- disconnect
Expand Down
1 change: 0 additions & 1 deletion libs/liblobby/lobby/interface_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function Interface:Disconnect(reason)
self.finishedConnecting = false
if self.client then
self.client:close()
self.client = nil
end
self:_OnDisconnected(reason, true)
end
Expand Down
7 changes: 1 addition & 6 deletions libs/spring-launcher/luaui/widgets/api_spring_launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,10 @@ local function explode(div,str)
end

function widget:SocketConnect()
if client then
client:close()
end
client = socket.tcp()
client:settimeout(0)
local res, err = client:connect(host, port)
if not res and err ~= "timeout" then
client:close()
client = nil
if not res and not res == "timeout" then
widgetHandler:RemoveWidget(self)
Spring.Log(LOG_SECTION, LOG.ERROR, "Error in connect launcher: " .. err)
return false
Expand Down

0 comments on commit 5b31a0a

Please sign in to comment.