summaryrefslogtreecommitdiff
path: root/buckets
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2017-03-23 21:51:00 +0000
committerYann Ylavic <ylavic@apache.org>2017-03-23 21:51:00 +0000
commit13417454879b0a42df0d9b8b06437566fce9dd97 (patch)
treeeceb527a2f6be5271f097744341350f9ed0d6211 /buckets
parentb8deb32e55fd4777a50d6c667969dbc64da52e3c (diff)
downloadapr-13417454879b0a42df0d9b8b06437566fce9dd97.tar.gz
apr_buckets: Add apr_bucket_file_set_buf_size() which allows to configure
the size of the buffer used to read files. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1788335 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'buckets')
-rw-r--r--buckets/apr_buckets_alloc.c18
-rw-r--r--buckets/apr_buckets_file.c20
2 files changed, 35 insertions, 3 deletions
diff --git a/buckets/apr_buckets_alloc.c b/buckets/apr_buckets_alloc.c
index 3bfd5b07c..833621c4a 100644
--- a/buckets/apr_buckets_alloc.c
+++ b/buckets/apr_buckets_alloc.c
@@ -123,6 +123,24 @@ APR_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list)
#endif
}
+APR_DECLARE_NONSTD(apr_size_t) apr_bucket_alloc_aligned_floor(apr_size_t size)
+{
+ if (size <= SMALL_NODE_SIZE) {
+ size = SMALL_NODE_SIZE;
+ }
+ else {
+ if (size < APR_MEMNODE_T_SIZE) {
+ size = apr_allocator_align(0);
+ }
+ else {
+ size = apr_allocator_align(size - APR_MEMNODE_T_SIZE);
+ }
+ size -= APR_MEMNODE_T_SIZE;
+ }
+ size -= SIZEOF_NODE_HEADER_T;
+ return size;
+}
+
APR_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t in_size,
apr_bucket_alloc_t *list)
{
diff --git a/buckets/apr_buckets_file.c b/buckets/apr_buckets_file.c
index c26089496..7cea3a40d 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 @@ APR_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 @@ APR_DECLARE(apr_status_t) apr_bucket_file_enable_mmap(apr_bucket *e,
#endif /* APR_HAS_MMAP */
}
+APR_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(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)
{