Mercurial > hg > ngx_http_upstream_keepalive
comparison ngx_http_upstream_keepalive_module.c @ 32:9aa0d263f2a7
Keepalive: ssl connection handling.
Don't cache ssl connections if it uses the same pool as request (i.e. we
don't have experimental patches). Properly close ssl connections if cached.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 31 Aug 2011 12:10:18 +0400 |
parents | 78fd926c306d |
children | 52ca695446d3 |
comparison
equal
deleted
inserted
replaced
31:78fd926c306d | 32:9aa0d263f2a7 |
---|---|
61 static void ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, | 61 static void ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, |
62 void *data, ngx_uint_t state); | 62 void *data, ngx_uint_t state); |
63 | 63 |
64 static void ngx_http_upstream_keepalive_dummy_handler(ngx_event_t *ev); | 64 static void ngx_http_upstream_keepalive_dummy_handler(ngx_event_t *ev); |
65 static void ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev); | 65 static void ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev); |
66 static void ngx_http_upstream_keepalive_close(ngx_connection_t *c); | |
67 | |
66 | 68 |
67 #if (NGX_HTTP_SSL) | 69 #if (NGX_HTTP_SSL) |
68 static ngx_int_t ngx_http_upstream_keepalive_set_session( | 70 static ngx_int_t ngx_http_upstream_keepalive_set_session( |
69 ngx_peer_connection_t *pc, void *data); | 71 ngx_peer_connection_t *pc, void *data); |
70 static void ngx_http_upstream_keepalive_save_session(ngx_peer_connection_t *pc, | 72 static void ngx_http_upstream_keepalive_save_session(ngx_peer_connection_t *pc, |
237 | 239 |
238 c->idle = 0; | 240 c->idle = 0; |
239 c->log = pc->log; | 241 c->log = pc->log; |
240 c->read->log = pc->log; | 242 c->read->log = pc->log; |
241 c->write->log = pc->log; | 243 c->write->log = pc->log; |
244 #if (NGX_UPSTREAM_KEEPALIVE_PATCHED) | |
245 c->pool->log = pc->log; | |
246 #endif | |
242 | 247 |
243 pc->connection = c; | 248 pc->connection = c; |
244 pc->cached = 1; | 249 pc->cached = 1; |
245 | 250 |
246 return NGX_DONE; | 251 return NGX_DONE; |
275 | 280 |
276 c->idle = 0; | 281 c->idle = 0; |
277 c->log = pc->log; | 282 c->log = pc->log; |
278 c->read->log = pc->log; | 283 c->read->log = pc->log; |
279 c->write->log = pc->log; | 284 c->write->log = pc->log; |
285 #if (NGX_UPSTREAM_KEEPALIVE_PATCHED) | |
286 c->pool->log = pc->log; | |
287 #endif | |
280 | 288 |
281 pc->connection = c; | 289 pc->connection = c; |
282 pc->cached = 1; | 290 pc->cached = 1; |
283 | 291 |
284 return NGX_DONE; | 292 return NGX_DONE; |
349 || (status == NGX_HTTP_OK && u->header_sent && u->length == 0))) | 357 || (status == NGX_HTTP_OK && u->header_sent && u->length == 0))) |
350 { | 358 { |
351 goto invalid; | 359 goto invalid; |
352 } | 360 } |
353 | 361 |
362 /* | |
363 * to cache ssl connections separate pool for peer connection is | |
364 * required, which is only available with patches | |
365 */ | |
366 | |
367 if (c->ssl) { | |
368 goto invalid; | |
369 } | |
370 | |
354 #endif | 371 #endif |
355 | 372 |
356 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | 373 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
357 "free keepalive peer: saving connection %p", c); | 374 "free keepalive peer: saving connection %p", c); |
358 | 375 |
361 q = ngx_queue_last(&kp->conf->cache); | 378 q = ngx_queue_last(&kp->conf->cache); |
362 ngx_queue_remove(q); | 379 ngx_queue_remove(q); |
363 | 380 |
364 item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); | 381 item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); |
365 | 382 |
366 ngx_close_connection(item->connection); | 383 ngx_http_upstream_keepalive_close(item->connection); |
367 | 384 |
368 } else { | 385 } else { |
369 q = ngx_queue_head(&kp->conf->free); | 386 q = ngx_queue_head(&kp->conf->free); |
370 ngx_queue_remove(q); | 387 ngx_queue_remove(q); |
371 | 388 |
390 c->data = item; | 407 c->data = item; |
391 c->idle = 1; | 408 c->idle = 1; |
392 c->log = ngx_cycle->log; | 409 c->log = ngx_cycle->log; |
393 c->read->log = ngx_cycle->log; | 410 c->read->log = ngx_cycle->log; |
394 c->write->log = ngx_cycle->log; | 411 c->write->log = ngx_cycle->log; |
412 #if (NGX_UPSTREAM_KEEPALIVE_PATCHED) | |
413 c->pool->log = ngx_cycle->log; | |
414 #endif | |
395 | 415 |
396 item->socklen = pc->socklen; | 416 item->socklen = pc->socklen; |
397 ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen); | 417 ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen); |
398 | 418 |
399 invalid: | 419 invalid: |
444 close: | 464 close: |
445 | 465 |
446 item = c->data; | 466 item = c->data; |
447 conf = item->conf; | 467 conf = item->conf; |
448 | 468 |
469 ngx_http_upstream_keepalive_close(c); | |
470 | |
449 ngx_queue_remove(&item->queue); | 471 ngx_queue_remove(&item->queue); |
450 ngx_close_connection(item->connection); | |
451 ngx_queue_insert_head(&conf->free, &item->queue); | 472 ngx_queue_insert_head(&conf->free, &item->queue); |
473 } | |
474 | |
475 | |
476 static void | |
477 ngx_http_upstream_keepalive_close(ngx_connection_t *c) | |
478 { | |
479 | |
480 #if (NGX_HTTP_SSL) | |
481 | |
482 if (c->ssl) { | |
483 c->ssl->no_wait_shutdown = 1; | |
484 c->ssl->no_send_shutdown = 1; | |
485 | |
486 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
487 c->ssl->handler = ngx_http_upstream_keepalive_close; | |
488 return; | |
489 } | |
490 } | |
491 | |
492 #endif | |
493 | |
494 #if (NGX_UPSTREAM_KEEPALIVE_PATCHED) | |
495 ngx_destroy_pool(c->pool); | |
496 #endif | |
497 ngx_close_connection(c); | |
452 } | 498 } |
453 | 499 |
454 | 500 |
455 #if (NGX_HTTP_SSL) | 501 #if (NGX_HTTP_SSL) |
456 | 502 |