|
16 | 16 | brave.on('loadProtoBySocket', function (param)
|
17 | 17 | local jsonrpc = require 'jsonrpc'
|
18 | 18 | local socket = require 'bee.socket'
|
| 19 | + local util = require 'utility' |
19 | 20 | local rfd = socket.fd(param.rfd)
|
20 | 21 | local wfd = socket.fd(param.wfd)
|
21 | 22 | local buf = ''
|
@@ -44,16 +45,28 @@ brave.on('loadProtoBySocket', function (param)
|
44 | 45 | end)
|
45 | 46 |
|
46 | 47 | 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 |
51 | 59 | 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) |
55 | 68 | end
|
56 |
| - coroutine.resume(parser) |
| 69 | + ::continue:: |
57 | 70 | end
|
58 | 71 | end)
|
59 | 72 |
|
|
0 commit comments