Skip to content

Commit

Permalink
merged meta into master.
Browse files Browse the repository at this point in the history
  • Loading branch information
agentzh committed Oct 26, 2017
2 parents 1853183 + 569c91d commit 8039f7a
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 126 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ install:
- git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module
- git clone https://github.com/openresty/memc-nginx-module.git ../memc-nginx-module
- git clone https://github.com/openresty/headers-more-nginx-module.git ../headers-more-nginx-module
- git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core

script:
- tar zxf download-cache/pcre-$PCRE_VER.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion src/api/ngx_stream_lua_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/* Public API for other Nginx modules */


#define ngx_stream_lua_version 10009
#define ngx_stream_lua_version 10011


typedef struct {
Expand Down
21 changes: 11 additions & 10 deletions src/ngx_stream_lua_balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@

struct ngx_stream_lua_balancer_peer_data_s {
/* the round robin data must be first */
ngx_stream_upstream_rr_peer_data_t rrp;
ngx_stream_upstream_rr_peer_data_t rrp;

ngx_stream_lua_srv_conf_t *conf;
ngx_stream_lua_request_t *request;
ngx_stream_lua_srv_conf_t *conf;
ngx_stream_lua_request_t *request;

ngx_uint_t more_tries;
ngx_uint_t total_tries;
ngx_uint_t more_tries;
ngx_uint_t total_tries;

struct sockaddr *sockaddr;
socklen_t socklen;
struct sockaddr *sockaddr;
socklen_t socklen;

ngx_str_t *host;
in_port_t port;
ngx_str_t *host;
in_port_t port;

int last_peer_state;
int last_peer_state;

};

Expand Down Expand Up @@ -259,6 +259,7 @@ ngx_stream_lua_balancer_init_peer(ngx_stream_session_t *s,
}

upstream->peer.data = &bp->rrp;

if (ngx_stream_upstream_init_round_robin_peer(s, us) != NGX_OK) {
return NGX_ERROR;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ngx_stream_lua_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ struct ngx_stream_lua_srv_conf_s {
ngx_stream_complex_value_t log_src; /* log_by_lua inline script/script
file path */

u_char *log_src_key; /* cached key for log_src */
u_char *log_src_key;
/* cached key for log_src */



Expand Down
2 changes: 1 addition & 1 deletion src/ngx_stream_lua_directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ ngx_stream_lua_conf_read_lua_token(ngx_conf_t *cf,

#if nginx_version >= 1009002
if (dump) {
dump->last = ngx_cpymem(dump->last, b->pos, size);
dump->last = ngx_cpymem(dump->last, b->start + len, size);
}
#endif
}
Expand Down
32 changes: 21 additions & 11 deletions src/ngx_stream_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ static ngx_command_t ngx_stream_lua_cmds[] = {
NULL },

{ ngx_string("lua_code_cache"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_FLAG,
ngx_stream_lua_code_cache,

NGX_STREAM_SRV_CONF_OFFSET,
Expand All @@ -137,7 +138,8 @@ static ngx_command_t ngx_stream_lua_cmds[] = {


{ ngx_string("lua_socket_log_errors"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,

NGX_STREAM_SRV_CONF_OFFSET,
Expand Down Expand Up @@ -273,49 +275,56 @@ static ngx_command_t ngx_stream_lua_cmds[] = {


{ ngx_string("lua_socket_keepalive_timeout"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, keepalive_timeout),
NULL },

{ ngx_string("lua_socket_connect_timeout"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, connect_timeout),
NULL },

{ ngx_string("lua_socket_send_timeout"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, send_timeout),
NULL },

{ ngx_string("lua_socket_send_lowat"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, send_lowat),
&ngx_stream_lua_lowat_post },

{ ngx_string("lua_socket_buffer_size"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, buffer_size),
NULL },

{ ngx_string("lua_socket_pool_size"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, pool_size),
NULL },

{ ngx_string("lua_socket_read_timeout"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, read_timeout),
Expand All @@ -324,7 +333,8 @@ static ngx_command_t ngx_stream_lua_cmds[] = {


{ ngx_string("lua_check_client_abort"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF
|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_lua_srv_conf_t, check_client_abort),
Expand Down Expand Up @@ -715,10 +725,10 @@ ngx_stream_lua_create_srv_conf(ngx_conf_t *cf)
static char *
ngx_stream_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
{

ngx_stream_lua_srv_conf_t *prev = parent;
ngx_stream_lua_srv_conf_t *conf = child;



#if (NGX_STREAM_SSL)

Expand Down
7 changes: 5 additions & 2 deletions src/ngx_stream_lua_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ ngx_stream_lua_flush_resume_helper(ngx_stream_lua_request_t *r, ngx_stream_lua_c
int n;
lua_State *vm;
ngx_int_t rc;
ngx_uint_t nreqs;
ngx_connection_t *c;

c = r->connection;
Expand All @@ -684,18 +685,20 @@ ngx_stream_lua_flush_resume_helper(ngx_stream_lua_request_t *r, ngx_stream_lua_c
}

vm = ngx_stream_lua_get_lua_vm(r, ctx);
nreqs = c->requests;

rc = ngx_stream_lua_run_thread(vm, r, ctx, n);

ngx_log_debug1(NGX_LOG_DEBUG_STREAM, r->connection->log, 0,
"lua run thread returned %d", rc);

if (rc == NGX_AGAIN) {
return ngx_stream_lua_run_posted_threads(c, vm, r, ctx);
return ngx_stream_lua_run_posted_threads(c, vm, r, ctx, nreqs);
}

if (rc == NGX_DONE) {
ngx_stream_lua_finalize_request(r, NGX_DONE);
return ngx_stream_lua_run_posted_threads(c, vm, r, ctx);
return ngx_stream_lua_run_posted_threads(c, vm, r, ctx, nreqs);
}

/* rc == NGX_ERROR || rc >= NGX_OK */
Expand Down
4 changes: 2 additions & 2 deletions src/ngx_stream_lua_prereadby.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ ngx_stream_lua_preread_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
c = r->connection;

if (rc == NGX_AGAIN) {
rc = ngx_stream_lua_run_posted_threads(c, L, r, ctx);
rc = ngx_stream_lua_run_posted_threads(c, L, r, ctx, 0);

if (rc == NGX_ERROR || rc == NGX_DONE || rc > NGX_OK) {
return rc;
Expand All @@ -264,7 +264,7 @@ ngx_stream_lua_preread_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
} else if (rc == NGX_DONE) {
ngx_stream_lua_finalize_request(r, NGX_DONE);

rc = ngx_stream_lua_run_posted_threads(c, L, r, ctx);
rc = ngx_stream_lua_run_posted_threads(c, L, r, ctx, 0);

if (rc == NGX_ERROR || rc == NGX_DONE || rc > NGX_OK) {
return rc;
Expand Down
13 changes: 8 additions & 5 deletions src/ngx_stream_lua_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,20 @@ ngx_stream_lua_finalize_real_request(ngx_stream_lua_request_t *r, ngx_int_t rc)

s = r->session;

if (rc == NGX_DECLINED) {
if (rc == NGX_ERROR) {
rc = NGX_STREAM_INTERNAL_SERVER_ERROR;
}

if (rc == NGX_DECLINED || rc == NGX_STREAM_INTERNAL_SERVER_ERROR) {
goto cleanup;
}

if (rc == NGX_DONE) {
return;
}

if (rc == NGX_ERROR) {
rc = NGX_STREAM_INTERNAL_SERVER_ERROR;
goto cleanup;
if (rc == NGX_OK) {
rc = NGX_STREAM_OK;
}

if (r->connection->buffered) {
Expand Down Expand Up @@ -215,7 +218,7 @@ ngx_stream_lua_finalize_real_request(ngx_stream_lua_request_t *r, ngx_int_t rc)
ngx_destroy_pool(pool);
#endif

ngx_stream_finalize_session(s, NGX_STREAM_OK);
ngx_stream_finalize_session(s, rc);
return;
}

Expand Down
Loading

0 comments on commit 8039f7a

Please sign in to comment.