-
Notifications
You must be signed in to change notification settings - Fork 2k
add exit_worker_by* feature #927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
712fd57
5d24fa1
d08f950
cc40d62
ab3e195
0dac2a1
b3b3abc
262bb28
59bfe2b
754e555
affda8a
11a0359
0657a39
a598365
2141d4b
d53ad01
b9474bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1208,6 +1208,64 @@ ngx_http_lua_init_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, | |
} | ||
|
||
|
||
char * | ||
ngx_http_lua_exit_worker_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd, | ||
void *conf) | ||
{ | ||
char *rv | ||
ngx_conf_t save; | ||
|
||
save = *cf; | ||
cf->handler = ngx_http_lua_exit_worker_by_lua; | ||
cf->handler_conf = conf; | ||
|
||
rv = ngx_http_lua_conf_lua_block_parse(cf, cmd); | ||
|
||
*cf = save; | ||
|
||
return rv; | ||
} | ||
|
||
char * | ||
ngx_http_lua_exit_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, | ||
void *conf) | ||
{ | ||
u_char *name; | ||
ngx_str_t *value; | ||
ngx_http_lua_main_conf_t *lmcf = conf; | ||
|
||
dd("enter"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better use more meaning use debug message here. people will see this message in the error log when they opened the DDEBUG. |
||
|
||
/* must specify a content handler */ | ||
if (cmd->post == NULL) { | ||
return NGX_CONF_ERROR; | ||
} | ||
|
||
if (lmcf->exit_worker_handler) { | ||
return "is duplicate"; | ||
} | ||
|
||
value = cf->args->elts; | ||
|
||
lmcf->exit_worker_handler = (ngx_http_lua_main_conf_handler_pt) cmd->post; | ||
|
||
if (cmd->pos == ngx_http_lua_exit_worker_by_lua_file) { | ||
name = ngx_http_lua_rebase_path(cf->pool, value[1].data, | ||
value[1].len); | ||
if (name == NULL) { | ||
return NGX_CONF_ERROR; | ||
} | ||
|
||
lmcf->exit_worker_src.data = name; | ||
lmcf->exit_worker_src.len = ngx_strlen(name); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: we need a blank line before the |
||
lmcf->exit_worker_src = value[1]; | ||
} | ||
|
||
return NGX_CONF_OK; | ||
} | ||
|
||
|
||
#if defined(NDK) && NDK | ||
static ngx_int_t | ||
ngx_http_lua_set_by_lua_init(ngx_http_request_t *r) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
/* | ||
* Copyright (C) Xianliang Li | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this patch to merge, you have to grant your copyright to the authors of this module. So please remove this copyright notice comment. |
||
*/ | ||
|
||
|
||
#ifndef DDEBUG | ||
#define DDEBUG 0 | ||
#endif | ||
#include "ddebug.h" | ||
|
||
|
||
#include "ngx_http_lua_exitworkerby.h" | ||
#include "ngx_http_lua_util.h" | ||
|
||
|
||
ngx_int_t | ||
ngx_http_lua_exit_worker(ngx_cycle_t *cycle) | ||
{ | ||
ngx_http_lua_main_conf_t *lmcf; | ||
|
||
lmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_lua_module); | ||
if (lmcf == NULL | ||
|| lmcf->exit_worker_handler == NULL | ||
|| lmcf->lua == NULL) | ||
{ | ||
return NGX_OK; | ||
} | ||
|
||
(void) lmcf->exit_worker_handler(cycle->log, lmcf, lmcf->lua); | ||
|
||
return NGX_OK; | ||
} | ||
|
||
|
||
ngx_int_t | ||
ngx_http_lua_exit_worker_by_inline(ngx_log_t *log, | ||
ngx_http_lua_main_conf_t *lmcf, lua_State *L) | ||
{ | ||
int status; | ||
|
||
status = luaL_loadbuffer(L, (char *) lmcf->exit_worker_src.data, | ||
lmcf->exit_worker_src.len, "=exit_worker_by_lua" | ||
|| ngx_http_lua_do_call(log, L)); | ||
|
||
return ngx_http_lua_report(log, L, status, "exit_worker_by_lua"); | ||
} | ||
|
||
|
||
ngx_int_t | ||
ngx_http_lua_exit_worker_by_file(ngx_log_t *log, | ||
ngx_http_lua_main_conf_t *lmcf, lua_State *L) | ||
{ | ||
int status; | ||
|
||
status = luaL_loadfile(L, (char *) lmcf->exit_worker_src.data) | ||
|| ngx_http_lua_do_call(log, L); | ||
|
||
return ngx_http_lua_report(log, L, status, "exit_worker_by_file"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
/* | ||
* Copyright (C) Xianliang Li | ||
*/ | ||
|
||
|
||
#ifndef _NGX_HTTP_LUA_EXITWORKERBY_H_INCLUDE_ | ||
#define _NGX_HTTP_LUA_EXITWORKERBY_H_INCLUDE_ | ||
|
||
|
||
#include "ngx_http_lua_common.h" | ||
|
||
|
||
ngx_int_t ngx_http_lua_exit_worker_by_inline(ngx_log_t *log, | ||
ngx_http_lua_main_conf_t *lmcf, lua_State *L); | ||
|
||
ngx_int_t ngx_http_lua_exit_worker_by_file(ngx_log_t *log, | ||
ngx_http_lua_main_conf_t *lmcf, lua_State *L); | ||
|
||
ngx_int_t ngx_http_lua_exit_worker(ngx_cycle_t *cycle); | ||
|
||
|
||
#endif /* _NGX_HTTP_LUA_EXITWORKERBY_H_INCLUDE_ */ | ||
|
||
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,27 @@ static ngx_command_t ngx_http_lua_cmds[] = { | |
0, | ||
(void *) ngx_http_lua_init_worker_by_file }, | ||
|
||
{ ngx_string("exit_worker_by_lua_block"), | ||
NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | ||
ngx_http_lua_exit_worker_by_lua_block, | ||
NGX_HTTP_MAIN_CONF_OFFSET, | ||
0, | ||
(void *) ngx_http_lua_exit_worker_by_inline }, | ||
|
||
{ ngx_string("exit_worker_by_lua"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work! I believe the newly added Lua handlers should only use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you would also need to update I believe it will also be requested of you that you introduce tests for this feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i reference to init_worker_by*, there have three method(init_worker_by_lua init_worker_by_lua_block init_worker_by_lua_file) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, on the bright side of things, it's less work for you ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok,thank you. i will add this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newly added directives should only provide the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enen,i will correction this。 |
||
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | ||
ngx_http_lua_exit_worker_by_lua, | ||
NGX_HTTP_MAIN_CONF_OFFSET, | ||
0, | ||
(void *) ngx_http_lua_exit_worker_by_inline }, | ||
|
||
{ ngx_string("exit_worker_by_lua_file"), | ||
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | ||
ngx_http_lua_exit_worker_by_lua, | ||
NGX_HTTP_MAIN_CONF_OFFSET, | ||
0, | ||
(void *) ngx_http_lua_exit_worker_by_file }, | ||
|
||
#if defined(NDK) && NDK | ||
/* set_by_lua $res { inline Lua code } [$arg1 [$arg2 [...]]] */ | ||
{ ngx_string("set_by_lua_block"), | ||
|
Uh oh!
There was an error while loading. Please reload this page.