[nginx] Use ngx_chain_get_free_buf() in pipe input filters.
Valentin Bartenev
vbart at nginx.com
Thu Dec 12 13:58:06 UTC 2013
details: http://hg.nginx.org/nginx/rev/e7b3b9855be8
branches:
changeset: 5466:e7b3b9855be8
user: Valentin Bartenev <vbart at nginx.com>
date: Wed Dec 11 21:30:38 2013 +0400
description:
Use ngx_chain_get_free_buf() in pipe input filters.
No functional changes.
diffstat:
src/event/ngx_event_pipe.c | 24 +++-----------
src/http/modules/ngx_http_fastcgi_module.c | 24 +++-----------
src/http/modules/ngx_http_proxy_module.c | 48 ++++++-----------------------
3 files changed, 20 insertions(+), 76 deletions(-)
diffs (168 lines):
diff -r a279d2a33dbf -r e7b3b9855be8 src/event/ngx_event_pipe.c
--- a/src/event/ngx_event_pipe.c Tue Dec 10 20:27:33 2013 +0400
+++ b/src/event/ngx_event_pipe.c Wed Dec 11 21:30:38 2013 +0400
@@ -857,18 +857,12 @@ ngx_event_pipe_copy_input_filter(ngx_eve
return NGX_OK;
}
- if (p->free) {
- cl = p->free;
- b = cl->buf;
- p->free = cl->next;
- ngx_free_chain(p->pool, cl);
+ cl = ngx_chain_get_free_buf(p->pool, &p->free);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
- } else {
- b = ngx_alloc_buf(p->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
- }
+ b = cl->buf;
ngx_memcpy(b, buf, sizeof(ngx_buf_t));
b->shadow = buf;
@@ -877,14 +871,6 @@ ngx_event_pipe_copy_input_filter(ngx_eve
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) {
diff -r a279d2a33dbf -r e7b3b9855be8 src/http/modules/ngx_http_fastcgi_module.c
--- a/src/http/modules/ngx_http_fastcgi_module.c Tue Dec 10 20:27:33 2013 +0400
+++ b/src/http/modules/ngx_http_fastcgi_module.c Wed Dec 11 21:30:38 2013 +0400
@@ -1827,19 +1827,13 @@ ngx_http_fastcgi_input_filter(ngx_event_
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_
*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 {
diff -r a279d2a33dbf -r e7b3b9855be8 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c Tue Dec 10 20:27:33 2013 +0400
+++ b/src/http/modules/ngx_http_proxy_module.c Wed Dec 11 21:30:38 2013 +0400
@@ -1615,19 +1615,13 @@ ngx_http_proxy_copy_filter(ngx_event_pip
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_pip
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_
/* 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_
*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 {
More information about the nginx-devel
mailing list