Skip to content

Commit 9aaec3d

Browse files
committed
整理代码
1 parent 5445c10 commit 9aaec3d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

websocket_thread.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local debugPrint=false
22

3-
local confCHN,sendCHN,readCHN
3+
local zPath,confCHN,sendCHN,readCHN=...
44

55
local connTimeout,pongTimeout=16,2.6
66
local sleepInterval,pingInterval=6,0.26
@@ -14,9 +14,9 @@ local CHN_push,CHN_pop,CHN_peek=confCHN.push,confCHN.pop,confCHN.peek
1414

1515
local SOCK=require'socket'.tcp()
1616
---@type Zenitha.Json
17-
local JSON=require((...)..'json')
17+
local JSON=require(zPath..'json')
1818

19-
do-- Connect
19+
do -- Connect
2020
local conf=CHN_demand(confCHN)
2121
local host=conf.host
2222
local port=conf.port
@@ -38,7 +38,7 @@ do-- Connect
3838
'Connection: Upgrade\r\n'..
3939
'Upgrade: websocket\r\n'..
4040
'Sec-WebSocket-Version: 13\r\n'..
41-
'Sec-WebSocket-Key: osT3F7mvlojIvf3/8uIsJQ==\r\n'..-- secKey
41+
'Sec-WebSocket-Key: osT3F7mvlojIvf3/8uIsJQ==\r\n'.. -- secKey
4242
headers..
4343
'\r\n'
4444
if debugPrint then
@@ -151,7 +151,7 @@ end
151151
local readThread=coroutine.wrap(function()
152152
local res,err
153153
local op,fin
154-
local lBuffer=""-- Long multi-pack buffer
154+
local lBuffer="" -- Long multi-pack buffer
155155
while true do
156156
-- Byte 0-1
157157
res,err=_receive(SOCK,2)
@@ -177,22 +177,22 @@ local readThread=coroutine.wrap(function()
177177
assert(res,err)
178178

179179
-- React
180-
if op==8 then-- 8=close
181-
CHN_push(readCHN,8)-- close
180+
if op==8 then -- 8=close
181+
CHN_push(readCHN,8) -- close
182182
if type(res)=='string' then
183-
CHN_push(readCHN,res:sub(3))--[Warning] 2 bytes close code at start so :sub(3)
183+
CHN_push(readCHN,res:sub(3)) --[Warning] 2 bytes close code at start so :sub(3)
184184
else
185185
CHN_push(readCHN,"WS closed")
186186
end
187187
error("Server Close")
188-
elseif op==0 then-- 0=continue
188+
elseif op==0 then -- 0=continue
189189
lBuffer=lBuffer..res
190190
if fin then
191191
CHN_push(readCHN,lBuffer)
192192
if debugPrint then print('mMes<',lBuffer) end
193193
lBuffer=""
194194
end
195-
elseif op==9 then-- 9=ping
195+
elseif op==9 then -- 9=ping
196196
_send(10,res)
197197
else
198198
CHN_push(readCHN,op)
@@ -210,7 +210,7 @@ end)
210210

211211
local suc,err
212212

213-
while true do-- Running
213+
while true do -- Running
214214
while CHN_peek(confCHN) do
215215
local c=CHN_pop(confCHN)
216216
local n=c[1]
@@ -239,6 +239,6 @@ while true do-- Running
239239
end
240240

241241
SOCK:close()
242-
CHN_push(readCHN,8)-- close
242+
CHN_push(readCHN,8) -- close
243243
CHN_push(readCHN,err or "Disconnected")
244244
error()

0 commit comments

Comments
 (0)