ws模块支持设定连接超时时间
This commit is contained in:
@@ -23,8 +23,9 @@ do--Connect
|
|||||||
local port=sendCHN:demand()
|
local port=sendCHN:demand()
|
||||||
local path=sendCHN:demand()
|
local path=sendCHN:demand()
|
||||||
local body=sendCHN:demand()
|
local body=sendCHN:demand()
|
||||||
|
local timeout=sendCHN:demand()
|
||||||
|
|
||||||
SOCK:settimeout(2.6)
|
SOCK:settimeout(timeout)
|
||||||
local res,err=SOCK:connect(host,port)
|
local res,err=SOCK:connect(host,port)
|
||||||
if err then readCHN:push(err)return end
|
if err then readCHN:push(err)return end
|
||||||
|
|
||||||
@@ -232,7 +233,7 @@ local wsList=setmetatable({},{
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
function WS.connect(name,subPath,body)
|
function WS.connect(name,subPath,body,timeout)
|
||||||
local ws={
|
local ws={
|
||||||
real=true,
|
real=true,
|
||||||
thread=love.thread.newThread(wsThread),
|
thread=love.thread.newThread(wsThread),
|
||||||
@@ -242,7 +243,7 @@ function WS.connect(name,subPath,body)
|
|||||||
lastPingTime=0,
|
lastPingTime=0,
|
||||||
lastPongTime=timer(),
|
lastPongTime=timer(),
|
||||||
pingInterval=12,
|
pingInterval=12,
|
||||||
status='connecting',--connecting, running, dead
|
status='connecting',--'connecting', 'running', 'dead'
|
||||||
sendTimer=0,
|
sendTimer=0,
|
||||||
alertTimer=0,
|
alertTimer=0,
|
||||||
pongTimer=0,
|
pongTimer=0,
|
||||||
@@ -253,6 +254,7 @@ function WS.connect(name,subPath,body)
|
|||||||
ws.sendCHN:push(port)
|
ws.sendCHN:push(port)
|
||||||
ws.sendCHN:push(path..subPath)
|
ws.sendCHN:push(path..subPath)
|
||||||
ws.sendCHN:push(body or"")
|
ws.sendCHN:push(body or"")
|
||||||
|
ws.sendCHN:push(timeout or 2.6)
|
||||||
end
|
end
|
||||||
|
|
||||||
function WS.status(name)
|
function WS.status(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user