|
|
|
@ -294,6 +294,7 @@ function itte.init_socket(name, svr)
|
|
|
|
|
cap_checked = false,
|
|
|
|
|
ns_checked = false,
|
|
|
|
|
authed = false,
|
|
|
|
|
ping_time = 0,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- Connect
|
|
|
|
@ -836,6 +837,7 @@ function itte.listen(name, str)
|
|
|
|
|
|
|
|
|
|
-- Respond to server ping
|
|
|
|
|
if util.is_substr(str, cxt.cmds.ping.check) then
|
|
|
|
|
cxt.state.ping_time = os.time()
|
|
|
|
|
util.debug(itte.config.debugs.listen[1], str, itte.config.debug)
|
|
|
|
|
itte.send_command(cxt.con, string.gsub(str, cxt.cmds.ping.check,
|
|
|
|
|
cxt.cmds.ping.resp))
|
|
|
|
@ -880,9 +882,17 @@ itte.docs.add_listener = [[ (context_table)
|
|
|
|
|
]]
|
|
|
|
|
function itte.add_listener(cxt)
|
|
|
|
|
local data, status = cxt.con:receive()
|
|
|
|
|
local delta = os.time() - cxt.state.ping_time
|
|
|
|
|
if data ~= nil then
|
|
|
|
|
itte.listen(cxt.name, data)
|
|
|
|
|
|
|
|
|
|
-- Send a pong every 120s in case the ping request was lost, e.g. during high
|
|
|
|
|
-- system load. Servers may send a ping request every ~90s. Disconnects from
|
|
|
|
|
-- ping timeouts occur at ~2m30s.
|
|
|
|
|
elseif (cxt.state.ping_time > 0) and (delta > 120) then
|
|
|
|
|
itte.send_command(cxt.con, cxt.cmds.ping.resp)
|
|
|
|
|
cxt.state.ping_time = os.time()
|
|
|
|
|
|
|
|
|
|
elseif status == "closed" then
|
|
|
|
|
itte.disconnect_server(cxt.name)
|
|
|
|
|
end
|
|
|
|
|