]> git.kaiwu.me - nginx.git/commitdiff
Use ngx_chain_get_free_buf() in pipe input filters.
authorValentin Bartenev <vbart@nginx.com>
Wed, 11 Dec 2013 17:30:38 +0000 (21:30 +0400)
committerValentin Bartenev <vbart@nginx.com>
Wed, 11 Dec 2013 17:30:38 +0000 (21:30 +0400)
No functional changes.

src/event/ngx_event_pipe.c
src/http/modules/ngx_http_fastcgi_module.c
src/http/modules/ngx_http_proxy_module.c

index 6f685a9ed2903327de0c7487321e3aeb706eaef9..eed807d61b82d3c02734c7683559cd3e9f27a104 100644 (file)
@@ -857,19 +857,13 @@ ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
         return NGX_OK;
     }
 
-    if (p->free) {
-        cl = p->free;
-        b = cl->buf;
-        p->free = cl->next;
-        ngx_free_chain(p->pool, cl);
-
-    } else {
-        b = ngx_alloc_buf(p->pool);
-        if (b == NULL) {
-            return NGX_ERROR;
-        }
+    cl = ngx_chain_get_free_buf(p->pool, &p->free);
+    if (cl == NULL) {
+        return NGX_ERROR;
     }
 
+    b = cl->buf;
+
     ngx_memcpy(b, buf, sizeof(ngx_buf_t));
     b->shadow = buf;
     b->tag = p->tag;
@@ -877,14 +871,6 @@ ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
     b->recycled = 1;
     buf->shadow = b;
 
-    cl = ngx_alloc_chain_link(p->pool);
-    if (cl == NULL) {
-        return NGX_ERROR;
-    }
-
-    cl->buf = b;
-    cl->next = NULL;
-
     ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num);
 
     if (p->in) {
index 4cbe51c61c313b37bd3028194ff4b80a6ee42f60..5bcf6ef8c7a90d524f894f1e089fa0d286394146 100644 (file)
@@ -1827,19 +1827,13 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
             break;
         }
 
-        if (p->free) {
-            cl = p->free;
-            b = cl->buf;
-            p->free = cl->next;
-            ngx_free_chain(p->pool, cl);
-
-        } else {
-            b = ngx_alloc_buf(p->pool);
-            if (b == NULL) {
-                return NGX_ERROR;
-            }
+        cl = ngx_chain_get_free_buf(p->pool, &p->free);
+        if (cl == NULL) {
+            return NGX_ERROR;
         }
 
+        b = cl->buf;
+
         ngx_memzero(b, sizeof(ngx_buf_t));
 
         b->pos = f->pos;
@@ -1852,14 +1846,6 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
         *prev = b;
         prev = &b->shadow;
 
-        cl = ngx_alloc_chain_link(p->pool);
-        if (cl == NULL) {
-            return NGX_ERROR;
-        }
-
-        cl->buf = b;
-        cl->next = NULL;
-
         if (p->in) {
             *p->last_in = cl;
         } else {
index 404607511420ac9ff3ef835ba39feb137a37e8dd..93469984c6a44afee73ae8f1a5cd9c3bda4733a5 100644 (file)
@@ -1615,19 +1615,13 @@ ngx_http_proxy_copy_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
         return NGX_OK;
     }
 
-    if (p->free) {
-        cl = p->free;
-        b = cl->buf;
-        p->free = cl->next;
-        ngx_free_chain(p->pool, cl);
-
-    } else {
-        b = ngx_alloc_buf(p->pool);
-        if (b == NULL) {
-            return NGX_ERROR;
-        }
+    cl = ngx_chain_get_free_buf(p->pool, &p->free);
+    if (cl == NULL) {
+        return NGX_ERROR;
     }
 
+    b = cl->buf;
+
     ngx_memcpy(b, buf, sizeof(ngx_buf_t));
     b->shadow = buf;
     b->tag = p->tag;
@@ -1635,14 +1629,6 @@ ngx_http_proxy_copy_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
     b->recycled = 1;
     buf->shadow = b;
 
-    cl = ngx_alloc_chain_link(p->pool);
-    if (cl == NULL) {
-        return NGX_ERROR;
-    }
-
-    cl->buf = b;
-    cl->next = NULL;
-
     ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num);
 
     if (p->in) {
@@ -1707,19 +1693,13 @@ ngx_http_proxy_chunked_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
 
             /* a chunk has been parsed successfully */
 
-            if (p->free) {
-                cl = p->free;
-                b = cl->buf;
-                p->free = cl->next;
-                ngx_free_chain(p->pool, cl);
-
-            } else {
-                b = ngx_alloc_buf(p->pool);
-                if (b == NULL) {
-                    return NGX_ERROR;
-                }
+            cl = ngx_chain_get_free_buf(p->pool, &p->free);
+            if (cl == NULL) {
+                return NGX_ERROR;
             }
 
+            b = cl->buf;
+
             ngx_memzero(b, sizeof(ngx_buf_t));
 
             b->pos = buf->pos;
@@ -1732,14 +1712,6 @@ ngx_http_proxy_chunked_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
             *prev = b;
             prev = &b->shadow;
 
-            cl = ngx_alloc_chain_link(p->pool);
-            if (cl == NULL) {
-                return NGX_ERROR;
-            }
-
-            cl->buf = b;
-            cl->next = NULL;
-
             if (p->in) {
                 *p->last_in = cl;
             } else {