summaryrefslogtreecommitdiff
path: root/buckets
diff options
context:
space:
mode:
Diffstat (limited to 'buckets')
-rw-r--r--buckets/apr_buckets_alloc.c32
-rw-r--r--buckets/apr_buckets_file.c20
2 files changed, 49 insertions, 3 deletions
diff --git a/buckets/apr_buckets_alloc.c b/buckets/apr_buckets_alloc.c
index 15baa3396655..e5838dd016ec 100644
--- a/buckets/apr_buckets_alloc.c
+++ b/buckets/apr_buckets_alloc.c
@@ -18,6 +18,7 @@
#include "apr_buckets.h"
#include "apr_allocator.h"
+#include "apr_version.h"
#define ALLOC_AMT (8192 - APR_MEMNODE_T_SIZE)
@@ -121,6 +122,37 @@ APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list)
#endif
}
+APU_DECLARE_NONSTD(apr_size_t) apr_bucket_alloc_aligned_floor(apr_bucket_alloc_t *list,
+ apr_size_t size)
+{
+ if (size <= SMALL_NODE_SIZE) {
+ size = SMALL_NODE_SIZE;
+ }
+ else {
+#if APR_VERSION_AT_LEAST(1,6,0)
+ if (size < APR_MEMNODE_T_SIZE) {
+ size = apr_allocator_align(list->allocator, 0);
+ }
+ else {
+ size = apr_allocator_align(list->allocator,
+ size - APR_MEMNODE_T_SIZE);
+ }
+#else
+ /* Assumes the minimum (default) allocator's boundary of 4K and
+ * minimum (immutable before APR-1.6.x) allocation size of 8K,
+ * hence possibly (yet unlikely) under-estimating the floor...
+ */
+ size = APR_ALIGN(size, 4096);
+ if (size < 8192) {
+ size = 8192;
+ }
+#endif
+ size -= APR_MEMNODE_T_SIZE;
+ }
+ size -= SIZEOF_NODE_HEADER_T;
+ return size;
+}
+
APU_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t size,
apr_bucket_alloc_t *list)
{
diff --git a/buckets/apr_buckets_file.c b/buckets/apr_buckets_file.c
index 0644cd82ce7a..06b7cf0039f1 100644
--- a/buckets/apr_buckets_file.c
+++ b/buckets/apr_buckets_file.c
@@ -108,10 +108,8 @@ static apr_status_t file_bucket_read(apr_bucket *e, const char **str,
}
#endif
- *len = (filelength > APR_BUCKET_BUFF_SIZE)
- ? APR_BUCKET_BUFF_SIZE
- : filelength;
*str = NULL; /* in case we die prematurely */
+ *len = (filelength > a->read_size) ? a->read_size : filelength;
buf = apr_bucket_alloc(*len, e->list);
/* Handle offset ... */
@@ -165,6 +163,7 @@ APU_DECLARE(apr_bucket *) apr_bucket_file_make(apr_bucket *b, apr_file_t *fd,
#if APR_HAS_MMAP
f->can_mmap = 1;
#endif
+ f->read_size = APR_BUCKET_BUFF_SIZE;
b = apr_bucket_shared_make(b, f, offset, len);
b->type = &apr_bucket_type_file;
@@ -197,6 +196,21 @@ APU_DECLARE(apr_status_t) apr_bucket_file_enable_mmap(apr_bucket *e,
#endif /* APR_HAS_MMAP */
}
+APU_DECLARE(apr_status_t) apr_bucket_file_set_buf_size(apr_bucket *e,
+ apr_size_t size)
+{
+ apr_bucket_file *a = e->data;
+
+ if (size <= APR_BUCKET_BUFF_SIZE) {
+ a->read_size = APR_BUCKET_BUFF_SIZE;
+ }
+ else {
+ apr_size_t floor = apr_bucket_alloc_aligned_floor(e->list, size);
+ a->read_size = (size < floor) ? size : floor;
+ }
+
+ return APR_SUCCESS;
+}
static apr_status_t file_bucket_setaside(apr_bucket *data, apr_pool_t *reqpool)
{