修复ws库分包消息解析错误

This commit is contained in:
MrZ626
2021-04-09 19:35:18 +08:00
parent 48ce3a3d8f
commit e46a28681d

View File

@@ -110,6 +110,8 @@ local _send do
end end
end end
end end
local res,err
local op,fin
local length local length
local lBuffer=""--Long multi-data buffer local lBuffer=""--Long multi-data buffer
local UFF--Un-finished-frame mode local UFF--Un-finished-frame mode
@@ -125,25 +127,13 @@ while true do--Running
--Read --Read
while true do while true do
if UFF then--UNF process if not UFF then--UNF process
local s,e,p=SOCK:receive(length)
if s then
sBuffer=sBuffer..s
UFF=false
elseif p then
sBuffer=sBuffer..p
length=length-#p
if length==0 then
UFF=false
end
end
else
--Byte 0-1 --Byte 0-1
local res,err=SOCK:receive(2) res,err=SOCK:receive(2)
if err then break end if err then break end
local op=band(byte(res,1),0x0f) op=band(byte(res,1),0x0f)
local fin=band(byte(res,1),0x80)==0x80 fin=band(byte(res,1),0x80)==0x80
--Calculating data length --Calculating data length
length=band(byte(res,2),0x7f) length=band(byte(res,2),0x7f)
@@ -171,6 +161,25 @@ while true do--Running
else else
res="" res=""
end end
else
local s,e,p=SOCK:receive(length)
if s then
]]..(debug==1 and""or"--")..[[print(("%s<%d>:%s"):format(threadName,length,s))
sBuffer=sBuffer..s
length=length-#s
elseif p then
]]..(debug==1 and""or"--")..[[print(("%s<%d>:%s"):format(threadName,length,p))
sBuffer=sBuffer..p
length=length-#p
end
if length==0 then
res,sBuffer=sBuffer,""
UFF=false
else
break
end
end
]]..(debug==1 and""or"--")..[[print(("%s<[%d]>:%s"):format(threadName,#res,res))
--React --React
if op==8 then--8=close if op==8 then--8=close
@@ -204,7 +213,6 @@ while true do--Running
end end
end end
end end
end
]] ]]
local timer=love.timer.getTime local timer=love.timer.getTime