From 6df72e58420a5688f80f12bef359bf2606473506 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Fri, 14 Nov 2014 16:13:48 +0800 Subject: [PATCH] remove snax queue mode --- service/snaxd.lua | 69 ++------------------------------------------- test/pingserver.lua | 3 -- 2 files changed, 3 insertions(+), 69 deletions(-) diff --git a/service/snaxd.lua b/service/snaxd.lua index 0ff9baa0..8be269e9 100644 --- a/service/snaxd.lua +++ b/service/snaxd.lua @@ -12,10 +12,6 @@ package.path = snax_path .. "?.lua;" .. package.path SERVICE_NAME = snax_name SERVICE_PATH = snax_path -local mode -local thread_id -local message_queue = {} -local init = false local profile_table = {} local function update_stat(name, ti) @@ -38,57 +34,6 @@ local function dispatch(f, ...) return skynet.pack(f(...)) end -local function message_dispatch() - while true do - if #message_queue==0 then - thread_id = coroutine.running() - skynet.wait() - else - local msg = table.remove(message_queue,1) - local method = msg.method - local f = method[4] - if f then - if method[2] == "accept" then - -- no return - profile.start() - local ok, data = xpcall(f, traceback, table.unpack(msg)) - local ti = profile.stop() - update_stat(method[3], ti) - if not ok then - print(string.format("Error on [:%x] to [:%x] %s", msg.source, skynet.self(), tostring(data))) - end - else - profile.start() - local ok, data, size = xpcall(dispatch, traceback, f, table.unpack(msg)) - local ti = profile.stop() - update_stat(method[3], ti) - if ok then - -- skynet.PTYPE_RESPONSE == 1 - c.send(msg.source, 1, msg.session, data, size) - if method[2] == "system" then - init = false - skynet.exit() - break - end - else - -- Can't throw error, so print it directly - print(string.format("Error on [:%x] to [:%x] %s", msg.source, skynet.self(), tostring(data))) - c.send(msg.source, skynet.PTYPE_ERROR, msg.session, "") - end - end - end - end - end -end - -local function queue( session, source, method, ...) - table.insert(message_queue, {session = session, source = source, method = method, ... }) - if thread_id then - skynet.wakeup(thread_id) - thread_id = nil - end -end - local function return_f(f, ...) return skynet.ret(skynet.pack(f(...))) end @@ -109,6 +54,7 @@ end skynet.start(function() skynet.dispatch("snax", function ( session , source , id, ...) + local init = false local method = func[id] if method[2] == "system" then @@ -119,17 +65,12 @@ skynet.start(function() elseif command == "init" then assert(not init, "Already init") local initfunc = method[4] or function() end - mode = initfunc(...) - if mode == "queue" then - skynet.fork(message_dispatch) - end + initfunc(...) skynet.ret() skynet.info_func(function() return profile_table end) init = true - elseif mode == "queue" then - queue( session, source, method , ...) else assert(init, "Never init") assert(command == "exit") @@ -141,11 +82,7 @@ skynet.start(function() end else assert(init, "Init first") - if mode == "queue" then - queue(session, source, method , ...) - else - timing(method, ...) - end + timing(method, ...) end end) end) diff --git a/test/pingserver.lua b/test/pingserver.lua index 5c44a21a..65a25405 100644 --- a/test/pingserver.lua +++ b/test/pingserver.lua @@ -45,9 +45,6 @@ function init( ... ) print ("ping server start:", ...) -- init queue lock = queue() - --- You can return "queue" for queue service mode --- return "queue" end function exit(...)