From c175d66e23bb7519925090276e0e8873e6684a9c Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 6 Jan 2016 16:55:15 +0800 Subject: [PATCH 01/12] remove unused function --- lualib/mysql.lua | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lualib/mysql.lua b/lualib/mysql.lua index c3573ae2..933e0643 100644 --- a/lualib/mysql.lua +++ b/lualib/mysql.lua @@ -125,19 +125,6 @@ local function _compose_packet(self, req, size) return packet end - -local function _send_packet(self, req, size) - local sock = self.sock - - self.packet_no = self.packet_no + 1 - - - local packet = _set_byte3(size) .. strchar(self.packet_no) .. req - - return socket.write(self.sock,packet) -end - - local function _recv_packet(self,sock) From d7a76c7c7272b1280bd37916c2d044e36d246991 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Thu, 7 Jan 2016 16:01:17 +0800 Subject: [PATCH 02/12] If no content-length, read all. see issue #431 --- lualib/http/httpc.lua | 3 ++- lualib/http/sockethelper.lua | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lualib/http/httpc.lua b/lualib/http/httpc.lua index 09ac9288..68d3ce9c 100644 --- a/lualib/http/httpc.lua +++ b/lualib/http/httpc.lua @@ -72,7 +72,8 @@ local function request(fd, method, host, url, recvheader, header, content) body = body .. padding end else - body = nil + -- no content-length, read all + body = body .. socket.readall(fd) end end diff --git a/lualib/http/sockethelper.lua b/lualib/http/sockethelper.lua index febe4cea..cac3130d 100644 --- a/lualib/http/sockethelper.lua +++ b/lualib/http/sockethelper.lua @@ -19,6 +19,8 @@ function sockethelper.readfunc(fd) end end +sockethelper.readall = socket.readall + function sockethelper.writefunc(fd) return function(content) local ok = writebytes(fd, content) From 24f9ee1560f588812e3749ed375fdd1846c058bb Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Fri, 8 Jan 2016 18:34:45 +0800 Subject: [PATCH 03/12] work thread for channel may not create if you never connect --- lualib/socketchannel.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lualib/socketchannel.lua b/lualib/socketchannel.lua index cf918645..350423a4 100644 --- a/lualib/socketchannel.lua +++ b/lualib/socketchannel.lua @@ -411,10 +411,10 @@ end function channel:close() if not self.__closed then - local thread = assert(self.__dispatch_thread) + local thread = self.__dispatch_thread self.__closed = true close_channel_socket(self) - if not self.__response and self.__dispatch_thread == thread then + if not self.__response and self.__dispatch_thread == thread and thread then -- dispatch by order, send close signal to dispatch thread push_response(self, true, false) -- (true, false) is close signal end From 532f47444bbd8e92a5c30611dbba4fdde610a293 Mon Sep 17 00:00:00 2001 From: snail Date: Mon, 11 Jan 2016 15:06:51 +0800 Subject: [PATCH 04/12] reduce needless 'add_string' call Short strings in lua proto are reused most of the time. The string in SSM may be added by one service and used by other service, there is no need to call `add_string`,which will call 'new_string' first. --- 3rd/lua/lstring.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/3rd/lua/lstring.c b/3rd/lua/lstring.c index 79a232df..71443a91 100644 --- a/3rd/lua/lstring.c +++ b/3rd/lua/lstring.c @@ -419,8 +419,11 @@ luaS_clonestring(lua_State *L, TString *ts) { result = query_ptr(ts); if (result) return result; - // ts is not in SSM, so recalc hash, and add it to SSM h = luaS_hash(str, l, 0); + result = query_string(h, str, l); + if (result) + return result; + // ts is not in SSM, so recalc hash, and add it to SSM return add_string(h, str, l); } From 7f45b3fd10cb2f2fb39d7c07309a4ce585828002 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 13 Jan 2016 13:13:31 +0800 Subject: [PATCH 05/12] correct maxsz --- lualib-src/sproto/lsproto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lualib-src/sproto/lsproto.c b/lualib-src/sproto/lsproto.c index d1cca74e..22e53189 100644 --- a/lualib-src/sproto/lsproto.c +++ b/lualib-src/sproto/lsproto.c @@ -469,7 +469,7 @@ lpack(lua_State *L) { size_t sz=0; const void * buffer = getbuffer(L, 1, &sz); // the worst-case space overhead of packing is 2 bytes per 2 KiB of input (256 words = 2KiB). - size_t maxsz = (sz + 2047) / 2048 * 2 + sz; + size_t maxsz = (sz + 2047) / 2048 * 2 + sz + 2; void * output = lua_touserdata(L, lua_upvalueindex(1)); int bytes; int osz = lua_tointeger(L, lua_upvalueindex(2)); From 9747cf9aeebb821acb6e755e5fc01f0d5bf8a257 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Tue, 19 Jan 2016 16:16:18 +0800 Subject: [PATCH 06/12] don't assert here --- service-src/service_harbor.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/service-src/service_harbor.c b/service-src/service_harbor.c index 70abe82b..d01b33a4 100644 --- a/service-src/service_harbor.c +++ b/service-src/service_harbor.c @@ -346,8 +346,14 @@ dispatch_name_queue(struct harbor *h, struct keyvalue * node) { struct harbor_msg_queue * queue = node->queue; uint32_t handle = node->value; int harbor_id = handle >> HANDLE_REMOTE_SHIFT; - assert(harbor_id != 0); struct skynet_context * context = h->ctx; + if (harbor_id == 0) { + char tmp [GLOBALNAME_LENGTH+1]; + memcpy(tmp, node->key, GLOBALNAME_LENGTH); + tmp[GLOBALNAME_LENGTH] = '\0'; + skynet_error(context, "Invalid name (%s) handle :%08x",tmp,handle); + return; + } struct slave *s = &h->s[harbor_id]; int fd = s->fd; if (fd == 0) { From 1da92850a0dd546963561c3e61383acead813a28 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Tue, 19 Jan 2016 17:14:52 +0800 Subject: [PATCH 07/12] bugfix: dispatch local global message queue --- service-src/service_harbor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/service-src/service_harbor.c b/service-src/service_harbor.c index d01b33a4..3e722fa9 100644 --- a/service-src/service_harbor.c +++ b/service-src/service_harbor.c @@ -347,13 +347,6 @@ dispatch_name_queue(struct harbor *h, struct keyvalue * node) { uint32_t handle = node->value; int harbor_id = handle >> HANDLE_REMOTE_SHIFT; struct skynet_context * context = h->ctx; - if (harbor_id == 0) { - char tmp [GLOBALNAME_LENGTH+1]; - memcpy(tmp, node->key, GLOBALNAME_LENGTH); - tmp[GLOBALNAME_LENGTH] = '\0'; - skynet_error(context, "Invalid name (%s) handle :%08x",tmp,handle); - return; - } struct slave *s = &h->s[harbor_id]; int fd = s->fd; if (fd == 0) { @@ -372,6 +365,16 @@ dispatch_name_queue(struct harbor *h, struct keyvalue * node) { push_queue_msg(s->queue, m); } } + if (harbor_id == (h->slave >> HANDLE_REMOTE_SHIFT)) { + // the harbor_id is local + struct harbor_msg * m; + while ((m = pop_queue(s->queue)) != NULL) { + int type = m->header.destination >> HANDLE_REMOTE_SHIFT; + skynet_send(context, m->header.source, handle , type | PTYPE_TAG_DONTCOPY, m->header.session, m->buffer, m->size); + } + release_queue(s->queue); + s->queue = NULL; + } } return; } From 96e0a4e3cceac4f7268775ace7d9f46ea313d228 Mon Sep 17 00:00:00 2001 From: David Feng Date: Wed, 20 Jan 2016 19:24:58 +0800 Subject: [PATCH 08/12] change socket.write to socketdriver.send MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这样改过之后可以直接调试使用了gate服务的模块。 因为gate服务注册了socket类型的消息,所以不能和socket模块一块使用;而debug模块只使用到了socket模块的write函数,所以这样修改后对debug的功能并没有影响,但改过之后就可以调试gate服务了。 --- lualib/skynet/remotedebug.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lualib/skynet/remotedebug.lua b/lualib/skynet/remotedebug.lua index 1fa04155..5c1ad9b2 100644 --- a/lualib/skynet/remotedebug.lua +++ b/lualib/skynet/remotedebug.lua @@ -1,6 +1,6 @@ local skynet = require "skynet" local debugchannel = require "debugchannel" -local socket = require "socket" +local socketdriver = require "socketdriver" local injectrun = require "skynet.injectcode" local table = table local debug = debug @@ -56,7 +56,7 @@ local function gen_print(fd) tmp[i] = tostring(tmp[i]) end table.insert(tmp, "\n") - socket.write(fd, table.concat(tmp, "\t")) + socketdriver.send(fd, table.concat(tmp, "\t")) end end @@ -208,7 +208,7 @@ local function hook_dispatch(dispatcher, resp, fd, channel) local function debug_hook() while true do if newline then - socket.write(fd, prompt) + socketdriver.send(fd, prompt) newline = false end local cmd = channel:read() From 77f407119112d0bd404cdd24a6262f50795209ee Mon Sep 17 00:00:00 2001 From: David Feng Date: Mon, 18 Jan 2016 11:56:25 +0800 Subject: [PATCH 09/12] remove unused local variables --- lualib/skynet/debug.lua | 2 -- lualib/snax/hotfix.lua | 3 --- 2 files changed, 5 deletions(-) diff --git a/lualib/skynet/debug.lua b/lualib/skynet/debug.lua index 635bdb31..79c51ad1 100644 --- a/lualib/skynet/debug.lua +++ b/lualib/skynet/debug.lua @@ -1,6 +1,4 @@ -local io = io local table = table -local debug = debug return function (skynet, export) diff --git a/lualib/snax/hotfix.lua b/lualib/snax/hotfix.lua index 3a6e4e3e..f56a5072 100644 --- a/lualib/snax/hotfix.lua +++ b/lualib/snax/hotfix.lua @@ -1,7 +1,4 @@ local si = require "snax.interface" -local io = io - -local hotfix = {} local function envid(f) local i = 1 From d34b092cdd3bf0cfe707c0dcc5829eb09b2a4f99 Mon Sep 17 00:00:00 2001 From: David Feng Date: Fri, 22 Jan 2016 10:28:03 +0800 Subject: [PATCH 10/12] =?UTF-8?q?remotedebug.lua=20call=20skynet.timeout()?= =?UTF-8?q?=20only=20in=20debug=20hook=20=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E5=9C=A8debug=E7=BB=93=E6=9D=9F=E5=90=8E=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lualib/skynet/remotedebug.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lualib/skynet/remotedebug.lua b/lualib/skynet/remotedebug.lua index 1fa04155..ccb4f8f9 100644 --- a/lualib/skynet/remotedebug.lua +++ b/lualib/skynet/remotedebug.lua @@ -244,7 +244,9 @@ local function hook_dispatch(dispatcher, resp, fd, channel) func = replace_upvalue(dispatcher, HOOK_FUNC, hook) if func then local function idle() - skynet.timeout(10,idle) -- idle every 0.1s + if raw_dispatcher then + skynet.timeout(10,idle) -- idle every 0.1s + end end skynet.timeout(0, idle) end From d982009260a16403f33cace61c2178b67bea6dc2 Mon Sep 17 00:00:00 2001 From: David Feng Date: Wed, 27 Jan 2016 10:35:40 +0800 Subject: [PATCH 11/12] fix --- lualib/skynet/remotedebug.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lualib/skynet/remotedebug.lua b/lualib/skynet/remotedebug.lua index 7cfe19eb..72a06809 100644 --- a/lualib/skynet/remotedebug.lua +++ b/lualib/skynet/remotedebug.lua @@ -140,10 +140,13 @@ end local function watch_proto(protoname, cond) local proto = assert(replace_upvalue(skynet.register_protocol, "proto"), "Can't find proto table") local p = proto[protoname] - local dispatch = p.dispatch_origin or p.dispatch - if p == nil or dispatch == nil then + if p == nil then return "No " .. protoname end + local dispatch = p.dispatch_origin or p.dispatch + if dispatch == nil then + return "No dispatch" + end p.dispatch_origin = dispatch p.dispatch = function(...) if not cond or cond(...) then From ea8557296b63e80c0cedf7635bdc600da4750ee4 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Sat, 13 Feb 2016 19:20:07 +0800 Subject: [PATCH 12/12] fix issue #450 --- lualib-src/lua-crypt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lualib-src/lua-crypt.c b/lualib-src/lua-crypt.c index 405679a9..5322b2d6 100644 --- a/lualib-src/lua-crypt.c +++ b/lualib-src/lua-crypt.c @@ -885,7 +885,12 @@ int lhmac_sha1(lua_State *L); int luaopen_crypt(lua_State *L) { luaL_checkversion(L); - srandom(time(NULL)); + static int init = 0; + if (!init) { + // Don't need call srandom more than once. + init = 1 ; + srandom(time(NULL)); + } luaL_Reg l[] = { { "hashkey", lhashkey }, { "randomkey", lrandomkey },