mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
Compare commits
44 Commits
v1.0.0-alp
...
v1.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2935ba3521 | ||
|
|
5c8ea6f09f | ||
|
|
c16ae57639 | ||
|
|
1c7d44fd4d | ||
|
|
e9cfdba22a | ||
|
|
704b016f2c | ||
|
|
3b48beb428 | ||
|
|
4cbead28d5 | ||
|
|
b3f966bcaa | ||
|
|
7b54e37d12 | ||
|
|
e87ac18b84 | ||
|
|
05af87ce8e | ||
|
|
0ee61de22c | ||
|
|
1da8a6b38d | ||
|
|
b2d8237363 | ||
|
|
39f9a96b6c | ||
|
|
588c4a3508 | ||
|
|
d6734890e0 | ||
|
|
4ebb139c2b | ||
|
|
20476d2280 | ||
|
|
3131bca6ef | ||
|
|
3f91484791 | ||
|
|
a0ecd51230 | ||
|
|
dba1db9cc4 | ||
|
|
538414408d | ||
|
|
4cf05fb2e7 | ||
|
|
d9ad981c8c | ||
|
|
21c941fe63 | ||
|
|
ea2437e138 | ||
|
|
86bbc9c701 | ||
|
|
95e1d9f45f | ||
|
|
55cf9375fc | ||
|
|
654f732cd5 | ||
|
|
d4023c8b63 | ||
|
|
375f8606b4 | ||
|
|
d17e6f59fe | ||
|
|
a77d36911d | ||
|
|
4352dc4047 | ||
|
|
172356be19 | ||
|
|
08dabd51c8 | ||
|
|
bd55a58515 | ||
|
|
b646a1b8a3 | ||
|
|
6b312fa09a | ||
|
|
dad66010cd |
@@ -44,6 +44,8 @@ LUAMOD_API int (luaopen_debug) (lua_State *L);
|
|||||||
#define LUA_LOADLIBNAME "package"
|
#define LUA_LOADLIBNAME "package"
|
||||||
LUAMOD_API int (luaopen_package) (lua_State *L);
|
LUAMOD_API int (luaopen_package) (lua_State *L);
|
||||||
|
|
||||||
|
#define LUA_CACHELIB
|
||||||
|
LUAMOD_API int (luaopen_cache) (lua_State *L);
|
||||||
|
|
||||||
/* open all previous libraries */
|
/* open all previous libraries */
|
||||||
LUALIB_API void (luaL_openlibs) (lua_State *L);
|
LUALIB_API void (luaL_openlibs) (lua_State *L);
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
v1.0.0-alpha9 (2015-8-10)
|
||||||
|
-----------
|
||||||
|
* Improve lua serialization , support pairs metamethod.
|
||||||
|
* Bugfix : sproto (See commits log of sproto)
|
||||||
|
* Add user log service support (In config)
|
||||||
|
* Remove the size limit of cluster RPC message.
|
||||||
|
* Remove the size limit of local message.
|
||||||
|
* Other minor bugfix (See commits log)
|
||||||
|
|
||||||
v1.0.0-alpha8 (2015-6-29)
|
v1.0.0-alpha8 (2015-6-29)
|
||||||
-----------
|
-----------
|
||||||
* Update lua 5.3.1
|
* Update lua 5.3.1
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -130,7 +130,9 @@ clean :
|
|||||||
rm -f $(SKYNET_BUILD_PATH)/skynet $(CSERVICE_PATH)/*.so $(LUA_CLIB_PATH)/*.so
|
rm -f $(SKYNET_BUILD_PATH)/skynet $(CSERVICE_PATH)/*.so $(LUA_CLIB_PATH)/*.so
|
||||||
|
|
||||||
cleanall: clean
|
cleanall: clean
|
||||||
|
ifneq (,$(wildcard 3rd/jemalloc/Makefile))
|
||||||
cd 3rd/jemalloc && $(MAKE) clean
|
cd 3rd/jemalloc && $(MAKE) clean
|
||||||
|
endif
|
||||||
cd 3rd/lua && $(MAKE) clean
|
cd 3rd/lua && $(MAKE) clean
|
||||||
rm -f $(LUA_STATICLIB)
|
rm -f $(LUA_STATICLIB)
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ Run these in different console
|
|||||||
|
|
||||||
## About Lua
|
## About Lua
|
||||||
|
|
||||||
Skynet now use Lua 5.3.0 final, http://www.lua.org/ftp/lua-5.3.0.tar.gz
|
Skynet now use a modify version of lua 5.3.1 (http://www.lua.org/ftp/lua-5.3.1.tar.gz) .
|
||||||
|
|
||||||
|
For detail : http://lua-users.org/lists/lua-l/2014-03/msg00489.html
|
||||||
|
|
||||||
You can also use the other official Lua version , edit the makefile by yourself .
|
You can also use the other official Lua version , edit the makefile by yourself .
|
||||||
|
|
||||||
|
|||||||
18
examples/config.userlog
Normal file
18
examples/config.userlog
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
root = "./"
|
||||||
|
thread = 8
|
||||||
|
logger = "userlog"
|
||||||
|
logservice = "snlua"
|
||||||
|
logpath = "."
|
||||||
|
harbor = 1
|
||||||
|
address = "127.0.0.1:2526"
|
||||||
|
master = "127.0.0.1:2013"
|
||||||
|
start = "main" -- main script
|
||||||
|
bootstrap = "snlua bootstrap" -- The service for bootstrap
|
||||||
|
standalone = "0.0.0.0:2013"
|
||||||
|
luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua"
|
||||||
|
lualoader = "lualib/loader.lua"
|
||||||
|
-- preload = "./examples/preload.lua" -- run preload.lua before every lua service run
|
||||||
|
snax = root.."examples/?.lua;"..root.."test/?.lua"
|
||||||
|
-- snax_interface_g = "snax_g"
|
||||||
|
cpath = root.."cservice/?.so"
|
||||||
|
-- daemon = "./skynet.pid"
|
||||||
@@ -131,7 +131,7 @@ local text = "echo"
|
|||||||
local index = 1
|
local index = 1
|
||||||
|
|
||||||
print("connect")
|
print("connect")
|
||||||
local fd = assert(socket.connect("127.0.0.1", 8888))
|
fd = assert(socket.connect("127.0.0.1", 8888))
|
||||||
last = ""
|
last = ""
|
||||||
|
|
||||||
local handshake = string.format("%s@%s#%s:%d", crypt.base64encode(token.user), crypt.base64encode(token.server),crypt.base64encode(subid) , index)
|
local handshake = string.format("%s@%s#%s:%d", crypt.base64encode(token.user), crypt.base64encode(token.server),crypt.base64encode(subid) , index)
|
||||||
@@ -151,7 +151,7 @@ socket.close(fd)
|
|||||||
index = index + 1
|
index = index + 1
|
||||||
|
|
||||||
print("connect again")
|
print("connect again")
|
||||||
local fd = assert(socket.connect("127.0.0.1", 8888))
|
fd = assert(socket.connect("127.0.0.1", 8888))
|
||||||
last = ""
|
last = ""
|
||||||
|
|
||||||
local handshake = string.format("%s@%s#%s:%d", crypt.base64encode(token.user), crypt.base64encode(token.server),crypt.base64encode(subid) , index)
|
local handshake = string.format("%s@%s#%s:%d", crypt.base64encode(token.user), crypt.base64encode(token.server),crypt.base64encode(subid) , index)
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ function server.login_handler(uid, secret)
|
|||||||
end
|
end
|
||||||
|
|
||||||
internal_id = internal_id + 1
|
internal_id = internal_id + 1
|
||||||
local username = msgserver.username(uid, internal_id, servername)
|
local id = internal_id -- don't use internal_id directly
|
||||||
|
local username = msgserver.username(uid, id, servername)
|
||||||
|
|
||||||
-- you can use a pool to alloc new agent
|
-- you can use a pool to alloc new agent
|
||||||
local agent = skynet.newservice "msgagent"
|
local agent = skynet.newservice "msgagent"
|
||||||
@@ -25,11 +26,11 @@ function server.login_handler(uid, secret)
|
|||||||
username = username,
|
username = username,
|
||||||
agent = agent,
|
agent = agent,
|
||||||
uid = uid,
|
uid = uid,
|
||||||
subid = internal_id,
|
subid = id,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- trash subid (no used)
|
-- trash subid (no used)
|
||||||
skynet.call(agent, "lua", "login", uid, internal_id, secret)
|
skynet.call(agent, "lua", "login", uid, id, secret)
|
||||||
|
|
||||||
users[uid] = u
|
users[uid] = u
|
||||||
username_map[username] = u
|
username_map[username] = u
|
||||||
@@ -37,7 +38,7 @@ function server.login_handler(uid, secret)
|
|||||||
msgserver.login(username, secret)
|
msgserver.login(username, secret)
|
||||||
|
|
||||||
-- you should return unique subid
|
-- you should return unique subid
|
||||||
return internal_id
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
-- call by agent
|
-- call by agent
|
||||||
|
|||||||
@@ -37,6 +37,16 @@ skynet.start(function()
|
|||||||
skynet.error(string.format("b[%d]=%s", k,v))
|
skynet.error(string.format("b[%d]=%s", k,v))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- test lua serialization
|
||||||
|
local s = skynet.packstring(obj)
|
||||||
|
local nobj = skynet.unpack(s)
|
||||||
|
for k,v in pairs(nobj) do
|
||||||
|
skynet.error(string.format("nobj[%s]=%s", k,v))
|
||||||
|
end
|
||||||
|
for k,v in ipairs(nobj.b) do
|
||||||
|
skynet.error(string.format("nobj.b[%d]=%s", k,v))
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, 5 do
|
for i = 1, 5 do
|
||||||
skynet.sleep(100)
|
skynet.sleep(100)
|
||||||
skynet.error("second " ..i)
|
skynet.error("second " ..i)
|
||||||
|
|||||||
15
examples/userlog.lua
Normal file
15
examples/userlog.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
local skynet = require "skynet"
|
||||||
|
require "skynet.manager"
|
||||||
|
|
||||||
|
skynet.register_protocol {
|
||||||
|
name = "text",
|
||||||
|
id = skynet.PTYPE_TEXT,
|
||||||
|
unpack = skynet.tostring,
|
||||||
|
dispatch = function(_, address, msg)
|
||||||
|
print(string.format("%x(%.2f): %s", address, skynet.time(), msg))
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
skynet.start(function()
|
||||||
|
skynet.register ".logger"
|
||||||
|
end)
|
||||||
@@ -243,12 +243,16 @@ append_key(struct bson *bs, int type, const char *key, size_t sz) {
|
|||||||
write_string(bs, key, sz);
|
write_string(bs, key, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
is_32bit(int64_t v) {
|
||||||
|
return v >= INT32_MIN && v <= INT32_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
append_number(struct bson *bs, lua_State *L, const char *key, size_t sz) {
|
append_number(struct bson *bs, lua_State *L, const char *key, size_t sz) {
|
||||||
if (lua_isinteger(L, -1)) {
|
if (lua_isinteger(L, -1)) {
|
||||||
int64_t i = lua_tointeger(L, -1);
|
int64_t i = lua_tointeger(L, -1);
|
||||||
int si = i >> 31;
|
if (is_32bit(i)) {
|
||||||
if (si == 0 || si == -1) {
|
|
||||||
append_key(bs, BSON_INT32, key, sz);
|
append_key(bs, BSON_INT32, key, sz);
|
||||||
write_int32(bs, i);
|
write_int32(bs, i);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ lpackrequest(lua_State *L) {
|
|||||||
size_t sz = (size_t)luaL_checkinteger(L,4);
|
size_t sz = (size_t)luaL_checkinteger(L,4);
|
||||||
int session = luaL_checkinteger(L,2);
|
int session = luaL_checkinteger(L,2);
|
||||||
if (session <= 0) {
|
if (session <= 0) {
|
||||||
|
skynet_free(msg);
|
||||||
return luaL_error(L, "Invalid request session %d", session);
|
return luaL_error(L, "Invalid request session %d", session);
|
||||||
}
|
}
|
||||||
int addr_type = lua_type(L,1);
|
int addr_type = lua_type(L,1);
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ luaopen_memory(lua_State *L) {
|
|||||||
{ "block", lblock },
|
{ "block", lblock },
|
||||||
{ "dumpinfo", ldumpinfo },
|
{ "dumpinfo", ldumpinfo },
|
||||||
{ "dump", ldump },
|
{ "dump", ldump },
|
||||||
|
{ "info", dump_mem_lua },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -254,14 +254,41 @@ wb_table_hash(lua_State *L, struct write_block * wb, int index, int depth, int a
|
|||||||
wb_nil(wb);
|
wb_nil(wb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wb_table_metapairs(lua_State *L, struct write_block *wb, int index, int depth) {
|
||||||
|
uint8_t n = COMBINE_TYPE(TYPE_TABLE, 0);
|
||||||
|
wb_push(wb, &n, 1);
|
||||||
|
lua_pushvalue(L, index);
|
||||||
|
lua_call(L, 1, 3);
|
||||||
|
for(;;) {
|
||||||
|
lua_pushvalue(L, -2);
|
||||||
|
lua_pushvalue(L, -2);
|
||||||
|
lua_copy(L, -5, -3);
|
||||||
|
lua_call(L, 2, 2);
|
||||||
|
int type = lua_type(L, -2);
|
||||||
|
if (type == LUA_TNIL) {
|
||||||
|
lua_pop(L, 4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pack_one(L, wb, -2, depth);
|
||||||
|
pack_one(L, wb, -1, depth);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
wb_nil(wb);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wb_table(lua_State *L, struct write_block *wb, int index, int depth) {
|
wb_table(lua_State *L, struct write_block *wb, int index, int depth) {
|
||||||
luaL_checkstack(L, LUA_MINSTACK, NULL);
|
luaL_checkstack(L, LUA_MINSTACK, NULL);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = lua_gettop(L) + index + 1;
|
index = lua_gettop(L) + index + 1;
|
||||||
}
|
}
|
||||||
int array_size = wb_table_array(L, wb, index, depth);
|
if (luaL_getmetafield(L, index, "__pairs") != LUA_TNIL) {
|
||||||
wb_table_hash(L, wb, index, depth, array_size);
|
wb_table_metapairs(L, wb, index, depth);
|
||||||
|
} else {
|
||||||
|
int array_size = wb_table_array(L, wb, index, depth);
|
||||||
|
wb_table_hash(L, wb, index, depth, array_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -376,6 +376,7 @@ pconv(lua_State *L) {
|
|||||||
static void
|
static void
|
||||||
convert_stringmap(struct context *ctx, struct table *tbl) {
|
convert_stringmap(struct context *ctx, struct table *tbl) {
|
||||||
lua_State *L = ctx->L;
|
lua_State *L = ctx->L;
|
||||||
|
lua_checkstack(L, ctx->string_index + LUA_MINSTACK);
|
||||||
lua_settop(L, ctx->string_index + 1);
|
lua_settop(L, ctx->string_index + 1);
|
||||||
lua_pushvalue(L, 1);
|
lua_pushvalue(L, 1);
|
||||||
struct state * s = lua_newuserdata(L, sizeof(*s));
|
struct state * s = lua_newuserdata(L, sizeof(*s));
|
||||||
|
|||||||
@@ -487,10 +487,10 @@ lunpack(lua_State *L) {
|
|||||||
return luaL_error(L, "Invalid unpack stream");
|
return luaL_error(L, "Invalid unpack stream");
|
||||||
if (r > osz) {
|
if (r > osz) {
|
||||||
output = expand_buffer(L, osz, r);
|
output = expand_buffer(L, osz, r);
|
||||||
|
r = sproto_unpack(buffer, sz, output, r);
|
||||||
|
if (r < 0)
|
||||||
|
return luaL_error(L, "Invalid unpack stream");
|
||||||
}
|
}
|
||||||
r = sproto_unpack(buffer, sz, output, r);
|
|
||||||
if (r < 0)
|
|
||||||
return luaL_error(L, "Invalid unpack stream");
|
|
||||||
lua_pushlstring(L, output, r);
|
lua_pushlstring(L, output, r);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ static void *
|
|||||||
pool_alloc(struct pool *p, size_t sz) {
|
pool_alloc(struct pool *p, size_t sz) {
|
||||||
// align by 8
|
// align by 8
|
||||||
sz = (sz + 7) & ~7;
|
sz = (sz + 7) & ~7;
|
||||||
if (sz > CHUNK_SIZE) {
|
if (sz >= CHUNK_SIZE) {
|
||||||
return pool_newchunk(p, sz);
|
return pool_newchunk(p, sz);
|
||||||
}
|
}
|
||||||
if (p->current == NULL) {
|
if (p->current == NULL) {
|
||||||
@@ -97,7 +97,7 @@ pool_alloc(struct pool *p, size_t sz) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sz > p->current_used) {
|
if (sz >= p->current_used) {
|
||||||
return pool_newchunk(p, sz);
|
return pool_newchunk(p, sz);
|
||||||
} else {
|
} else {
|
||||||
void * ret = pool_newchunk(p, CHUNK_SIZE);
|
void * ret = pool_newchunk(p, CHUNK_SIZE);
|
||||||
@@ -152,7 +152,7 @@ struct_field(const uint8_t * stream, size_t sz) {
|
|||||||
sz -= header;
|
sz -= header;
|
||||||
stream += header;
|
stream += header;
|
||||||
for (i=0;i<fn;i++) {
|
for (i=0;i<fn;i++) {
|
||||||
int value= toword(field + i * SIZEOF_FIELD + SIZEOF_HEADER);
|
int value= toword(field + i * SIZEOF_FIELD);
|
||||||
uint32_t dsz;
|
uint32_t dsz;
|
||||||
if (value != 0)
|
if (value != 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -305,7 +305,7 @@ import_type(struct sproto *s, struct sproto_type *t, const uint8_t * stream) {
|
|||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
tag = f->tag;
|
tag = f->tag;
|
||||||
if (tag < last)
|
if (tag <= last)
|
||||||
return NULL; // tag must in ascending order
|
return NULL; // tag must in ascending order
|
||||||
if (tag > last+1) {
|
if (tag > last+1) {
|
||||||
++maxn;
|
++maxn;
|
||||||
@@ -394,7 +394,7 @@ create_from_bundle(struct sproto *s, const uint8_t * stream, size_t sz) {
|
|||||||
const uint8_t * protocoldata = NULL;
|
const uint8_t * protocoldata = NULL;
|
||||||
int fn = struct_field(stream, sz);
|
int fn = struct_field(stream, sz);
|
||||||
int i;
|
int i;
|
||||||
if (fn < 0)
|
if (fn < 0 || fn > 2)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
stream += SIZEOF_HEADER;
|
stream += SIZEOF_HEADER;
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ local dispatch = setmetatable({} , {__mode = "kv" })
|
|||||||
local chan = {}
|
local chan = {}
|
||||||
local chan_meta = {
|
local chan_meta = {
|
||||||
__index = chan,
|
__index = chan,
|
||||||
__gc = unsubscribe,
|
__gc = function(self)
|
||||||
|
self:unsubscribe()
|
||||||
|
end,
|
||||||
__tostring = function (self)
|
__tostring = function (self)
|
||||||
return string.format("[Multicast:%x]",self.channel)
|
return string.format("[Multicast:%x]",self.channel)
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -415,9 +415,14 @@ function skynet.wakeup(co)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.dispatch(typename, func)
|
function skynet.dispatch(typename, func)
|
||||||
local p = assert(proto[typename],tostring(typename))
|
local p = proto[typename]
|
||||||
assert(p.dispatch == nil, tostring(typename))
|
if func then
|
||||||
p.dispatch = func
|
local ret = p.dispatch
|
||||||
|
p.dispatch = func
|
||||||
|
return ret
|
||||||
|
else
|
||||||
|
return p and p.dispatch
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function unknown_request(session, address, msg, sz, prototype)
|
local function unknown_request(session, address, msg, sz, prototype)
|
||||||
@@ -466,7 +471,15 @@ local function raw_dispatch_message(prototype, msg, sz, session, source, ...)
|
|||||||
suspend(co, coroutine.resume(co, true, msg, sz))
|
suspend(co, coroutine.resume(co, true, msg, sz))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local p = assert(proto[prototype], prototype)
|
local p = proto[prototype]
|
||||||
|
if p == nil then
|
||||||
|
if session ~= 0 then
|
||||||
|
c.send(source, skynet.PTYPE_ERROR, session, "")
|
||||||
|
else
|
||||||
|
unknown_request(session, source, msg, sz, prototype)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
local f = p.dispatch
|
local f = p.dispatch
|
||||||
if f then
|
if f then
|
||||||
local ref = watching_service[source]
|
local ref = watching_service[source]
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ function skynet.info_func(func)
|
|||||||
internal_info_func = func
|
internal_info_func = func
|
||||||
end
|
end
|
||||||
|
|
||||||
local dbgcmd = {}
|
local dbgcmd
|
||||||
|
|
||||||
|
local function init_dbgcmd()
|
||||||
|
dbgcmd = {}
|
||||||
|
|
||||||
function dbgcmd.MEM()
|
function dbgcmd.MEM()
|
||||||
local kb, bytes = collectgarbage "count"
|
local kb, bytes = collectgarbage "count"
|
||||||
@@ -63,8 +66,15 @@ function dbgcmd.REMOTEDEBUG(...)
|
|||||||
remotedebug.start(export, ...)
|
remotedebug.start(export, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function dbgcmd.SUPPORT(pname)
|
||||||
|
return skynet.ret(skynet.pack(skynet.dispatch(pname) ~= nil))
|
||||||
|
end
|
||||||
|
|
||||||
|
return dbgcmd
|
||||||
|
end -- function init_dbgcmd
|
||||||
|
|
||||||
local function _debug_dispatch(session, address, cmd, ...)
|
local function _debug_dispatch(session, address, cmd, ...)
|
||||||
local f = dbgcmd[cmd]
|
local f = (dbgcmd or init_dbgcmd())[cmd] -- lazy init dbgcmd
|
||||||
assert(f, cmd)
|
assert(f, cmd)
|
||||||
f(...)
|
f(...)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ local function collect_all_uv(funcs)
|
|||||||
collect_uv(v[4], global, envid(v[4]))
|
collect_uv(v[4], global, envid(v[4]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not global["_ENV"] then
|
||||||
|
global["_ENV"] = {func = collect_uv, index = 1}
|
||||||
|
end
|
||||||
return global
|
return global
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ end
|
|||||||
|
|
||||||
local typedef = P {
|
local typedef = P {
|
||||||
"ALL",
|
"ALL",
|
||||||
FIELD = namedpat("field", (name * blanks * tag * blank0 * ":" * blank0 * (C"*")^0 * typename * mainkey^0)),
|
FIELD = namedpat("field", (name * blanks * tag * blank0 * ":" * blank0 * (C"*")^-1 * typename * mainkey^0)),
|
||||||
STRUCT = P"{" * multipat(V"FIELD" + V"TYPE") * P"}",
|
STRUCT = P"{" * multipat(V"FIELD" + V"TYPE") * P"}",
|
||||||
TYPE = namedpat("type", P"." * name * blank0 * V"STRUCT" ),
|
TYPE = namedpat("type", P"." * name * blank0 * V"STRUCT" ),
|
||||||
SUBPROTO = Ct((C"request" + C"response") * blanks * (typename + V"STRUCT")),
|
SUBPROTO = Ct((C"request" + C"response") * blanks * (typename + V"STRUCT")),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ require "skynet.manager" -- import skynet.launch, ...
|
|||||||
local globalname = {}
|
local globalname = {}
|
||||||
local queryname = {}
|
local queryname = {}
|
||||||
local harbor = {}
|
local harbor = {}
|
||||||
|
local harbor_service
|
||||||
|
|
||||||
skynet.register_protocol {
|
skynet.register_protocol {
|
||||||
name = "harbor",
|
name = "harbor",
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ local function open_channel(t, key)
|
|||||||
}
|
}
|
||||||
assert(c:connect(true))
|
assert(c:connect(true))
|
||||||
t[key] = c
|
t[key] = c
|
||||||
node_session[key] = 1
|
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -63,11 +62,13 @@ function command.listen(source, addr, port)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function send_request(source, node, addr, msg, sz)
|
local function send_request(source, node, addr, msg, sz)
|
||||||
local request
|
local session = node_session[node] or 1
|
||||||
local c = node_channel[node]
|
|
||||||
local session = node_session[node]
|
|
||||||
-- msg is a local pointer, cluster.packrequest will free it
|
-- msg is a local pointer, cluster.packrequest will free it
|
||||||
request, node_session[node] = cluster.packrequest(addr, session , msg, sz)
|
local request, new_session = cluster.packrequest(addr, session, msg, sz)
|
||||||
|
node_session[node] = new_session
|
||||||
|
|
||||||
|
-- node_channel[node] may yield or throw error
|
||||||
|
local c = node_channel[node]
|
||||||
|
|
||||||
return c:request(request, session)
|
return c:request(request, session)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ local skynet = require "skynet"
|
|||||||
local memory = require "memory"
|
local memory = require "memory"
|
||||||
|
|
||||||
memory.dumpinfo()
|
memory.dumpinfo()
|
||||||
memory.dump()
|
--memory.dump()
|
||||||
|
local info = memory.info()
|
||||||
|
for k,v in pairs(info) do
|
||||||
|
print(string.format(":%08x %gK",k,v/1024))
|
||||||
|
end
|
||||||
|
|
||||||
print("Total memory:", memory.total())
|
print("Total memory:", memory.total())
|
||||||
print("Total block:", memory.block())
|
print("Total block:", memory.block())
|
||||||
|
|||||||
@@ -228,6 +228,7 @@ function COMMAND.debug(address, fd)
|
|||||||
skynet.fork(function()
|
skynet.fork(function()
|
||||||
repeat
|
repeat
|
||||||
local cmdline = socket.readline(fd, "\n")
|
local cmdline = socket.readline(fd, "\n")
|
||||||
|
cmdline = cmdline:gsub("(.*)\r$", "%1")
|
||||||
if not cmdline then
|
if not cmdline then
|
||||||
skynet.send(agent, "lua", "cmd", "cont")
|
skynet.send(agent, "lua", "cmd", "cont")
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <lua.h>
|
||||||
|
|
||||||
#include "malloc_hook.h"
|
#include "malloc_hook.h"
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
@@ -224,3 +225,17 @@ skynet_lalloc(void *ud, void *ptr, size_t osize, size_t nsize) {
|
|||||||
return skynet_realloc(ptr, nsize);
|
return skynet_realloc(ptr, nsize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
dump_mem_lua(lua_State *L) {
|
||||||
|
int i;
|
||||||
|
lua_newtable(L);
|
||||||
|
for(i=0; i<SLOT_SIZE; i++) {
|
||||||
|
mem_data* data = &mem_stats[i];
|
||||||
|
if(data->handle != 0 && data->allocated != 0) {
|
||||||
|
lua_pushinteger(L, data->allocated);
|
||||||
|
lua_rawseti(L, -2, (lua_Integer)data->handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define SKYNET_MALLOC_HOOK_H
|
#define SKYNET_MALLOC_HOOK_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <lua.h>
|
||||||
|
|
||||||
extern size_t malloc_used_memory(void);
|
extern size_t malloc_used_memory(void);
|
||||||
extern size_t malloc_memory_block(void);
|
extern size_t malloc_memory_block(void);
|
||||||
@@ -9,6 +10,7 @@ extern void memory_info_dump(void);
|
|||||||
extern size_t mallctl_int64(const char* name, size_t* newval);
|
extern size_t mallctl_int64(const char* name, size_t* newval);
|
||||||
extern int mallctl_opt(const char* name, int* newval);
|
extern int mallctl_opt(const char* name, int* newval);
|
||||||
extern void dump_c_mem(void);
|
extern void dump_c_mem(void);
|
||||||
|
extern int dump_mem_lua(lua_State *L);
|
||||||
|
|
||||||
#endif /* SKYNET_MALLOC_HOOK_H */
|
#endif /* SKYNET_MALLOC_HOOK_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1265,7 +1265,7 @@ send_request(struct socket_server *ss, struct request_package *request, char typ
|
|||||||
static int
|
static int
|
||||||
open_request(struct socket_server *ss, struct request_package *req, uintptr_t opaque, const char *addr, int port) {
|
open_request(struct socket_server *ss, struct request_package *req, uintptr_t opaque, const char *addr, int port) {
|
||||||
int len = strlen(addr);
|
int len = strlen(addr);
|
||||||
if (len + sizeof(req->u.open) > 256) {
|
if (len + sizeof(req->u.open) >= 256) {
|
||||||
fprintf(stderr, "socket-server : Invalid addr %s.\n",addr);
|
fprintf(stderr, "socket-server : Invalid addr %s.\n",addr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user