add harbor query api

This commit is contained in:
云风
2012-08-30 17:52:44 +08:00
parent 4610781498
commit 161528e686
5 changed files with 31 additions and 0 deletions

View File

@@ -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

View File

@@ -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 },
};

View File

@@ -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

View File

@@ -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);

View File

@@ -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) {