From 1d8ca31d55bd64a4650f6df1546e180a5e60a35c Mon Sep 17 00:00:00 2001 From: niuys Date: Tue, 21 Oct 2014 16:34:25 +0800 Subject: [PATCH] message sequence wrong for queue When the lua state yield in "more queue" proceeding, "data" comes, it should wait in queue, not immediatly do message process. --- lualib-src/lua-netpack.c | 41 +++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lualib-src/lua-netpack.c b/lualib-src/lua-netpack.c index 4012c9bce..1e2ad6328 100644 --- a/lualib-src/lua-netpack.c +++ b/lualib-src/lua-netpack.c @@ -240,12 +240,19 @@ filter_data_(lua_State *L, int fd, uint8_t * buffer, int size) { buffer += need; size -= need; if (size == 0) { - lua_pushvalue(L, lua_upvalueindex(TYPE_DATA)); - lua_pushinteger(L, fd); - lua_pushlightuserdata(L, uc->pack.buffer); - lua_pushinteger(L, uc->pack.size); - skynet_free(uc); - return 5; + if (q == NULL || q->head == q->tail ) { + lua_pushvalue(L, lua_upvalueindex(TYPE_DATA)); + lua_pushinteger(L, fd); + lua_pushlightuserdata(L, uc->pack.buffer); + lua_pushinteger(L, uc->pack.size); + skynet_free(uc); + return 5; + } + else{ + push_data(L, fd, uc->pack.buffer, uc->pack.size, 0); + skynet_free(uc); + return 1; + } } // more data push_data(L, fd, uc->pack.buffer, uc->pack.size, 0); @@ -274,13 +281,21 @@ filter_data_(lua_State *L, int fd, uint8_t * buffer, int size) { } if (size == pack_size) { // just one package - lua_pushvalue(L, lua_upvalueindex(TYPE_DATA)); - lua_pushinteger(L, fd); - void * result = skynet_malloc(pack_size); - memcpy(result, buffer, size); - lua_pushlightuserdata(L, result); - lua_pushinteger(L, size); - return 5; + if ( q == NULL || q->head == q->tail) { + lua_pushvalue(L, lua_upvalueindex(TYPE_DATA)); + lua_pushinteger(L, fd); + void * result = skynet_malloc(pack_size); + memcpy(result, buffer, size); + lua_pushlightuserdata(L, result); + lua_pushinteger(L, size); + return 5; + } + else{ + push_data(L, fd, buffer, pack_size, 1); + buffer += pack_size; + size -= pack_size; + return 1; + } } // more data push_data(L, fd, buffer, pack_size, 1);