mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +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)
|
v0.3.1 (2014-6-16)
|
||||||
-----------
|
-----------
|
||||||
* Bugfix: lua mongo driver . Hold reply string before decode bson data.
|
* Bugfix: lua mongo driver . Hold reply string before decode bson data.
|
||||||
|
|||||||
@@ -153,6 +153,8 @@ lunpackrequest(lua_State *L) {
|
|||||||
static int
|
static int
|
||||||
lpackresponse(lua_State *L) {
|
lpackresponse(lua_State *L) {
|
||||||
uint32_t session = luaL_checkunsigned(L,1);
|
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);
|
void * msg = lua_touserdata(L,2);
|
||||||
size_t sz = luaL_checkunsigned(L, 3);
|
size_t sz = luaL_checkunsigned(L, 3);
|
||||||
|
|
||||||
@@ -161,8 +163,6 @@ lpackresponse(lua_State *L) {
|
|||||||
fill_uint32(buf+2, session);
|
fill_uint32(buf+2, session);
|
||||||
memcpy(buf+6,msg,sz);
|
memcpy(buf+6,msg,sz);
|
||||||
|
|
||||||
skynet_free(msg);
|
|
||||||
|
|
||||||
lua_pushlstring(L, (const char *)buf, sz+6);
|
lua_pushlstring(L, (const char *)buf, sz+6);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -188,10 +188,29 @@ pop_lstring(lua_State *L, struct socket_buffer *sb, int sz, int skip) {
|
|||||||
luaL_pushresult(&b);
|
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
|
userdata send_buffer
|
||||||
table pool
|
table pool
|
||||||
integer sz or string (big endian)
|
integer sz
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
lpopbuffer(lua_State *L) {
|
lpopbuffer(lua_State *L) {
|
||||||
@@ -200,23 +219,7 @@ lpopbuffer(lua_State *L) {
|
|||||||
return luaL_error(L, "Need buffer object at param 1");
|
return luaL_error(L, "Need buffer object at param 1");
|
||||||
}
|
}
|
||||||
luaL_checktype(L,2,LUA_TTABLE);
|
luaL_checktype(L,2,LUA_TTABLE);
|
||||||
int type = lua_type(L,3);
|
int sz = luaL_checkinteger(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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sb->size < sz || sz == 0) {
|
if (sb->size < sz || sz == 0) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
} else {
|
} else {
|
||||||
@@ -485,6 +488,7 @@ luaopen_socketdriver(lua_State *L) {
|
|||||||
{ "clear", lclearbuffer },
|
{ "clear", lclearbuffer },
|
||||||
{ "readline", lreadline },
|
{ "readline", lreadline },
|
||||||
{ "str2p", lstr2p },
|
{ "str2p", lstr2p },
|
||||||
|
{ "header", lheader },
|
||||||
|
|
||||||
{ "unpack", lunpack },
|
{ "unpack", lunpack },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ end
|
|||||||
|
|
||||||
socket.write = assert(driver.send)
|
socket.write = assert(driver.send)
|
||||||
socket.lwrite = assert(driver.lsend)
|
socket.lwrite = assert(driver.lsend)
|
||||||
|
socket.header = assert(driver.header)
|
||||||
|
|
||||||
function socket.invalid(id)
|
function socket.invalid(id)
|
||||||
return socket_pool[id] == nil
|
return socket_pool[id] == nil
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ local node_session = {}
|
|||||||
local command = {}
|
local command = {}
|
||||||
|
|
||||||
local function read_response(sock)
|
local function read_response(sock)
|
||||||
local sz = sock:read(2)
|
local sz = socket.header(sock:read(2))
|
||||||
local msg = sock:read(sz)
|
local msg = sock:read(sz)
|
||||||
return cluster.unpackresponse(msg) -- session, ok, data
|
return cluster.unpackresponse(msg) -- session, ok, data
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user