From d3747e09567909eed1917c65b19eeef24315e3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 24 Sep 2019 15:57:07 +0800 Subject: =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=8D=8F=E8=AE=AE=E6=98=AF=E5=B8=B8?= =?UTF-8?q?=E9=A9=BB=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/brave/init.lua | 2 +- server-beta/src/proto/proto.lua | 11 +---------- server-beta/src/pub/init.lua | 9 +++++++++ server-beta/src/pub/pub.lua | 7 ++++--- server-beta/src/task.lua | 1 - 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/server-beta/src/brave/init.lua b/server-beta/src/brave/init.lua index 4616110f..0a2d2d25 100644 --- a/server-beta/src/brave/init.lua +++ b/server-beta/src/brave/init.lua @@ -9,7 +9,7 @@ brave.on('loadProto', function () while true do local proto = jsonrpc.decode(io.read, log.error) if proto then - return proto + brave.push('proto', proto) end end end) diff --git a/server-beta/src/proto/proto.lua b/server-beta/src/proto/proto.lua index cc9988a8..27ba68b8 100644 --- a/server-beta/src/proto/proto.lua +++ b/server-beta/src/proto/proto.lua @@ -112,16 +112,7 @@ function m.listen() subprocess.filemode(io.stdout, 'b') io.stdin:setvbuf 'no' io.stdout:setvbuf 'no' - task.create(function () - while true do - local proto = pub.task('loadProto') - if proto.method then - m.doMethod(proto) - else - m.doResponse(proto) - end - end - end) + pub.syncTask('loadProto') end return m diff --git a/server-beta/src/pub/init.lua b/server-beta/src/pub/init.lua index bf188e8d..65343d64 100644 --- a/server-beta/src/pub/init.lua +++ b/server-beta/src/pub/init.lua @@ -8,4 +8,13 @@ pub.on('mem', function (count, brave) brave.memory = count end) +pub.on('proto', function (params) + local proto = require 'proto' + if params.method then + proto.doMethod(params) + else + proto.doResponse(params) + end +end) + return pub diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua index df594707..4f245517 100644 --- a/server-beta/src/pub/pub.lua +++ b/server-beta/src/pub/pub.lua @@ -68,7 +68,7 @@ function m.pushTask(brave, info) end brave.taskpad:push(info.name, info.id, info.params) brave.taskMap[info.id] = info - log.info(('Push task %q to # %d, queue length %d'):format(info.name, brave.id, #m.taskQueue)) + log.info(('Push task %q(%d) to # %d, queue length %d'):format(info.name, info.id, brave.id, #m.taskQueue)) return true end @@ -80,6 +80,7 @@ function m.popTask(brave, id, result) return end brave.taskMap[id] = nil + log.info(('Pop task %q(%d) from # %d'):format(info.name, info.id, brave.id)) m.checkWaitingTask(brave) if not info.removed then info.removed = true @@ -123,7 +124,7 @@ function m.task(name, params) -- 当有勇者提交任务反馈后,尝试把按顺序将堆积任务 -- 交给该勇者 m.taskQueue[#m.taskQueue+1] = info - log.info(('Add task %q in queue, length %d.'):format(name, #m.taskQueue)) + log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) return task.wait(function (waker) info.callback = waker end) @@ -151,7 +152,7 @@ function m.syncTask(name, params, callback) -- 当有勇者提交任务反馈后,尝试把按顺序将堆积任务 -- 交给该勇者 m.taskQueue[#m.taskQueue+1] = info - log.info(('Add task %q in queue, length %d.'):format(name, #m.taskQueue)) + log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) return info end diff --git a/server-beta/src/task.lua b/server-beta/src/task.lua index ba7bec94..b4cf46d0 100644 --- a/server-beta/src/task.lua +++ b/server-beta/src/task.lua @@ -1,6 +1,5 @@ local timer = require 'timer' - ---@class task local m = {} m.type = 'task' -- cgit v1.2.3