Compare commits

...

44 Commits

Author SHA1 Message Date
Cloud Wu
2935ba3521 Release alpha9 2015-08-10 16:17:55 +08:00
云风
5c8ea6f09f Merge pull request #318 from felixdae/cloud
not work with telnet due to \r\n
2015-08-08 16:45:21 +08:00
felixdae
c16ae57639 not work with telnet due to \r\n 2015-08-07 18:52:50 +08:00
云风
1c7d44fd4d Merge pull request #316 from niuys/patch-2
'hotfix' code cannot use '_ENV'
2015-08-07 16:14:13 +08:00
snail
e9cfdba22a 'hotfix' code cannot use '_ENV'
If there's no global variable or function used in any interface of a snax service,the upvalue "_ENV" for 'hotfix' is not set. This modify is not  complete, it depend's on the 'collect_uv' method having upvalue '_ENV',maybe other good method to get upvalue index of '_ENV'.
2015-08-07 10:38:57 +08:00
Cloud Wu
704b016f2c bugfix: inc session before get channel 2015-08-04 17:51:35 +08:00
Cloud Wu
3b48beb428 bson bugfix 2015-07-30 15:41:17 +08:00
Cloud Wu
4cbead28d5 skynet.dispatch can replace old func 2015-07-29 16:12:49 +08:00
Cloud Wu
b3f966bcaa bugfix: multicast chan gc 2015-07-29 16:10:38 +08:00
Cloud Wu
7b54e37d12 Merge branch 'master' of github.com:cloudwu/skynet 2015-07-24 17:58:06 +08:00
Cloud Wu
e87ac18b84 expand lua stack first 2015-07-24 17:50:42 +08:00
云风
05af87ce8e Merge pull request #311 from jintiao/patch-1
fix "make cleanall" on macosx
2015-07-24 17:45:41 +08:00
jintiao
0ee61de22c skip jemalloc clean if jemalloc's makefile was missing 2015-07-24 00:48:24 +08:00
Cloud Wu
1da8a6b38d lazy init debug command 2015-07-23 18:35:29 +08:00
Cloud Wu
b2d8237363 improve unregister protocol error report 2015-07-23 18:23:47 +08:00
Cloud Wu
39f9a96b6c add cmemory.info() returns a table of c memory info 2015-07-23 16:47:35 +08:00
Cloud Wu
588c4a3508 bugfix 2015-07-22 16:49:25 +08:00
Cloud Wu
d6734890e0 Merge branch 'master' of github.com:cloudwu/skynet 2015-07-22 15:53:19 +08:00
Cloud Wu
4ebb139c2b bugfix: free message when cluster not connected 2015-07-22 15:52:26 +08:00
云风
20476d2280 Merge pull request #308 from jsenter/patch-1
Update cdummy.lua
2015-07-21 15:20:56 +08:00
Cloud Wu
3131bca6ef Merge branch 'master' of github.com:cloudwu/skynet 2015-07-21 11:31:41 +08:00
Cloud Wu
3f91484791 user log service 2015-07-21 11:31:27 +08:00
LiBei
a0ecd51230 Update cdummy.lua
误定义全局变量
2015-07-21 11:12:55 +08:00
云风
dba1db9cc4 Merge pull request #304 from JiessieDawn/master
sharedata serialization bugfix
2015-07-13 14:13:48 +08:00
cxj
538414408d sharedata serialization bugfix 2015-07-13 13:04:09 +08:00
云风
4cf05fb2e7 Merge pull request #303 from JiessieDawn/master
sproto optimize
2015-07-11 20:36:39 +08:00
cxj
d9ad981c8c sproto optimize, malloc newchunk and return directly if sz >= CHUNK_SIZE in pool_alloc, do not replace current chunk if sz >= p->current_used in pool_alloc, more safety checking 2015-07-10 20:21:07 +08:00
云风
21c941fe63 Merge pull request #302 from sanikoyes/Pr-optimize-sproto-lunpack
Pr-optimize-sproto-unpack
2015-07-09 18:24:06 +08:00
sanikoyes
ea2437e138 lunpack optimize, do not unpack twice if r <= osz 2015-07-09 18:07:32 +08:00
Cloud Wu
86bbc9c701 off by 1 error 2015-07-07 12:11:16 +08:00
Cloud Wu
95e1d9f45f Merge branch 'master' of github.com:cloudwu/skynet 2015-07-03 10:58:53 +08:00
Cloud Wu
55cf9375fc asterisk(*) should be once or not at all 2015-07-03 10:58:40 +08:00
云风
654f732cd5 Merge pull request #300 from sanikoyes/Pr-fix-login-client
Pr-fix-login-client
2015-07-03 10:28:24 +08:00
sanikoyes
d4023c8b63 fix invalid fd after reconnected, used in unpack_f 2015-07-02 16:25:10 +08:00
云风
375f8606b4 Merge pull request #298 from JiessieDawn/master
support sharedata serialization
2015-07-02 15:04:49 +08:00
cxj
d17e6f59fe add sharedata lua serialization test 2015-07-02 15:02:11 +08:00
cxj
a77d36911d change wb_table to call wb_table_metapairs for keeping consistent style 2015-07-02 14:47:50 +08:00
cxj
4352dc4047 Merge branch 'master' of https://github.com/cloudwu/skynet 2015-07-02 13:56:55 +08:00
cxj
172356be19 fix lua-seric.c wb_table 2015-07-02 13:51:03 +08:00
Cloud Wu
08dabd51c8 fix issue #299 2015-07-02 12:17:18 +08:00
cxj
bd55a58515 support sharedata serialization 2015-07-01 16:54:20 +08:00
Cloud Wu
b646a1b8a3 fix login example 2015-07-01 12:51:20 +08:00
Cloud Wu
6b312fa09a update readme 2015-07-01 11:35:05 +08:00
Cloud Wu
dad66010cd sproto bugfix, see sproto issue 34 for detail 2015-06-30 15:05:49 +08:00
28 changed files with 179 additions and 35 deletions

