changeset 31:78fd926c306d

Keepalive: reduce indentation, no functional changes.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 31 Aug 2011 06:03:30 +0400
parents c5b498c5aa3c
children 9aa0d263f2a7
files ngx_http_upstream_keepalive_module.c
diffstat 1 files changed, 59 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/ngx_http_upstream_keepalive_module.c
+++ b/ngx_http_upstream_keepalive_module.c
@@ -296,7 +296,9 @@ ngx_http_upstream_free_keepalive_peer(ng
     ngx_http_upstream_keepalive_peer_data_t  *kp = data;
     ngx_http_upstream_keepalive_cache_t      *item;
 
+#if !(NGX_UPSTREAM_KEEPALIVE_PATCHED)
     ngx_uint_t            status;
+#endif
     ngx_queue_t          *q;
     ngx_connection_t     *c;
     ngx_http_upstream_t  *u;
@@ -324,64 +326,77 @@ ngx_http_upstream_free_keepalive_peer(ng
 
     u = kp->upstream;
     c = pc->connection;
+
+    if (kp->failed
+        || c == NULL
+        || c->read->timedout
+        || c->write->timedout)
+    {
+        goto invalid;
+    }
+
+#if (NGX_UPSTREAM_KEEPALIVE_PATCHED)
+
+    if (!u->keepalive) {
+        goto invalid;
+    }
+
+#else
+
     status = u->headers_in.status_n;
 
-    if (!kp->failed
-        && c != NULL
-        && !c->read->timedout
-        && !c->write->timedout
-#if (NGX_UPSTREAM_KEEPALIVE_PATCHED)
-        && u->keepalive)
-#else
-        && (status == NGX_HTTP_NOT_FOUND
-            || (status == NGX_HTTP_OK && u->header_sent && u->length == 0)))
+    if (!(status == NGX_HTTP_NOT_FOUND
+          || (status == NGX_HTTP_OK && u->header_sent && u->length == 0)))
+    {
+        goto invalid;
+    }
+
 #endif
-    {
-        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
-                       "free keepalive peer: saving connection %p", c);
+
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
+                   "free keepalive peer: saving connection %p", c);
 
-        if (ngx_queue_empty(&kp->conf->free)) {
+    if (ngx_queue_empty(&kp->conf->free)) {
 
-            q = ngx_queue_last(&kp->conf->cache);
-            ngx_queue_remove(q);
+        q = ngx_queue_last(&kp->conf->cache);
+        ngx_queue_remove(q);
 
-            item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t,
-                                  queue);
+        item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue);
+
+        ngx_close_connection(item->connection);
 
-            ngx_close_connection(item->connection);
-
-        } else {
-            q = ngx_queue_head(&kp->conf->free);
-            ngx_queue_remove(q);
+    } else {
+        q = ngx_queue_head(&kp->conf->free);
+        ngx_queue_remove(q);
 
-            item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t,
-                                  queue);
-        }
+        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;
+    ngx_queue_insert_head(&kp->conf->cache, q);
 
-        pc->connection = NULL;
+    pc->connection = NULL;
 
-        if (c->read->timer_set) {
-            ngx_del_timer(c->read);
-        }
-        if (c->write->timer_set) {
-            ngx_del_timer(c->write);
-        }
+    if (c->read->timer_set) {
+        ngx_del_timer(c->read);
+    }
+    if (c->write->timer_set) {
+        ngx_del_timer(c->write);
+    }
 
-        c->write->handler = ngx_http_upstream_keepalive_dummy_handler;
-        c->read->handler = ngx_http_upstream_keepalive_close_handler;
+    c->write->handler = ngx_http_upstream_keepalive_dummy_handler;
+    c->read->handler = ngx_http_upstream_keepalive_close_handler;
 
-        c->data = item;
-        c->idle = 1;
-        c->log = ngx_cycle->log;
-        c->read->log = ngx_cycle->log;
-        c->write->log = ngx_cycle->log;
+    c->data = item;
+    c->idle = 1;
+    c->log = ngx_cycle->log;
+    c->read->log = ngx_cycle->log;
+    c->write->log = ngx_cycle->log;
 
-        item->socklen = pc->socklen;
-        ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
-    }
+    item->socklen = pc->socklen;
+    ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
+
+invalid:
 
     return kp->original_free_peer(pc, kp->data, state);
 }