Deal slightly better with unavailable server

This commit is contained in:
osmarks 2018-10-05 19:47:04 +01:00
parent c7f7b9d624
commit 2101cee26e
1 changed files with 9 additions and 2 deletions

View File

@ -33,9 +33,16 @@ local function value_in_table(t, v)
return false
end
local function send_raw(data)
local function send_raw(data, tries)
local tries = tries or 0
skynet.connect()
skynet.socket.send(json.encode(data))
local ok, err = pcall(skynet.socket.send, json.encode(data))
if not ok then
if tries > 0 then sleep(tries) end
if tries > 5 then error("Max reconnection attempts exceeded. " .. err) end
skynet.connect(true) -- attempt to force reconnect
send_raw(data, tries + 1)
end
end
-- Opens the given channel