Skip to content

Commit e3784c9

Browse files
committed
cleanup
1 parent 7aac174 commit e3784c9

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

script/brave/work.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ end)
1616
brave.on('loadProtoBySocket', function (param)
1717
local jsonrpc = require 'jsonrpc'
1818
local socket = require 'bee.socket'
19+
local util = require 'utility'
1920
local rfd = socket.fd(param.rfd)
2021
local wfd = socket.fd(param.wfd)
2122
local buf = ''
@@ -44,16 +45,28 @@ brave.on('loadProtoBySocket', function (param)
4445
end)
4546

4647
while true do
47-
socket.select({rfd, wfd}, nil, 10)
48-
local needSend = wfd:recv()
49-
if needSend then
50-
rfd:send(needSend)
48+
local rd = socket.select({rfd, wfd}, nil, 10)
49+
if not rd or #rd == 0 then
50+
goto continue
51+
end
52+
if util.arrayHas(rd, wfd) then
53+
local needSend = wfd:recv()
54+
if needSend then
55+
rfd:send(needSend)
56+
elseif needSend == nil then
57+
error('socket closed!')
58+
end
5159
end
52-
local recved = rfd:recv()
53-
if recved then
54-
buf = buf .. recved
60+
if util.arrayHas(rd, rfd) then
61+
local recved = rfd:recv()
62+
if recved then
63+
buf = buf .. recved
64+
elseif recved == nil then
65+
error('socket closed!')
66+
end
67+
coroutine.resume(parser)
5568
end
56-
coroutine.resume(parser)
69+
::continue::
5770
end
5871
end)
5972

0 commit comments

Comments
 (0)