mirror of
https://github.com/nginx/nginx.git
synced 2024-11-23 20:19:02 +08:00
Upstream keepalive: reduced diffs to the plus version of nginx.
This commit is contained in:
parent
e041efc306
commit
f5d79ffb82
@ -22,6 +22,18 @@ typedef struct {
|
||||
} ngx_http_upstream_keepalive_srv_conf_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_http_upstream_keepalive_srv_conf_t *conf;
|
||||
|
||||
ngx_queue_t queue;
|
||||
ngx_connection_t *connection;
|
||||
|
||||
socklen_t socklen;
|
||||
u_char sockaddr[NGX_SOCKADDRLEN];
|
||||
|
||||
} ngx_http_upstream_keepalive_cache_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_http_upstream_keepalive_srv_conf_t *conf;
|
||||
|
||||
@ -40,18 +52,6 @@ typedef struct {
|
||||
} ngx_http_upstream_keepalive_peer_data_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_http_upstream_keepalive_srv_conf_t *conf;
|
||||
|
||||
ngx_queue_t queue;
|
||||
ngx_connection_t *connection;
|
||||
|
||||
socklen_t socklen;
|
||||
u_char sockaddr[NGX_SOCKADDRLEN];
|
||||
|
||||
} ngx_http_upstream_keepalive_cache_t;
|
||||
|
||||
|
||||
static ngx_int_t ngx_http_upstream_init_keepalive_peer(ngx_http_request_t *r,
|
||||
ngx_http_upstream_srv_conf_t *us);
|
||||
static ngx_int_t ngx_http_upstream_get_keepalive_peer(ngx_peer_connection_t *pc,
|
||||
@ -63,7 +63,6 @@ static void ngx_http_upstream_keepalive_dummy_handler(ngx_event_t *ev);
|
||||
static void ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev);
|
||||
static void ngx_http_upstream_keepalive_close(ngx_connection_t *c);
|
||||
|
||||
|
||||
#if (NGX_HTTP_SSL)
|
||||
static ngx_int_t ngx_http_upstream_keepalive_set_session(
|
||||
ngx_peer_connection_t *pc, void *data);
|
||||
@ -244,24 +243,28 @@ ngx_http_upstream_get_keepalive_peer(ngx_peer_connection_t *pc, void *data)
|
||||
ngx_queue_remove(q);
|
||||
ngx_queue_insert_head(&kp->conf->free, q);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
||||
"get keepalive peer: using connection %p", c);
|
||||
|
||||
c->idle = 0;
|
||||
c->sent = 0;
|
||||
c->log = pc->log;
|
||||
c->read->log = pc->log;
|
||||
c->write->log = pc->log;
|
||||
c->pool->log = pc->log;
|
||||
|
||||
pc->connection = c;
|
||||
pc->cached = 1;
|
||||
|
||||
return NGX_DONE;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
|
||||
found:
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
||||
"get keepalive peer: using connection %p", c);
|
||||
|
||||
c->idle = 0;
|
||||
c->sent = 0;
|
||||
c->log = pc->log;
|
||||
c->read->log = pc->log;
|
||||
c->write->log = pc->log;
|
||||
c->pool->log = pc->log;
|
||||
|
||||
pc->connection = c;
|
||||
pc->cached = 1;
|
||||
|
||||
return NGX_DONE;
|
||||
}
|
||||
|
||||
|
||||
@ -322,9 +325,10 @@ ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, void *data,
|
||||
item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue);
|
||||
}
|
||||
|
||||
item->connection = c;
|
||||
ngx_queue_insert_head(&kp->conf->cache, q);
|
||||
|
||||
item->connection = c;
|
||||
|
||||
pc->connection = NULL;
|
||||
|
||||
if (c->read->timer_set) {
|
||||
@ -470,10 +474,9 @@ ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf)
|
||||
*
|
||||
* conf->original_init_upstream = NULL;
|
||||
* conf->original_init_peer = NULL;
|
||||
* conf->max_cached = 0;
|
||||
*/
|
||||
|
||||
conf->max_cached = 1;
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
@ -487,18 +490,10 @@ ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
ngx_int_t n;
|
||||
ngx_str_t *value;
|
||||
|
||||
uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);
|
||||
|
||||
if (kcf->original_init_upstream) {
|
||||
if (kcf->max_cached) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
kcf->original_init_upstream = uscf->peer.init_upstream
|
||||
? uscf->peer.init_upstream
|
||||
: ngx_http_upstream_init_round_robin;
|
||||
|
||||
uscf->peer.init_upstream = ngx_http_upstream_init_keepalive;
|
||||
|
||||
/* read options */
|
||||
|
||||
value = cf->args->elts;
|
||||
@ -514,5 +509,13 @@ ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
|
||||
kcf->max_cached = n;
|
||||
|
||||
uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);
|
||||
|
||||
kcf->original_init_upstream = uscf->peer.init_upstream
|
||||
? uscf->peer.init_upstream
|
||||
: ngx_http_upstream_init_round_robin;
|
||||
|
||||
uscf->peer.init_upstream = ngx_http_upstream_init_keepalive;
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user