mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 11:03:12 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2128a82571 | ||
|
|
d910686cb8 | ||
|
|
078ac2bcd2 |
@@ -1,3 +1,9 @@
|
||||
v0.3.2 (2014-6-23)
|
||||
----------
|
||||
* Bugifx : mongo driver and lua-bson . (objectid encoding, and gc problem when mongdo driver reply bson object).
|
||||
* Bugfix : cluster (double free).
|
||||
* Add socket.header() to decode big-endian package header (and fix the bug in cluster).
|
||||
|
||||
v0.3.1 (2014-6-16)
|
||||
-----------
|
||||
* Bugfix: lua mongo driver . Hold reply string before decode bson data.
|
||||
|
||||
@@ -153,6 +153,8 @@ lunpackrequest(lua_State *L) {
|
||||
static int
|
||||
lpackresponse(lua_State *L) {
|
||||
uint32_t session = luaL_checkunsigned(L,1);
|
||||
// clusterd.lua:command.socket call lpackresponse,
|
||||
// and the msg/sz is return by skynet.rawcall , so don't free(msg)
|
||||
void * msg = lua_touserdata(L,2);
|
||||
size_t sz = luaL_checkunsigned(L, 3);
|
||||
|
||||
@@ -161,8 +163,6 @@ lpackresponse(lua_State *L) {
|
||||
fill_uint32(buf+2, session);
|
||||
memcpy(buf+6,msg,sz);
|
||||
|
||||
skynet_free(msg);
|
||||
|
||||
lua_pushlstring(L, (const char *)buf, sz+6);
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -188,10 +188,29 @@ pop_lstring(lua_State *L, struct socket_buffer *sb, int sz, int skip) {
|
||||
luaL_pushresult(&b);
|
||||
}
|
||||
|
||||
static int
|
||||
lheader(lua_State *L) {
|
||||
size_t len;
|
||||
const uint8_t * s = (const uint8_t *)luaL_checklstring(L, 1, &len);
|
||||
if (len > 4 || len < 1) {
|
||||
return luaL_error(L, "Invalid read %s", s);
|
||||
}
|
||||
int i;
|
||||
size_t sz = 0;
|
||||
for (i=0;i<(int)len;i++) {
|
||||
sz <<= 8;
|
||||
sz |= s[i];
|
||||
}
|
||||
|
||||
lua_pushunsigned(L, sz);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
userdata send_buffer
|
||||
table pool
|
||||
integer sz or string (big endian)
|
||||
integer sz
|
||||
*/
|
||||
static int
|
||||
lpopbuffer(lua_State *L) {
|
||||
@@ -200,23 +219,7 @@ lpopbuffer(lua_State *L) {
|
||||
return luaL_error(L, "Need buffer object at param 1");
|
||||
}
|
||||
luaL_checktype(L,2,LUA_TTABLE);
|
||||
int type = lua_type(L,3);
|
||||
int sz;
|
||||
if (type == LUA_TNUMBER) {
|
||||
sz = lua_tointeger(L,3);
|
||||
} else {
|
||||
size_t len;
|
||||
const uint8_t * s = (const uint8_t *)luaL_checklstring(L, 3, &len);
|
||||
if (len > 4 || len < 1) {
|
||||
return luaL_error(L, "Invalid read %s", s);
|
||||
}
|
||||
int i;
|
||||
sz = 0;
|
||||
for (i=0;i<(int)len;i++) {
|
||||
sz <<= 8;
|
||||
sz |= s[i];
|
||||
}
|
||||
}
|
||||
int sz = luaL_checkinteger(L,3);
|
||||
if (sb->size < sz || sz == 0) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
@@ -485,6 +488,7 @@ luaopen_socketdriver(lua_State *L) {
|
||||
{ "clear", lclearbuffer },
|
||||
{ "readline", lreadline },
|
||||
{ "str2p", lstr2p },
|
||||
{ "header", lheader },
|
||||
|
||||
{ "unpack", lunpack },
|
||||
{ NULL, NULL },
|
||||
|
||||
@@ -266,6 +266,7 @@ end
|
||||
|
||||
socket.write = assert(driver.send)
|
||||
socket.lwrite = assert(driver.lsend)
|
||||
socket.header = assert(driver.header)
|
||||
|
||||
function socket.invalid(id)
|
||||
return socket_pool[id] == nil
|
||||
|
||||
@@ -10,7 +10,7 @@ local node_session = {}
|
||||
local command = {}
|
||||
|
||||
local function read_response(sock)
|
||||
local sz = sock:read(2)
|
||||
local sz = socket.header(sock:read(2))
|
||||
local msg = sock:read(sz)
|
||||
return cluster.unpackresponse(msg) -- session, ok, data
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user