View File

@@ -44,6 +44,8 @@ LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
#define LUA_CACHELIB
LUAMOD_API int (luaopen_cache) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);

View File

@@ -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)
-----------
* Update lua 5.3.1

View File

@@ -130,7 +130,9 @@ clean :
rm -f $(SKYNET_BUILD_PATH)/skynet $(CSERVICE_PATH)/*.so $(LUA_CLIB_PATH)/*.so
cleanall: clean
ifneq (,$(wildcard 3rd/jemalloc/Makefile))
cd 3rd/jemalloc && $(MAKE) clean
endif
cd 3rd/lua && $(MAKE) clean
rm -f $(LUA_STATICLIB)

View File

@@ -28,7 +28,9 @@ Run these in different console
## 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 .

18
examples/config.userlog Normal file
View 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"

View File

@@ -131,7 +131,7 @@ local text = "echo"
local index = 1
print("connect")
local fd = assert(socket.connect("127.0.0.1", 8888))
fd = assert(socket.connect("127.0.0.1", 8888))
last = ""
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
print("connect again")
local fd = assert(socket.connect("127.0.0.1", 8888))
fd = assert(socket.connect("127.0.0.1", 8888))
last = ""
local handshake = string.format("%s@%s#%s:%d", crypt.base64encode(token.user), crypt.base64encode(token.server),crypt.base64encode(subid) , index)

View File

@@ -17,7 +17,8 @@ function server.login_handler(uid, secret)
end
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
local agent = skynet.newservice "msgagent"
@@ -25,11 +26,11 @@ function server.login_handler(uid, secret)
username = username,
agent = agent,
uid = uid,
subid = internal_id,
subid = id,
}
-- trash subid (no used)
skynet.call(agent, "lua", "login", uid, internal_id, secret)
skynet.call(agent, "lua", "login", uid, id, secret)
users[uid] = u
username_map[username] = u
@@ -37,7 +38,7 @@ function server.login_handler(uid, secret)
msgserver.login(username, secret)
-- you should return unique subid
return internal_id
return id
end
-- call by agent

View File

@@ -37,6 +37,16 @@ skynet.start(function()
skynet.error(string.format("b[%d]=%s", k,v))
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
skynet.sleep(100)
skynet.error("second " ..i)

15
examples/userlog.lua Normal file
View 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)

View File

@@ -243,12 +243,16 @@ append_key(struct bson *bs, int type, const char *key, size_t sz) {
write_string(bs, key, sz);
}
static inline int
is_32bit(int64_t v) {
return v >= INT32_MIN && v <= INT32_MAX;
}
static void
append_number(struct bson *bs, lua_State *L, const char *key, size_t sz) {
if (lua_isinteger(L, -1)) {
int64_t i = lua_tointeger(L, -1);
int si = i >> 31;
if (si == 0 || si == -1) {
if (is_32bit(i)) {
append_key(bs, BSON_INT32, key, sz);
write_int32(bs, i);
} else {

View File

@@ -76,6 +76,7 @@ lpackrequest(lua_State *L) {
size_t sz = (size_t)luaL_checkinteger(L,4);
int session = luaL_checkinteger(L,2);
if (session <= 0) {
skynet_free(msg);
return luaL_error(L, "Invalid request session %d", session);
}
int addr_type = lua_type(L,1);

View File

@@ -42,6 +42,7 @@ luaopen_memory(lua_State *L) {
{ "block", lblock },
{ "dumpinfo", ldumpinfo },
{ "dump", ldump },
{ "info", dump_mem_lua },
{ NULL, NULL },
};

View File

@@ -254,14 +254,41 @@ wb_table_hash(lua_State *L, struct write_block * wb, int index, int depth, int a
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
wb_table(lua_State *L, struct write_block *wb, int index, int depth) {
luaL_checkstack(L, LUA_MINSTACK, NULL);
if (index < 0) {
index = lua_gettop(L) + index + 1;
}
int array_size = wb_table_array(L, wb, index, depth);
wb_table_hash(L, wb, index, depth, array_size);
if (luaL_getmetafield(L, index, "__pairs") != LUA_TNIL) {
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

View File

@@ -376,6 +376,7 @@ pconv(lua_State *L) {
static void
convert_stringmap(struct context *ctx, struct table *tbl) {
lua_State *L = ctx->L;
lua_checkstack(L, ctx->string_index + LUA_MINSTACK);
lua_settop(L, ctx->string_index + 1);
lua_pushvalue(L, 1);
struct state * s = lua_newuserdata(L, sizeof(*s));

View File

@@ -487,10 +487,10 @@ lunpack(lua_State *L) {
return luaL_error(L, "Invalid unpack stream");
if (r > osz) {
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);
return 1;
}

View File

@@ -83,7 +83,7 @@ static void *
pool_alloc(struct pool *p, size_t sz) {
// align by 8
sz = (sz + 7) & ~7;
if (sz > CHUNK_SIZE) {
if (sz >= CHUNK_SIZE) {
return pool_newchunk(p, sz);
}
if (p->current == NULL) {
@@ -97,7 +97,7 @@ pool_alloc(struct pool *p, size_t sz) {
return ret;
}
if (sz > p->current_used) {
if (sz >= p->current_used) {
return pool_newchunk(p, sz);
} else {
void * ret = pool_newchunk(p, CHUNK_SIZE);
@@ -152,7 +152,7 @@ struct_field(const uint8_t * stream, size_t sz) {
sz -= header;
stream += header;
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;
if (value != 0)
continue;
@@ -305,7 +305,7 @@ import_type(struct sproto *s, struct sproto_type *t, const uint8_t * stream) {
if (stream == NULL)
return NULL;
tag = f->tag;
if (tag < last)
if (tag <= last)
return NULL; // tag must in ascending order
if (tag > last+1) {
++maxn;
@@ -394,7 +394,7 @@ create_from_bundle(struct sproto *s, const uint8_t * stream, size_t sz) {
const uint8_t * protocoldata = NULL;
int fn = struct_field(stream, sz);
int i;
if (fn < 0)
if (fn < 0 || fn > 2)
return NULL;
stream += SIZEOF_HEADER;

View File

@@ -8,7 +8,9 @@ local dispatch = setmetatable({} , {__mode = "kv" })
local chan = {}
local chan_meta = {
__index = chan,
__gc = unsubscribe,
__gc = function(self)
self:unsubscribe()
end,
__tostring = function (self)
return string.format("[Multicast:%x]",self.channel)
end,

View File

@@ -415,9 +415,14 @@ function skynet.wakeup(co)
end
function skynet.dispatch(typename, func)
local p = assert(proto[typename],tostring(typename))
assert(p.dispatch == nil, tostring(typename))
p.dispatch = func
local p = proto[typename]
if func then
local ret = p.dispatch
p.dispatch = func
return ret
else
return p and p.dispatch
end
end
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))
end
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
if f then
local ref = watching_service[source]

View File

@@ -10,7 +10,10 @@ function skynet.info_func(func)
internal_info_func = func
end
local dbgcmd = {}
local dbgcmd
local function init_dbgcmd()
dbgcmd = {}
function dbgcmd.MEM()
local kb, bytes = collectgarbage "count"
@@ -63,8 +66,15 @@ function dbgcmd.REMOTEDEBUG(...)
remotedebug.start(export, ...)
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 f = dbgcmd[cmd]
local f = (dbgcmd or init_dbgcmd())[cmd] -- lazy init dbgcmd
assert(f, cmd)
f(...)
end

View File

@@ -49,7 +49,9 @@ local function collect_all_uv(funcs)
collect_uv(v[4], global, envid(v[4]))
end
end
if not global["_ENV"] then
global["_ENV"] = {func = collect_uv, index = 1}
end
return global
end

View File

@@ -81,7 +81,7 @@ end
local typedef = P {
"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"}",
TYPE = namedpat("type", P"." * name * blank0 * V"STRUCT" ),
SUBPROTO = Ct((C"request" + C"response") * blanks * (typename + V"STRUCT")),

View File

@@ -4,6 +4,7 @@ require "skynet.manager" -- import skynet.launch, ...
local globalname = {}
local queryname = {}
local harbor = {}
local harbor_service
skynet.register_protocol {
name = "harbor",

View File

@@ -24,7 +24,6 @@ local function open_channel(t, key)
}
assert(c:connect(true))
t[key] = c
node_session[key] = 1
return c
end
@@ -63,11 +62,13 @@ function command.listen(source, addr, port)
end
local function send_request(source, node, addr, msg, sz)
local request
local c = node_channel[node]
local session = node_session[node]
local session = node_session[node] or 1
-- 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)
end

View File

@@ -2,7 +2,11 @@ local skynet = require "skynet"
local memory = require "memory"
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 block:", memory.block())

View File

@@ -228,6 +228,7 @@ function COMMAND.debug(address, fd)
skynet.fork(function()
repeat
local cmdline = socket.readline(fd, "\n")
cmdline = cmdline:gsub("(.*)\r$", "%1")
if not cmdline then
skynet.send(agent, "lua", "cmd", "cont")
break

View File

@@ -2,6 +2,7 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <lua.h>
#include "malloc_hook.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);
}
}
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;
}

View File

@@ -2,6 +2,7 @@
#define SKYNET_MALLOC_HOOK_H
#include <stdlib.h>
#include <lua.h>
extern size_t malloc_used_memory(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 int mallctl_opt(const char* name, int* newval);
extern void dump_c_mem(void);
extern int dump_mem_lua(lua_State *L);
#endif /* SKYNET_MALLOC_HOOK_H */

View File

@@ -1265,7 +1265,7 @@ send_request(struct socket_server *ss, struct request_package *request, char typ
static int
open_request(struct socket_server *ss, struct request_package *req, uintptr_t opaque, const char *addr, int port) {
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);
return -1;
}