---
src/ngx_http_lua_sleep.c | 51 ++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/src/ngx_http_lua_sleep.c b/src/ngx_http_lua_sleep.c
index 4365e19..3f03cbb 100644
--- a/src/ngx_http_lua_sleep.c
+++ b/src/ngx_http_lua_sleep.c
@@ -93,7 +93,8 @@ ngx_http_lua_ngx_sleep(lua_State *L)
} else if ( n == 0 ) {
delay = -1;
} else {
- return luaL_error(L, "attempt to pass %d arguments, but accepted 1", n);
+ return luaL_error(L, "attempt to pass %d arguments, but accepted 1",
+ n);
}
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
@@ -141,6 +142,7 @@ ngx_http_lua_ngx_wakeup(lua_State *L)
int n;
ngx_connection_t *c;
ngx_http_request_t *r;
+ lua_State *vm;
ngx_http_lua_ctx_t *ctx;
ngx_http_lua_co_ctx_t *coctx;
ngx_http_lua_wakeup_co_t *wakeup_co;
@@ -166,13 +168,13 @@ ngx_http_lua_ngx_wakeup(lua_State *L)
}
n = lua_gettop(L);
- if (n != 1) {
- return luaL_error(L, "attempt to pass %d arguments, but accepted 1", n);
+ if (n == 0) {
+ return luaL_error(L, "pass 0 arguments, but accepted 1");
}
wakeup_co = (ngx_http_lua_wakeup_co_t*) lua_touserdata(L, 1);
if (wakeup_co == NULL) {
- return luaL_error(L, "only accept userdata returned by ngx.co");
+ return luaL_error(L, "argument 1 only accept value returned by co()");
}
coctx = wakeup_co->co_ctx;
@@ -181,41 +183,34 @@ ngx_http_lua_ngx_wakeup(lua_State *L)
return 1;
}
- coctx->wakeup_co->co_ctx = NULL;
-
- r = coctx->data;
- c = r->connection;
-
- ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
-
- if (ctx == NULL) {
- return;
- }
-
+ coctx->cleanup = NULL;
+ wakeup_co->co_ctx = NULL;
if (coctx->sleep.timer_set) {
ngx_del_timer(&coctx->sleep);
}
+ r = coctx->data;
+ c = r->connection;
if (c->fd != -1) { /* not a fake connection */
log_ctx = c->log->data;
log_ctx->current_request = r;
}
- coctx->cleanup = NULL;
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
+ if (ctx == NULL) {
+ return;
+ }
+ ctx->cur_co_ctx = coctx;
+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"lua sleep wakeuped: \"%V?%V\"", &r->uri, &r->args);
- ctx->cur_co_ctx = coctx;
+ 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 (ctx->entered_content_phase) {
- (void) ngx_http_lua_sleep_resume(r);
-
- } else {
- ctx->resume_handler = ngx_http_lua_sleep_resume;
- ngx_http_core_run_phases(r);
- }
-
lua_pushboolean(L, 1);
return 1;
}
@@ -274,6 +269,12 @@ ngx_http_lua_inject_sleep_api(lua_State *L)
{
lua_pushcfunction(L, ngx_http_lua_ngx_sleep);
lua_setfield(L, -2, "sleep");
+
+ lua_pushcfunction(L, ngx_http_lua_ngx_co);
+ lua_setfield(L, -2, "co");
+
+ lua_pushcfunction(L, ngx_http_lua_ngx_wakeup);
+ lua_setfield(L, -2, "wakeup");
}
--
1.9.5.msysgit.1