Mercurial > hg > ngx_http_upstream_keepalive
comparison ngx_http_upstream_keepalive_module.c @ 3:42e64900483b
Keepalive: always save connections to cache.
Free last recently used one if there is not enough room.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 23 Oct 2008 19:11:15 +0400 |
parents | 8545bbda9e4b |
children | e18e4613b841 |
comparison
equal
deleted
inserted
replaced
2:8545bbda9e4b | 3:42e64900483b |
---|---|
222 | 222 |
223 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, | 223 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
224 "free keepalive peer"); | 224 "free keepalive peer"); |
225 | 225 |
226 if (!(state & NGX_PEER_FAILED) | 226 if (!(state & NGX_PEER_FAILED) |
227 && pc->connection != NULL | 227 && pc->connection != NULL) |
228 && !ngx_queue_empty(&kp->conf->free)) | |
229 { | 228 { |
230 c = pc->connection; | 229 c = pc->connection; |
231 | 230 |
232 q = ngx_queue_head(&kp->conf->free); | 231 if (ngx_queue_empty(&kp->conf->free)) { |
233 ngx_queue_remove(q); | 232 |
234 | 233 q = ngx_queue_last(&kp->conf->cache); |
235 item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); | 234 ngx_queue_remove(q); |
235 | |
236 item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, | |
237 queue); | |
238 | |
239 ngx_close_connection(item->connection); | |
240 | |
241 } else { | |
242 q = ngx_queue_head(&kp->conf->free); | |
243 ngx_queue_remove(q); | |
244 | |
245 item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, | |
246 queue); | |
247 } | |
248 | |
236 item->connection = c; | 249 item->connection = c; |
237 | |
238 ngx_queue_insert_head(&kp->conf->cache, q); | 250 ngx_queue_insert_head(&kp->conf->cache, q); |
239 | 251 |
240 pc->connection = NULL; | 252 pc->connection = NULL; |
241 | 253 |
242 if (c->read->timer_set) { | 254 if (c->read->timer_set) { |