From 1b4b46d2714f4b1362b71ce1fc429db8913c190c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Mon, 29 Jul 2013 21:24:57 +0800 Subject: [PATCH] add skynet.context_ptr() & noneblocking socket.close --- lualib-src/lua-skynet.c | 9 +++++++++ lualib/skynet.lua | 4 ++++ service-src/service_socket.c | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/lualib-src/lua-skynet.c b/lualib-src/lua-skynet.c index 4e58590a..6ff837a2 100644 --- a/lualib-src/lua-skynet.c +++ b/lualib-src/lua-skynet.c @@ -385,6 +385,14 @@ _harbor(lua_State *L) { return 2; } +static int +_context(lua_State *L) { + struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); + lua_pushlightuserdata(L, context); + + return 1; +} + // trace api static int _trace_new(lua_State *L) { @@ -465,6 +473,7 @@ luaopen_skynet_c(lua_State *L) { { "error", _error }, { "tostring", _tostring }, { "harbor", _harbor }, + { "context", _context }, { NULL, NULL }, }; diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 62368228..108fd743 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -615,4 +615,8 @@ function skynet.abort() c.command("ABORT") end +function skynet.context_ptr() + return c.context() +end + return skynet diff --git a/service-src/service_socket.c b/service-src/service_socket.c index 4483b7e2..f36e57b9 100644 --- a/service-src/service_socket.c +++ b/service-src/service_socket.c @@ -49,6 +49,10 @@ struct socket_pool { static void reply(struct skynet_context * ctx, uint32_t source, int session, char * cmd, int sz) { + if (session == 0) { + // don't reply when session == 0 + return; + } if (sz < 0) { sz = strlen(cmd); }