Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not closing sockets and bad timeout error condition checks. #827

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions LuaMenu/widgets/api_analytics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ end


local function SocketConnect(host, port)
if client then
client:close()
client = nil
saurtron marked this conversation as resolved.
Show resolved Hide resolved
end
client=socket.tcp()
client:settimeout(0)
res, err = client:connect(host, port)
if not res and not res=="timeout" then
if not res and err ~= "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 @@ -652,8 +658,10 @@ 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 not res=="timeout" then Spring.Echo("Lobby:Info Error", res, err) else client:send(message) end
if client ~= nil then client:close() end
if not res and err ~= "timeout" then Spring.Echo("Lobby:Info Error", res, err) else client:send(message) end
if client then
client:close()
end
end
end

Expand Down Expand Up @@ -735,6 +743,7 @@ function widget:Initialize()
isConnected = true
if client ~= nil then
client:close()
client = nil
end
ACTIVE = false
-- disconnect
Expand Down
7 changes: 6 additions & 1 deletion libs/spring-launcher/luaui/widgets/api_spring_launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ 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 not res == "timeout" then
if not res and err ~= "timeout" then
client:close()
client = nil
widgetHandler:RemoveWidget(self)
Spring.Log(LOG_SECTION, LOG.ERROR, "Error in connect launcher: " .. err)
return false
Expand Down