From: Yann Ylavic Date: Mon, 16 Jul 2018 11:06:57 +0000 (+0000) Subject: core: Add ap_reuse_brigade_from_pool(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb5e821beae8362ccc6b8b30d0d8a02d4131b8e1;p=apache core: Add ap_reuse_brigade_from_pool(). Current RETRIEVE_BRIGADE_FROM_POOL macro from "http_request.c" is turned into a helper and used in ap_request_core_filter(). We will need it in a subsequent commit in "util_filter.c" too. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1836018 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 718b5223f8..87d6854161 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -580,6 +580,7 @@ * by the ap_filter_ring_t 'pending_filters' in struct * conn_rec, and add ring entry 'pending' in struct * ap_filter_t + * 20180711.2 (2.5.1-dev) Add ap_reuse_brigade_from_pool() */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -587,7 +588,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20180711 #endif -#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index 2a7586f8ac..cf84d5fb73 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -2193,6 +2193,19 @@ AP_DECLARE(int) ap_request_has_body(request_rec *r); */ AP_DECLARE(int) ap_request_tainted(request_rec *r, int flags); +/** + * Reuse a brigade from a pool, or create it on the given pool/alloc and + * associate it with the given key for further reuse. + * + * @param key the key/id of the brigade + * @param pool the pool to cache and create the brigade from + * @param alloc the bucket allocator to be used by the brigade + * @return the reused and cleaned up brigade, or a new one + */ +AP_DECLARE(apr_bucket_brigade *) ap_reuse_brigade_from_pool(const char *key, + apr_pool_t *pool, + apr_bucket_alloc_t *alloc); + /** * Cleanup a string (mainly to be filesystem safe) * We only allow '_' and alphanumeric chars. Non-printable diff --git a/modules/http/http_request.c b/modules/http/http_request.c index 20a75d4f08..ac8944b865 100644 --- a/modules/http/http_request.c +++ b/modules/http/http_request.c @@ -345,17 +345,6 @@ AP_DECLARE(apr_status_t) ap_check_pipeline(conn_rec *c, apr_bucket_brigade *bb, return rv; } -#define RETRIEVE_BRIGADE_FROM_POOL(bb, key, pool, allocator) do { \ - apr_pool_userdata_get((void **)&bb, key, pool); \ - if (bb == NULL) { \ - bb = apr_brigade_create(pool, allocator); \ - apr_pool_userdata_setn((const void *)bb, key, NULL, pool); \ - } \ - else { \ - apr_brigade_cleanup(bb); \ - } \ -} while(0) - AP_DECLARE(void) ap_process_request_after_handler(request_rec *r) { apr_bucket_brigade *bb; @@ -368,8 +357,7 @@ AP_DECLARE(void) ap_process_request_after_handler(request_rec *r) * this bucket is destroyed, the request will be logged and * its pool will be freed */ - RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_after_handler_brigade", - c->pool, c->bucket_alloc); + bb = ap_reuse_brigade_from_pool("ap_prah_bb", c->pool, c->bucket_alloc); b = ap_bucket_eor_create(c->bucket_alloc, r); APR_BRIGADE_INSERT_HEAD(bb, b); @@ -507,8 +495,7 @@ AP_DECLARE(void) ap_process_request(request_rec *r) ap_process_async_request(r); if (!c->data_in_input_filters || ap_run_input_pending(c) != OK) { - RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_brigade", - c->pool, c->bucket_alloc); + bb = ap_reuse_brigade_from_pool("ap_pr_bb", c->pool, c->bucket_alloc); b = apr_bucket_flush_create(c->bucket_alloc); APR_BRIGADE_INSERT_HEAD(bb, b); rv = ap_pass_brigade(c->output_filters, bb); diff --git a/server/request.c b/server/request.c index 1297cf007e..926148cf73 100644 --- a/server/request.c +++ b/server/request.c @@ -2081,13 +2081,8 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_core_filter(ap_filter_t *f, } if (!tmp_bb) { - const char *tmp_bb_key = "ap_request_core_filter_bb"; - tmp_bb = (void *)apr_table_get(f->c->notes, tmp_bb_key); - if (!tmp_bb) { - tmp_bb = apr_brigade_create(f->c->pool, f->c->bucket_alloc); - apr_table_setn(f->c->notes, tmp_bb_key, (void *)tmp_bb); - } - f->ctx = tmp_bb; + f->ctx = tmp_bb = ap_reuse_brigade_from_pool("ap_rcf_bb", f->c->pool, + f->c->bucket_alloc); } /* Reinstate any buffered content */ @@ -2137,13 +2132,12 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_core_filter(ap_filter_t *f, } status = ap_pass_brigade(f->next, tmp_bb); + apr_brigade_cleanup(tmp_bb); + if (seen_eor || (status != APR_SUCCESS && !APR_STATUS_IS_EOF(status))) { - apr_brigade_cleanup(tmp_bb); return status; } - - apr_brigade_cleanup(tmp_bb); } return ap_filter_setaside_brigade(f, bb); diff --git a/server/util.c b/server/util.c index 38ed346ce1..57d3023979 100644 --- a/server/util.c +++ b/server/util.c @@ -2675,6 +2675,22 @@ AP_DECLARE_NONSTD(apr_status_t) ap_pool_cleanup_set_null(void *data_) return APR_SUCCESS; } +AP_DECLARE(apr_bucket_brigade *) ap_reuse_brigade_from_pool(const char *key, + apr_pool_t *pool, + apr_bucket_alloc_t *alloc) +{ + apr_bucket_brigade *bb = NULL; + apr_pool_userdata_get((void **)&bb, key, pool); + if (bb == NULL) { + bb = apr_brigade_create(pool, alloc); + apr_pool_userdata_set(bb, key, NULL, pool); + } + else { + apr_brigade_cleanup(bb); + } + return bb; +} + AP_DECLARE(apr_status_t) ap_str2_alnum(const char *src, char *dest) { for ( ; *src; src++, dest++)