summaryrefslogtreecommitdiff
path: root/buckets/apr_buckets_refcount.c
diff options
context:
space:
mode:
authorjwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68>2001-02-27 20:45:38 +0000
committerjwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68>2001-02-27 20:45:38 +0000
commit11caed1c75c67c031011ae3372a57df9fe7b43c8 (patch)
tree9094f3c48ed9431fd4b646d3d061c78edf58ef0b /buckets/apr_buckets_refcount.c
parent94c0af235eebf42d7f059b90d861b492aeb08aa0 (diff)
downloadlibapr-util-11caed1c75c67c031011ae3372a57df9fe7b43c8.tar.gz
*) The apr_bucket_shared and apr_bucket_simple structures have been
removed as an API simplification/optimization. This should be transparent outside APR-util except to callers who attempt to directly manipulate the buckets' internal structure (which is not recommended anyway) and to callers who create their own bucket types. *) apr_bucket_simple_split() and apr_bucket_simple_copy() are now exported functions, which could be helpful in implementing external bucket types. *) The third parameter to apr_bucket_shared_make() is now 'apr_off_t length' rather than 'apr_off_t end', since the end usually had to be computed by the caller and all we really want is the length anyway. This addresses issue #1 from the "Bucket API cleanup issues" thread. git-svn-id: http://svn.apache.org/repos/asf/apr/apr-util/trunk@58137 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'buckets/apr_buckets_refcount.c')
-rw-r--r--buckets/apr_buckets_refcount.c87
1 files changed, 22 insertions, 65 deletions
diff --git a/buckets/apr_buckets_refcount.c b/buckets/apr_buckets_refcount.c
index 8e05700d..1f3ef3d2 100644
--- a/buckets/apr_buckets_refcount.c
+++ b/buckets/apr_buckets_refcount.c
@@ -58,96 +58,53 @@
#include "apr_buckets.h"
-APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *a, apr_off_t point)
+APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *a,
+ apr_off_t point)
{
- apr_bucket *b;
- apr_bucket_shared *ad, *bd;
+ apr_bucket_refcount *r = a->data;
apr_status_t rv;
- if (point < 0 || point > a->length) {
- return APR_EINVAL;
- }
-
- rv = apr_bucket_shared_copy(a, &b);
- if (rv != APR_SUCCESS) {
+ if ((rv = apr_bucket_simple_split(a, point)) != APR_SUCCESS) {
return rv;
}
-
- ad = a->data;
- bd = b->data;
-
- a->length = point;
- ad->end = ad->start + point;
- b->length -= point;
- bd->start += point;
-
- APR_BUCKET_INSERT_AFTER(a, b);
+ r->refcount++;
return APR_SUCCESS;
}
-APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a, apr_bucket **c)
+APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a,
+ apr_bucket **b)
{
- apr_bucket *b;
- apr_bucket_shared *ad, *bd;
- apr_bucket_refcount *r;
+ apr_bucket_refcount *r = a->data;
+ apr_status_t rv;
- b = malloc(sizeof(*b));
- if (b == NULL) {
- return APR_ENOMEM;
- }
- bd = malloc(sizeof(*bd));
- if (bd == NULL) {
- free(b);
- return APR_ENOMEM;
+ if ((rv = apr_bucket_simple_copy(a, b)) != APR_SUCCESS) {
+ return rv;
}
- *b = *a;
- ad = a->data;
- b->data = bd;
- *bd = *ad;
-
- r = ad->data;
- r->refcount += 1;
-
- *c = b;
+ r->refcount++;
return APR_SUCCESS;
}
+/* XXX: can this just return true or false? */
APU_DECLARE(void *) apr_bucket_shared_destroy(void *data)
{
- apr_bucket_shared *s = data;
- apr_bucket_refcount *r = s->data;
-
- free(s);
- r->refcount -= 1;
- if (r->refcount == 0) {
- return r;
- }
- else {
- return NULL;
- }
+ apr_bucket_refcount *r = data;
+ r->refcount--;
+ return (r->refcount == 0) ? r : NULL;
}
APU_DECLARE(apr_bucket *) apr_bucket_shared_make(apr_bucket *b, void *data,
- apr_off_t start, apr_off_t end)
+ apr_off_t start,
+ apr_off_t length)
{
- apr_bucket_shared *s;
apr_bucket_refcount *r = data;
- s = malloc(sizeof(*s));
- if (s == NULL) {
- return NULL;
- }
-
- b->data = s;
- b->length = end - start;
- /* caller initializes the type field and function pointers */
- s->start = start;
- s->end = end;
- s->data = r;
+ b->data = r;
+ b->start = start;
+ b->length = length;
+ /* caller initializes the type field */
r->refcount = 1;
- /* caller initializes the rest of r */
return b;
}