]> granicus.if.org Git - apache/commitdiff
core: Add ap_reuse_brigade_from_pool().
authorYann Ylavic <ylavic@apache.org>
Mon, 16 Jul 2018 11:06:57 +0000 (11:06 +0000)
committerYann Ylavic <ylavic@apache.org>
Mon, 16 Jul 2018 11:06:57 +0000 (11:06 +0000)
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

include/ap_mmn.h
include/httpd.h
modules/http/http_request.c
server/request.c
server/util.c

index 718b5223f87d8b1ddd8db3b3803a95463e195d03..87d6854161d880dd50483d5ebb2a8fa728cb6d0e 100644 (file)
  *                         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" */
 #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
index 2a7586f8ac45935bea58c937e0379c29f277ef00..cf84d5fb73acb4be6d91fa0f4538c518f88e2998 100644 (file)
@@ -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
index 20a75d4f087d8946d8293fc500222eb7c923be32..ac8944b86511ff352d6b5906f82d61a2c24eec81 100644 (file)
@@ -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);
index 1297cf007e05c447bc425deeeac9210f18ba65ad..926148cf73841a9a4ec0fe0c061b8a162cae80ae 100644 (file)
@@ -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);
index 38ed346ce15e0cc5c56756888ff9dc7c395d5f1a..57d3023979f18a6a67f0f1fdfb363d9624de656c 100644 (file)
@@ -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++)