socket channel order mode support padding, see issue #835

This commit is contained in:
Cloud Wu
2018-05-09 17:38:32 +08:00
parent 5f8e5f9be5
commit 4dd622e180

View File

@@ -153,6 +153,25 @@ local function push_response(self, response, co)
end end
end end
local function get_response(func, sock)
local result_ok, result_data, padding = func(sock)
if result_ok and padding then
local result = { result_data }
local index = 2
repeat
result_ok, result_data, padding = func(sock)
if not result_ok then
return result_ok, result_data
end
result[index] = result_data
index = index + 1
until not padding
return true, result
else
return result_ok, result_data
end
end
local function dispatch_by_order(self) local function dispatch_by_order(self)
while self.__sock do while self.__sock do
local func, co = pop_response(self) local func, co = pop_response(self)
@@ -161,23 +180,15 @@ local function dispatch_by_order(self)
wakeup_all(self, "channel_closed") wakeup_all(self, "channel_closed")
break break
end end
local ok, result_ok, result_data, padding = pcall(func, self.__sock) local ok, result_ok, result_data = pcall(get_response, func, self.__sock)
if ok then if ok then
if padding and result_ok then self.__result[co] = result_ok
-- if padding is true, wait for next result_data if result_ok and self.__result_data[co] then
-- self.__result_data[co] is a table table.insert(self.__result_data[co], result_data)
local result = self.__result_data[co] or {}
self.__result_data[co] = result
table.insert(result, result_data)
else else
self.__result[co] = result_ok self.__result_data[co] = result_data
if result_ok and self.__result_data[co] then
table.insert(self.__result_data[co], result_data)
else
self.__result_data[co] = result_data
end
skynet.wakeup(co)
end end
skynet.wakeup(co)
else else
close_channel_socket(self) close_channel_socket(self)
local errmsg local errmsg