summaryrefslogtreecommitdiff
path: root/buckets
diff options
context:
space:
mode:
authorRyan Bloom <rbb@apache.org>2000-07-31 22:28:58 +0000
committerRyan Bloom <rbb@apache.org>2000-07-31 22:28:58 +0000
commit1a61fcf64b7193f7cc9a19ce2fc536bdb03a20d9 (patch)
tree3564ac1456bb2bb5a4289466715376444910ecd2 /buckets
parenta9c0f31d2e8d63cd54cdaab7744670f5bbcbee99 (diff)
downloadapr-1a61fcf64b7193f7cc9a19ce2fc536bdb03a20d9.tar.gz
Combine the create and write functions. I am leaving the write function
pointer in the structure because I think it is still useful, but having one API to create a bucket and put data in it is much cleaner. If we decide to have a list of free buckets, then the create function may not call malloc, it may grab a bucket off the free list. Regardless of where the memory comes from, create's job is to grab the memory from someplace and fill out the structure. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@60462 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'buckets')
-rw-r--r--buckets/ap_buf.c6
-rw-r--r--buckets/ap_mmap_buf.c10
-rw-r--r--buckets/ap_rmem_buf.c10
-rw-r--r--buckets/ap_rwmem_buf.c12
-rw-r--r--buckets/apr_buf.h12
5 files changed, 32 insertions, 18 deletions
diff --git a/buckets/ap_buf.c b/buckets/ap_buf.c
index 1d9d43860..92e8d6b72 100644
--- a/buckets/ap_buf.c
+++ b/buckets/ap_buf.c
@@ -258,8 +258,7 @@ APR_EXPORT(int) ap_brigade_vputstrs(ap_bucket_brigade *b, va_list va)
break;
j = strlen(x);
- r = ap_bucket_rwmem_create();
- rv = r->write(r, x, j, &i);
+ r = ap_bucket_rwmem_create(x, j, &i);
if (i != j) {
/* Do we need better error reporting? */
return -1;
@@ -294,8 +293,7 @@ APR_EXPORT(int) ap_brigade_vprintf(ap_bucket_brigade *b, const char *fmt, va_lis
res = ap_vsnprintf(buf, 4096, fmt, va);
- r = ap_bucket_rwmem_create();
- res = r->write(r, buf, strlen(buf), &i);
+ r = ap_bucket_rwmem_create(buf, strlen(buf), &i);
ap_bucket_brigade_append_buckets(b, r);
return res;
diff --git a/buckets/ap_mmap_buf.c b/buckets/ap_mmap_buf.c
index 2edce928d..7f1a3dc6d 100644
--- a/buckets/ap_mmap_buf.c
+++ b/buckets/ap_mmap_buf.c
@@ -88,8 +88,9 @@ static ap_status_t mmap_split(ap_bucket *e, ap_size_t nbyte)
ap_bucket *newbuck;
ap_bucket_mmap *a = (ap_bucket_mmap *)e->data;
ap_bucket_mmap *b;
+ ap_ssize_t dump;
- newbuck = ap_bucket_mmap_create();
+ newbuck = ap_bucket_mmap_create(a->alloc_addr, a->len, &dump);
b = (ap_bucket_mmap *)newbuck->data;
a->alloc_addr = a->alloc_addr + nbyte;
a->len = b->len - nbyte;
@@ -103,7 +104,8 @@ static ap_status_t mmap_split(ap_bucket *e, ap_size_t nbyte)
return APR_SUCCESS;
}
-APR_EXPORT(ap_bucket *) ap_bucket_mmap_create(void)
+APR_EXPORT(ap_bucket *) ap_bucket_mmap_create(const void *buf,
+ ap_size_t nbytes, ap_ssize_t *w)
{
ap_bucket *newbuf;
ap_bucket_mmap *b;
@@ -114,13 +116,15 @@ APR_EXPORT(ap_bucket *) ap_bucket_mmap_create(void)
b->alloc_addr = NULL;
b->len = 0;
+ newbuf->data = b;
+ mmap_bucket_insert(newbuf, buf, nbytes, w);
+
newbuf->color = AP_BUCKET_mmap;
newbuf->read = mmap_get_str;
newbuf->getlen = mmap_get_len;
newbuf->write = mmap_bucket_insert;
newbuf->split = mmap_split;
newbuf->free = NULL;
- newbuf->data = b;
return newbuf;
}
diff --git a/buckets/ap_rmem_buf.c b/buckets/ap_rmem_buf.c
index 9f33afbba..6b2719d65 100644
--- a/buckets/ap_rmem_buf.c
+++ b/buckets/ap_rmem_buf.c
@@ -80,8 +80,9 @@ static ap_status_t rmem_split(ap_bucket *e, ap_size_t nbyte)
ap_bucket *newbuck;
ap_bucket_rmem *a = (ap_bucket_rmem *)e->data;
ap_bucket_rmem *b;
+ ap_ssize_t dump;
- newbuck = ap_bucket_rmem_create();
+ newbuck = ap_bucket_rmem_create(a->start, a->alloc_len, &dump);
b = (ap_bucket_rmem *)newbuck->data;
b->alloc_len = a->alloc_len - nbyte;
@@ -124,7 +125,8 @@ static ap_status_t rmem_insert(ap_bucket *e, const void *buf,
return APR_SUCCESS;
}
-APR_EXPORT(ap_bucket *) ap_bucket_rmem_create(void)
+APR_EXPORT(ap_bucket *) ap_bucket_rmem_create(const void *buf,
+ ap_size_t nbyte, ap_ssize_t *w)
{
ap_bucket *newbuf;
ap_bucket_rmem *b;
@@ -135,13 +137,15 @@ APR_EXPORT(ap_bucket *) ap_bucket_rmem_create(void)
b->alloc_len = 0;
b->start = b->end = NULL;
+ newbuf->data = b;
+ rmem_insert(newbuf, buf, nbyte, w);
+
newbuf->color = AP_BUCKET_rmem;
newbuf->read = rmem_get_str;
newbuf->getlen = rmem_get_len;
newbuf->write = rmem_insert;
newbuf->split = rmem_split;
newbuf->free = NULL;
- newbuf->data = b;
return newbuf;
}
diff --git a/buckets/ap_rwmem_buf.c b/buckets/ap_rwmem_buf.c
index ad34213b2..b01ef7427 100644
--- a/buckets/ap_rwmem_buf.c
+++ b/buckets/ap_rwmem_buf.c
@@ -86,9 +86,10 @@ static ap_status_t rwmem_split(ap_bucket *e, ap_size_t nbyte)
ap_bucket *newbuck;
ap_bucket_rwmem *a = (ap_bucket_rwmem *)e;
ap_bucket_rwmem *b;
+ ap_ssize_t dump;
- newbuck = ap_bucket_rwmem_create();
- b = (ap_bucket_rwmem *)newbuck;
+ newbuck = ap_bucket_rwmem_create(a->alloc_addr, a->alloc_len, &dump);
+ b = (ap_bucket_rwmem *)newbuck->data;
b->alloc_addr = a->alloc_addr;
b->alloc_len = a->alloc_len;
@@ -141,7 +142,8 @@ static ap_status_t rwmem_insert(ap_bucket *e, const void *buf,
return APR_SUCCESS;
}
-APR_EXPORT(ap_bucket *) ap_bucket_rwmem_create(void)
+APR_EXPORT(ap_bucket *) ap_bucket_rwmem_create(const void *buf,
+ ap_size_t nbyte, ap_ssize_t *w)
{
ap_bucket *newbuf;
ap_bucket_rwmem *b;
@@ -154,13 +156,15 @@ APR_EXPORT(ap_bucket *) ap_bucket_rwmem_create(void)
b->start = b->alloc_addr;
b->end = b->alloc_addr;
+ newbuf->data = b;
+ rwmem_insert(newbuf, buf, nbyte, w);
+
newbuf->color = AP_BUCKET_rwmem;
newbuf->read = rwmem_get_str;
newbuf->getlen = rwmem_get_len;
newbuf->write = rwmem_insert;
newbuf->split = rwmem_split;
newbuf->free = rwmem_destroy;
- newbuf->data = b;
return newbuf;
}
diff --git a/buckets/apr_buf.h b/buckets/apr_buf.h
index ba2ff927e..9ed2621df 100644
--- a/buckets/apr_buf.h
+++ b/buckets/apr_buf.h
@@ -57,8 +57,8 @@
#include "apr_mmap.h"
#include "apr_errno.h"
-#include "../../../include/ap_iol.h"
#include "apr_private.h"
+#include "../../../include/ap_iol.h"
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h> /* for struct iovec */
#endif
@@ -249,13 +249,17 @@ APR_EXPORT(int) ap_get_bucket_len(ap_bucket *b);
/****** Functions to Create Buckets of varying type ******/
/* Create a read/write memory bucket */
-APR_EXPORT(ap_bucket *) ap_bucket_rwmem_create(void);
+APR_EXPORT(ap_bucket *) ap_bucket_rwmem_create(const void *buf,
+ ap_size_t nbyte, ap_ssize_t *w);
+
/* Create a mmap memory bucket */
-APR_EXPORT(ap_bucket *) ap_bucket_mmap_create(void);
+APR_EXPORT(ap_bucket *) ap_bucket_mmap_create(const void *buf,
+ ap_size_t nbytes, ap_ssize_t *w);
/* Create a read only memory bucket. */
-APR_EXPORT(ap_bucket *) ap_bucket_rmem_create(void);
+APR_EXPORT(ap_bucket *) ap_bucket_rmem_create(const void *buf,
+ ap_size_t nbyte, ap_ssize_t *w);
/* Create an End of Stream bucket */
APR_EXPORT(ap_bucket *) ap_bucket_eos_create(void);