---
src/ngx_http_lua_sleep.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/src/ngx_http_lua_sleep.c b/src/ngx_http_lua_sleep.c
index 3f03cbb..4977923 100644
--- a/src/ngx_http_lua_sleep.c
+++ b/src/ngx_http_lua_sleep.c
@@ -26,7 +26,6 @@ static ngx_int_t ngx_http_lua_sleep_resume(ngx_http_request_t *r);
static int
ngx_http_lua_ngx_co(lua_State *L)
{
- int index;
ngx_http_request_t *r;
ngx_http_lua_ctx_t *ctx;
ngx_http_lua_co_ctx_t *coctx;
@@ -64,8 +63,9 @@ ngx_http_lua_ngx_co(lua_State *L)
}
wakeup_co->co_ctx = NULL;
wakeup_co->self_ref = luaL_ref(L, -2);
+ coctx->wakeup_co = wakeup_co;
}
- lua_rawgeti(L, -1, wakup_co->self_ref);
+ lua_rawgeti(L, -1, wakeup_co->self_ref);
return 1;
}
@@ -140,9 +140,10 @@ static int
ngx_http_lua_ngx_wakeup(lua_State *L)
{
int n;
+ ngx_int_t rc;
ngx_connection_t *c;
ngx_http_request_t *r;
- lua_State *vm;
+ ngx_http_log_ctx_t *log_ctx;
ngx_http_lua_ctx_t *ctx;
ngx_http_lua_co_ctx_t *coctx;
ngx_http_lua_wakeup_co_t *wakeup_co;
@@ -162,11 +163,6 @@ ngx_http_lua_ngx_wakeup(lua_State *L)
| NGX_HTTP_LUA_CONTEXT_CONTENT
| NGX_HTTP_LUA_CONTEXT_TIMER);
- coctx = ctx->cur_co_ctx;
- if (coctx == NULL) {
- return luaL_error(L, "no co ctx found");
- }
-
n = lua_gettop(L);
if (n == 0) {
return luaL_error(L, "pass 0 arguments, but accepted 1");
@@ -198,7 +194,8 @@ ngx_http_lua_ngx_wakeup(lua_State *L)
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (ctx == NULL) {
- return;
+ lua_pushboolean(L, 0);
+ return 1;
}
ctx->cur_co_ctx = coctx;
@@ -206,10 +203,10 @@ ngx_http_lua_ngx_wakeup(lua_State *L)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"lua sleep wakeuped: \"%V?%V\"", &r->uri, &r->args);
- lua_pop(L, 1);
- lua_pushinteger(L, n - 1);
- lua_xmove(L, ctx->co, n - 1);
- rc = ngx_http_lua_run_thread(L, r, ctx, n - 1);
+ if (--n > 0) {
+ lua_xmove(L, coctx->co, n);
+ }
+ rc = ngx_http_lua_run_thread(L, r, ctx, n);
lua_pushboolean(L, 1);
return 1;
--
1.9.5.msysgit.1