|
|
@@ -591,49 +591,48 @@ local function main()
|
|
|
end
|
|
|
|
|
|
-- WebSocket connection and keepalive
|
|
|
- while true do
|
|
|
- log("info", "Connecting to server...")
|
|
|
+ while true do
|
|
|
+ log("info", "Connecting to server...")
|
|
|
|
|
|
- if ws_client then
|
|
|
- sock = ws.connect(cfg.url)
|
|
|
- end
|
|
|
+ if ws_client then
|
|
|
+ sock = ws.connect(cfg.url)
|
|
|
+ end
|
|
|
|
|
|
- if sock then
|
|
|
- log("info", "Connected!")
|
|
|
- retries = 0
|
|
|
+ if sock then
|
|
|
+ log("info", "Connected!")
|
|
|
+ retries = 0
|
|
|
|
|
|
- -- Flush buffer
|
|
|
+ -- Flush buffer
|
|
|
+ buffer.flush(function(data)
|
|
|
+ return ws.send(sock, data)
|
|
|
+ end)
|
|
|
+
|
|
|
+ -- Keep alive loop
|
|
|
+ local loop_count = 0
|
|
|
+ while ws.connected(sock) and loop_count < (cfg.ping_interval / 5) do
|
|
|
+ luv.sleep(5000)
|
|
|
+ loop_count = loop_count + 1
|
|
|
+
|
|
|
+ -- Periodic flush
|
|
|
buffer.flush(function(data)
|
|
|
return ws.send(sock, data)
|
|
|
end)
|
|
|
-
|
|
|
- -- Keep alive loop
|
|
|
- local loop_count = 0
|
|
|
- while ws.connected(sock) and loop_count < (cfg.ping_interval / 5) do
|
|
|
- luv.sleep(5000)
|
|
|
- loop_count = loop_count + 1
|
|
|
-
|
|
|
- -- Periodic flush
|
|
|
- buffer.flush(function(data)
|
|
|
- return ws.send(sock, data)
|
|
|
- end)
|
|
|
- end
|
|
|
- else
|
|
|
- log("err", "Connection failed")
|
|
|
- retries = retries + 1
|
|
|
end
|
|
|
+ else
|
|
|
+ log("err", "Connection failed")
|
|
|
+ retries = retries + 1
|
|
|
+ end
|
|
|
|
|
|
- -- Cleanup and reconnect
|
|
|
- ws.close(sock)
|
|
|
- sock = nil
|
|
|
+ -- Cleanup and reconnect
|
|
|
+ ws.close(sock)
|
|
|
+ sock = nil
|
|
|
|
|
|
- -- Save buffer on disconnect
|
|
|
- buffer.save()
|
|
|
+ -- Save buffer on disconnect
|
|
|
+ buffer.save()
|
|
|
|
|
|
- -- Delay before reconnect
|
|
|
- luv.sleep(cfg.reconnect_delay * 1000)
|
|
|
- end
|
|
|
- end)
|
|
|
+ -- Delay before reconnect
|
|
|
+ luv.sleep(cfg.reconnect_delay * 1000)
|
|
|
+ end
|
|
|
else
|
|
|
-- Fallback: sequential mode
|
|
|
while true do
|