diff --git a/Makefile b/Makefile index 78718ae9..9c352e38 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ all : \ lualib/int64.so \ service/master.so \ service/multicast.so \ + service/tunnel.so \ service/harbor.so skynet : \ @@ -35,6 +36,9 @@ skynet : \ skynet-src/skynet_env.c gcc $(CFLAGS) -Wl,-E -o $@ $^ -Iskynet-src -lpthread -ldl -lrt -Wl,-E -llua -lm +service/tunnel.so : service-src/service_tunnel.c + gcc $(CFLAGS) $(SHARED) $^ -o $@ -Iskynet-src + service/multicast.so : service-src/service_multicast.c gcc $(CFLAGS) $(SHARED) $^ -o $@ -Iskynet-src diff --git a/lualib-src/lua-skynet.c b/lualib-src/lua-skynet.c index 6b6f767d..d19c8181 100644 --- a/lualib-src/lua-skynet.c +++ b/lualib-src/lua-skynet.c @@ -234,6 +234,18 @@ _tostring(lua_State *L) { return 1; } +static int +_harbor(lua_State *L) { + struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); + uint32_t handle = luaL_checkunsigned(L,1); + int harbor = 0; + int remote = skynet_isremote(context, handle, &harbor); + lua_pushinteger(L,harbor); + lua_pushboolean(L, remote); + + return 2; +} + // define in lua-remoteobj.c int remoteobj_init(lua_State *L); @@ -255,6 +267,7 @@ luaopen_skynet_c(lua_State *L) { { "callback" , _callback }, { "error", _error }, { "tostring", _tostring }, + { "harbor", _harbor }, { NULL, NULL }, }; diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 3a93e311..496b0daa 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -255,6 +255,10 @@ function skynet.address(addr) return string.format(":%x",addr) end +function skynet.harbor(addr) + return c.harbor(addr) +end + ------ remote object -------- do diff --git a/skynet-src/skynet.h b/skynet-src/skynet.h index 48c2fffa..00bda87c 100644 --- a/skynet-src/skynet.h +++ b/skynet-src/skynet.h @@ -18,6 +18,7 @@ int skynet_send(struct skynet_context * context, uint32_t source, uint32_t desti int skynet_sendname(struct skynet_context * context, const char * destination , int session, void * msg, size_t sz, int flags); void skynet_forward(struct skynet_context *, uint32_t destination); +int skynet_isremote(struct skynet_context *, uint32_t handle, int * harbor); typedef int (*skynet_cb)(struct skynet_context * context, void *ud, int session, uint32_t source , const void * msg, size_t sz); void skynet_callback(struct skynet_context * context, void *ud, skynet_cb cb); diff --git a/skynet-src/skynet_server.c b/skynet-src/skynet_server.c index dc801c64..61d2d5af 100644 --- a/skynet-src/skynet_server.c +++ b/skynet-src/skynet_server.c @@ -153,6 +153,15 @@ skynet_context_push(uint32_t handle, struct skynet_message *message) { return 0; } +int +skynet_isremote(struct skynet_context * ctx, uint32_t handle, int * harbor) { + int ret = skynet_harbor_message_isremote(handle); + if (harbor) { + *harbor = (int)(handle >> HANDLE_REMOTE_SHIFT); + } + return ret; +} + static int _forwarding(struct skynet_context *ctx, struct skynet_message *msg) { if (ctx->forward) {