From adc39705f392b0a7cc6cadd62b9bf6ed703699f3 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 12 Aug 2015 20:56:29 +0800 Subject: [PATCH] remove unused netpack c api --- lualib-src/lua-netpack.c | 53 --------------------------------------- lualib/snax/msgserver.lua | 10 ++++---- 2 files changed, 5 insertions(+), 58 deletions(-) diff --git a/lualib-src/lua-netpack.c b/lualib-src/lua-netpack.c index 0ec6f7e9..193938b1 100644 --- a/lualib-src/lua-netpack.c +++ b/lualib-src/lua-netpack.c @@ -448,57 +448,6 @@ lpack(lua_State *L) { return 2; } -static int -lpack_string(lua_State *L) { - uint8_t tmp[SMALLSTRING+2]; - size_t len; - uint8_t *buffer; - const char * ptr = tolstring(L, &len, 1); - if (len > 0x10000) { - return luaL_error(L, "Invalid size (too long) of data : %d", (int)len); - } - - if (len <= SMALLSTRING) { - buffer = tmp; - } else { - buffer = lua_newuserdata(L, len + 2); - } - - write_size(buffer, len); - memcpy(buffer+2, ptr, len); - lua_pushlstring(L, (const char *)buffer, len+2); - - return 1; -} - -static int -lpack_padding(lua_State *L) { - uint8_t tmp[SMALLSTRING+2]; - size_t content_sz; - uint8_t *buffer; - const char * ptr = tolstring(L, &content_sz, 2); - size_t cookie_sz = 0; - const char * cookie = luaL_checklstring(L,1,&cookie_sz); - size_t len = cookie_sz + content_sz; - - if (len > 0x10000) { - return luaL_error(L, "Invalid size (too long) of data : %d", (int)len); - } - - if (len <= SMALLSTRING) { - buffer = tmp; - } else { - buffer = lua_newuserdata(L, len + 2); - } - - write_size(buffer, len); - memcpy(buffer+2, ptr, content_sz); - memcpy(buffer+2+content_sz, cookie, cookie_sz); - lua_pushlstring(L, (const char *)buffer, len+2); - - return 1; -} - static int ltostring(lua_State *L) { void * ptr = lua_touserdata(L, 1); @@ -518,8 +467,6 @@ luaopen_netpack(lua_State *L) { luaL_Reg l[] = { { "pop", lpop }, { "pack", lpack }, - { "pack_string", lpack_string }, - { "pack_padding", lpack_padding }, { "clear", lclear }, { "tostring", ltostring }, { NULL, NULL }, diff --git a/lualib/snax/msgserver.lua b/lualib/snax/msgserver.lua index c480a8a6..765387cc 100644 --- a/lualib/snax/msgserver.lua +++ b/lualib/snax/msgserver.lua @@ -236,7 +236,7 @@ function server.start(conf) local function do_request(fd, message) local u = assert(connection[fd], "invalid fd") - local session = string.unpack("I4", message, -4) + local session = string.unpack(">I4", message, -4) message = message:sub(1,-5) local p = u.response[session] if p then @@ -257,16 +257,16 @@ function server.start(conf) p = { fd } u.response[session] = p local ok, result = pcall(conf.request_handler, u.username, message) - result = result or "" -- NOTICE: YIELD here, socket may close. + result = result or "" if not ok then skynet.error(result) - result = "\0" .. session + result = string.pack(">BI4", 0, session) else - result = result .. '\1' .. session + result = result .. string.pack(">BI4", 1, session) end - p[2] = netpack.pack_string(result) + p[2] = string.pack(">s2",result) p[3] = u.version p[4] = u.index else