summaryrefslogtreecommitdiff
path: root/buckets
diff options
context:
space:
mode:
authorRyan Bloom <rbb@apache.org>2000-07-18 00:32:31 +0000
committerRyan Bloom <rbb@apache.org>2000-07-18 00:32:31 +0000
commit1af8e3b801ae894ca03326c17bcf1f1b6bb68b58 (patch)
tree742a3e88ebd601b03ede728d1a04bcbf75e225ba /buckets
parent0adafc134169a89a962d84915bb9d5a1dd8243e8 (diff)
downloadapr-1af8e3b801ae894ca03326c17bcf1f1b6bb68b58.tar.gz
Add a split function for buckets. This basically just takes one bucket
and makes it two buckets. This is useful if you want to insert something in the middle of some data already in the brigade. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@60384 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'buckets')
-rw-r--r--buckets/ap_buf.c1
-rw-r--r--buckets/ap_eos_buf.c2
-rw-r--r--buckets/ap_mmap_buf.c30
-rw-r--r--buckets/ap_rmem_buf.c24
-rw-r--r--buckets/ap_rwmem_buf.c23
-rw-r--r--buckets/apr_buf.h4
6 files changed, 77 insertions, 7 deletions
diff --git a/buckets/ap_buf.c b/buckets/ap_buf.c
index fe6eed156..9ff396d13 100644
--- a/buckets/ap_buf.c
+++ b/buckets/ap_buf.c
@@ -325,4 +325,3 @@ APR_EXPORT(int) ap_brigade_vprintf(ap_bucket_brigade *b, const char *fmt, va_lis
return res;
}
-
diff --git a/buckets/ap_eos_buf.c b/buckets/ap_eos_buf.c
index 0a788abaf..6d491f9b0 100644
--- a/buckets/ap_eos_buf.c
+++ b/buckets/ap_eos_buf.c
@@ -78,6 +78,8 @@ APR_EXPORT(ap_bucket *) ap_eos_create(void)
newbuf->color = AP_BUCKET_eos;
newbuf->getstr = eos_get_str;
newbuf->getlen = eos_get_len;
+ newbuf->insert = NULL;
+ newbuf->split = NULL;
newbuf->free = NULL;
newbuf->data = NULL;
diff --git a/buckets/ap_mmap_buf.c b/buckets/ap_mmap_buf.c
index d99ee903e..6634ee972 100644
--- a/buckets/ap_mmap_buf.c
+++ b/buckets/ap_mmap_buf.c
@@ -62,7 +62,7 @@
static const char * mmap_get_str(ap_bucket *e)
{
ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
- return b->data->mm;
+ return b->alloc_addr;
}
static int mmap_get_len(ap_bucket *e)
@@ -75,14 +75,33 @@ static ap_status_t mmap_bucket_insert(ap_bucket *e, const void *buf,
ap_size_t nbytes, ap_ssize_t *w)
{
ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
- const ap_mmap_t *mm = buf;
+ ap_mmap_t *mm = (ap_mmap_t *)buf;
- b->data = mm;
+ b->alloc_addr = mm->mm;;
b->len = nbytes;
*w = nbytes;
return APR_SUCCESS;
}
+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;
+
+ newbuck = ap_bucket_new(AP_BUCKET_mmap);
+ b = (ap_bucket_mmap *)newbuck->data;
+ a->alloc_addr = a->alloc_addr + nbyte;
+ a->len = b->len - nbyte;
+
+ a->len = nbyte;
+
+ newbuck->prev = e;
+ newbuck->next = e->next;
+ e->next = newbuck;
+
+ return APR_SUCCESS;
+}
APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void)
{
@@ -92,13 +111,14 @@ APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void)
newbuf = calloc(1, sizeof(*newbuf));
b = malloc(sizeof(*b));
- b->data = NULL;
- b->len = 0;
+ b->alloc_addr = NULL;
+ b->len = 0;
newbuf->color = AP_BUCKET_mmap;
newbuf->getstr = mmap_get_str;
newbuf->getlen = mmap_get_len;
newbuf->insert = mmap_bucket_insert;
+ newbuf->split = mmap_split;
newbuf->free = NULL;
newbuf->data = b;
diff --git a/buckets/ap_rmem_buf.c b/buckets/ap_rmem_buf.c
index 55aeaaff5..6772b3a89 100644
--- a/buckets/ap_rmem_buf.c
+++ b/buckets/ap_rmem_buf.c
@@ -75,6 +75,29 @@ static int rmem_get_len(ap_bucket *e)
return (char *)b->end - (char *)b->start;
}
+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;
+
+ newbuck = ap_bucket_new(AP_BUCKET_rmem);
+ b = (ap_bucket_rmem *)newbuck->data;
+
+ b->alloc_len = a->alloc_len - nbyte;
+ a->alloc_len = nbyte;
+ b->end = a->end;
+ a->end = a->start + nbyte;
+ b->start = a->end + 1;
+
+ newbuck->prev = e;
+ newbuck->next = e->next;
+ e->next = newbuck;
+
+
+ return APR_SUCCESS;
+}
+
/*
* save nbyte bytes to the bucket.
* Only returns fewer than nbyte if an error ocurred.
@@ -116,6 +139,7 @@ APR_EXPORT(ap_bucket *) ap_rmem_create(void)
newbuf->getstr = rmem_get_str;
newbuf->getlen = rmem_get_len;
newbuf->insert = 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 6b01c3af5..b252cac68 100644
--- a/buckets/ap_rwmem_buf.c
+++ b/buckets/ap_rwmem_buf.c
@@ -81,6 +81,28 @@ static void rwmem_destroy(void *e)
free(d->alloc_addr);
}
+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;
+
+ newbuck = ap_bucket_new(AP_BUCKET_rwmem);
+ b = (ap_bucket_rwmem *)newbuck;
+
+ b->alloc_addr = a->alloc_addr;
+ b->alloc_len = a->alloc_len;
+ b->end = a->end;
+ a->end = a->start + nbyte;
+ b->start = a->end + 1;
+
+ newbuck->prev = e;
+ newbuck->next = e->next;
+ e->next = newbuck;
+
+ return APR_SUCCESS;
+}
+
/*
* save nbyte bytes to the bucket.
* Only returns fewer than nbyte if an error occurred.
@@ -136,6 +158,7 @@ APR_EXPORT(ap_bucket *) ap_rwmem_create(void)
newbuf->getstr = rwmem_get_str;
newbuf->getlen = rwmem_get_len;
newbuf->insert = rwmem_insert;
+ newbuf->split = rwmem_split;
newbuf->free = rwmem_destroy;
newbuf->data = b;
diff --git a/buckets/apr_buf.h b/buckets/apr_buf.h
index aeb0b34e6..83700b5e4 100644
--- a/buckets/apr_buf.h
+++ b/buckets/apr_buf.h
@@ -95,6 +95,8 @@ struct ap_bucket {
* into the bucket.
*/
int (*insert)(ap_bucket *e, const void *buf, ap_size_t nbytes, ap_ssize_t *w);
+ ap_status_t (*split)(ap_bucket *e, ap_size_t nbytes);
+
ap_bucket *next; /* The next node in the bucket list */
ap_bucket *prev; /* The prev node in the bucket list */
};
@@ -131,7 +133,7 @@ struct ap_bucket_rwmem {
typedef struct ap_bucket_mmap ap_bucket_mmap;
struct ap_bucket_mmap {
- const ap_mmap_t *data;
+ void *alloc_addr; /* Where does the mmap start? */
int len; /* The amount of data in the mmap that we are
* referencing with this bucket. This may be
* smaller than the length in the data object,