Latest update - 7505

This commit is contained in:
2019-04-25 08:30:35 +09:00
parent 7564cabbbe
commit dd71767aff
12 changed files with 215 additions and 56 deletions
+17 -12
View File
@@ -24,8 +24,8 @@ typedef struct {
ngx_msec_t timeout;
ngx_msec_t next_upstream_timeout;
size_t buffer_size;
size_t upload_rate;
size_t download_rate;
ngx_stream_complex_value_t *upload_rate;
ngx_stream_complex_value_t *download_rate;
ngx_uint_t requests;
ngx_uint_t responses;
ngx_uint_t next_upstream_tries;
@@ -184,14 +184,14 @@ static ngx_command_t ngx_stream_proxy_commands[] = {
{ ngx_string("proxy_upload_rate"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
ngx_stream_set_complex_value_size_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_proxy_srv_conf_t, upload_rate),
NULL },
{ ngx_string("proxy_download_rate"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
ngx_stream_set_complex_value_size_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_proxy_srv_conf_t, download_rate),
NULL },
@@ -895,6 +895,9 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
u->proxy_protocol = 0;
}
u->upload_rate = ngx_stream_complex_value_size(s, pscf->upload_rate, 0);
u->download_rate = ngx_stream_complex_value_size(s, pscf->download_rate, 0);
u->connected = 1;
pc->read->handler = ngx_stream_proxy_upstream_handler;
@@ -1532,7 +1535,7 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
src = pc;
dst = c;
b = &u->upstream_buf;
limit_rate = pscf->download_rate;
limit_rate = u->download_rate;
received = &u->received;
packets = &u->responses;
out = &u->downstream_out;
@@ -1544,7 +1547,7 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
src = c;
dst = pc;
b = &u->downstream_buf;
limit_rate = pscf->upload_rate;
limit_rate = u->upload_rate;
received = &s->received;
packets = &u->requests;
out = &u->upstream_out;
@@ -1955,6 +1958,8 @@ ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf)
* conf->ssl_certificate = { 0, NULL };
* conf->ssl_certificate_key = { 0, NULL };
*
* conf->upload_rate = NULL;
* conf->download_rate = NULL;
* conf->ssl = NULL;
* conf->upstream = NULL;
* conf->upstream_value = NULL;
@@ -1964,8 +1969,6 @@ ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf)
conf->timeout = NGX_CONF_UNSET_MSEC;
conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC;
conf->buffer_size = NGX_CONF_UNSET_SIZE;
conf->upload_rate = NGX_CONF_UNSET_SIZE;
conf->download_rate = NGX_CONF_UNSET_SIZE;
conf->requests = NGX_CONF_UNSET_UINT;
conf->responses = NGX_CONF_UNSET_UINT;
conf->next_upstream_tries = NGX_CONF_UNSET_UINT;
@@ -2005,11 +2008,13 @@ ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_size_value(conf->buffer_size,
prev->buffer_size, 16384);
ngx_conf_merge_size_value(conf->upload_rate,
prev->upload_rate, 0);
if (conf->upload_rate == NULL) {
conf->upload_rate = prev->upload_rate;
}
ngx_conf_merge_size_value(conf->download_rate,
prev->download_rate, 0);
if (conf->download_rate == NULL) {
conf->download_rate = prev->download_rate;
}
ngx_conf_merge_uint_value(conf->requests,
prev->requests, 0);
+61
View File
@@ -105,6 +105,37 @@ ngx_stream_complex_value(ngx_stream_session_t *s,
}
size_t
ngx_stream_complex_value_size(ngx_stream_session_t *s,
ngx_stream_complex_value_t *val, size_t default_value)
{
size_t size;
ngx_str_t value;
if (val == NULL) {
return default_value;
}
if (val->lengths == NULL) {
return val->u.size;
}
if (ngx_stream_complex_value(s, val, &value) != NGX_OK) {
return default_value;
}
size = ngx_parse_size(&value);
if (size == (size_t) NGX_ERROR) {
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
"invalid size \"%V\"", &value);
return default_value;
}
return size;
}
ngx_int_t
ngx_stream_compile_complex_value(ngx_stream_compile_complex_value_t *ccv)
{
@@ -246,6 +277,36 @@ ngx_stream_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
}
char *
ngx_stream_set_complex_value_size_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
char *p = conf;
char *rv;
ngx_stream_complex_value_t *cv;
rv = ngx_stream_set_complex_value_slot(cf, cmd, conf);
if (rv != NGX_CONF_OK) {
return rv;
}
cv = *(ngx_stream_complex_value_t **) (p + cmd->offset);
if (cv->lengths) {
return NGX_CONF_OK;
}
cv->u.size = ngx_parse_size(&cv->value);
if (cv->u.size == (size_t) NGX_ERROR) {
return "invalid value";
}
return NGX_CONF_OK;
}
ngx_uint_t
ngx_stream_script_variables_count(ngx_str_t *value)
{
+8
View File
@@ -56,6 +56,10 @@ typedef struct {
ngx_uint_t *flushes;
void *lengths;
void *values;
union {
size_t size;
} u;
} ngx_stream_complex_value_t;
@@ -102,10 +106,14 @@ void ngx_stream_script_flush_complex_value(ngx_stream_session_t *s,
ngx_stream_complex_value_t *val);
ngx_int_t ngx_stream_complex_value(ngx_stream_session_t *s,
ngx_stream_complex_value_t *val, ngx_str_t *value);
size_t ngx_stream_complex_value_size(ngx_stream_session_t *s,
ngx_stream_complex_value_t *val, size_t default_value);
ngx_int_t ngx_stream_compile_complex_value(
ngx_stream_compile_complex_value_t *ccv);
char *ngx_stream_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
char *ngx_stream_set_complex_value_size_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
ngx_uint_t ngx_stream_script_variables_count(ngx_str_t *value);
+3
View File
@@ -132,6 +132,9 @@ typedef struct {
ngx_uint_t responses;
ngx_msec_t start_time;
size_t upload_rate;
size_t download_rate;
ngx_str_t ssl_name;
ngx_stream_upstream_srv_conf_t *upstream;