Skip to content

Commit

Permalink
add skynet.context_ptr() & noneblocking socket.close
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Jul 29, 2013
1 parent ba22224 commit 1b4b46d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lualib-src/lua-skynet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -465,6 +473,7 @@ luaopen_skynet_c(lua_State *L) {
{ "error", _error },
{ "tostring", _tostring },
{ "harbor", _harbor },
{ "context", _context },
{ NULL, NULL },
};

Expand Down
4 changes: 4 additions & 0 deletions lualib/skynet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,8 @@ function skynet.abort()
c.command("ABORT")
end

function skynet.context_ptr()
return c.context()
end

return skynet
4 changes: 4 additions & 0 deletions service-src/service_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 1b4b46d

Please sign in to comment.