summaryrefslogtreecommitdiff
path: root/script/brave
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-05-23 15:50:48 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-05-23 15:50:48 +0800
commite3784c96a618a8dfa34a4f0fc622c5d2397544b1 (patch)
tree81151407bedf5ef1be986ed9a36210ca87301293 /script/brave
parent7aac1748434eda3726d1ed001edd1327c3973e0b (diff)
downloadlua-language-server-e3784c96a618a8dfa34a4f0fc622c5d2397544b1.zip
cleanup
Diffstat (limited to 'script/brave')
-rw-r--r--script/brave/work.lua29
1 files changed, 21 insertions, 8 deletions
diff --git a/script/brave/work.lua b/script/brave/work.lua
index b3e79272..9eb756eb 100644
--- a/script/brave/work.lua
+++ b/script/brave/work.lua
@@ -16,6 +16,7 @@ end)
brave.on('loadProtoBySocket', function (param)
local jsonrpc = require 'jsonrpc'
local socket = require 'bee.socket'
+ local util = require 'utility'
local rfd = socket.fd(param.rfd)
local wfd = socket.fd(param.wfd)
local buf = ''
@@ -44,16 +45,28 @@ brave.on('loadProtoBySocket', function (param)
end)
while true do
- socket.select({rfd, wfd}, nil, 10)
- local needSend = wfd:recv()
- if needSend then
- rfd:send(needSend)
+ local rd = socket.select({rfd, wfd}, nil, 10)
+ if not rd or #rd == 0 then
+ goto continue
+ end
+ if util.arrayHas(rd, wfd) then
+ local needSend = wfd:recv()
+ if needSend then
+ rfd:send(needSend)
+ elseif needSend == nil then
+ error('socket closed!')
+ end
end
- local recved = rfd:recv()
- if recved then
- buf = buf .. recved
+ if util.arrayHas(rd, rfd) then
+ local recved = rfd:recv()
+ if recved then
+ buf = buf .. recved
+ elseif recved == nil then
+ error('socket closed!')
+ end
+ coroutine.resume(parser)
end
- coroutine.resume(parser)
+ ::continue::
end
end)