You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@locus.apache.org on 2000/07/13 23:48:39 UTC
cvs commit: apache-2.0/src/lib/apr/buckets ap_eos_buf.c ap_buf.c ap_mmap_buf.c ap_rmem_buf.c ap_rwmem_buf.c apr_buf.h
rbb 00/07/13 14:48:38
Modified: src/lib/apr/buckets ap_buf.c ap_mmap_buf.c ap_rmem_buf.c
ap_rwmem_buf.c apr_buf.h
Added: src/lib/apr/buckets ap_eos_buf.c
Log:
Update the bucket brigades to be a bit less complex. This makes the
functions get_str and get_len function pointers inside the bucket
itself. This is the first step in cleaning these up just a bit.
Revision Changes Path
1.11 +11 -49 apache-2.0/src/lib/apr/buckets/ap_buf.c
Index: ap_buf.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_buf.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ap_buf.c 2000/07/13 15:10:05 1.10
+++ ap_buf.c 2000/07/13 21:48:33 1.11
@@ -68,38 +68,28 @@
APR_EXPORT(ap_bucket *) ap_bucket_new(ap_bucket_color_e color)
{
/* TODO: keep a free list of ap_bufels... and allocate them in big chunks */
- ap_bucket *newbuf;
- newbuf = malloc(sizeof(*newbuf));
- newbuf->color = color;
switch (color) {
case AP_BUCKET_rwmem:
- newbuf->data = ap_rwmem_create();
- newbuf->free = ap_rwmem_destroy;
- break;
+ return ap_rwmem_create();
case AP_BUCKET_mmap:
- newbuf->data = ap_mmap_bucket_create();
- newbuf->free = NULL;
- break;
+ return ap_mmap_bucket_create();
case AP_BUCKET_rmem:
- newbuf->data = ap_rmem_create();
- newbuf->free = NULL;
- break;
+ return ap_rmem_create();
case AP_BUCKET_eos:
- newbuf->data = NULL;
- newbuf->free = NULL;
+ return ap_eos_create();
case AP_BUCKET_file:
case AP_BUCKET_filename:
case AP_BUCKET_cached_entity:
case AP_BUCKET_URI:
/* not implemented yet */
- break;
+ return NULL;
}
- return newbuf;
+ return NULL;
}
APR_EXPORT(ap_status_t) ap_bucket_destroy(ap_bucket *e)
{
- if (e->free != NULL) {
+ if (e->free) {
e->free(e);
}
free(e);
@@ -263,45 +253,17 @@
APR_EXPORT(const char *) ap_get_bucket_char_str(ap_bucket *b)
{
- switch (b->color) {
- case AP_BUCKET_rwmem:
- return ap_rwmem_get_char_str(b->data);
- case AP_BUCKET_mmap:
- return ap_mmap_get_char_str(b->data);
- case AP_BUCKET_rmem:
- return ap_rmem_get_char_str(b->data);
- case AP_BUCKET_eos:
- return NULL;
- case AP_BUCKET_file:
- case AP_BUCKET_filename:
- case AP_BUCKET_cached_entity:
- case AP_BUCKET_URI:
- /* not implemented yet */
- return NULL;
+ if (b) {
+ return b->getstr(b);
}
- /* We should NEVER actually get here */
return NULL;
}
APR_EXPORT(int) ap_get_bucket_len(ap_bucket *b)
{
- switch (b->color) {
- case AP_BUCKET_rwmem:
- return ap_rwmem_get_len(b->data);
- case AP_BUCKET_mmap:
- return ap_mmap_get_len(b->data);
- case AP_BUCKET_rmem:
- return ap_rmem_get_len(b->data);
- case AP_BUCKET_eos:
- return 0;
- case AP_BUCKET_file:
- case AP_BUCKET_filename:
- case AP_BUCKET_cached_entity:
- case AP_BUCKET_URI:
- /* not implemented yet */
- return 0;
+ if (b) {
+ return b->getlen(b);
}
- /* We should NEVER actually get here */
return 0;
}
1.3 +22 -9 apache-2.0/src/lib/apr/buckets/ap_mmap_buf.c
Index: ap_mmap_buf.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_mmap_buf.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ap_mmap_buf.c 2000/07/11 17:15:50 1.2
+++ ap_mmap_buf.c 2000/07/13 21:48:33 1.3
@@ -59,22 +59,35 @@
#include "apr_buf.h"
#include <stdlib.h>
-APR_EXPORT(ap_bucket_mmap *) ap_mmap_bucket_create(void)
+static const char * mmap_get_str(ap_bucket *e)
{
- ap_bucket_mmap *newbuf;
- newbuf = malloc(sizeof(*newbuf));
- newbuf->data = NULL;
- return newbuf;
+ ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
+ return b->data->mm;
}
-APR_EXPORT(char *) ap_mmap_get_char_str(ap_bucket_mmap *b)
+static int mmap_get_len(ap_bucket *e)
{
- return b->data->mm;
+ ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
+ return b->data->size;
}
-APR_EXPORT(int) ap_mmap_get_len(ap_bucket_mmap *b)
+APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void)
{
- return b->data->size;
+ ap_bucket *newbuf;
+ ap_bucket_mmap *b;
+
+ newbuf = malloc(sizeof(*newbuf));
+ b = malloc(sizeof(*b));
+
+ b->data = NULL;
+
+ newbuf->color = AP_BUCKET_mmap;
+ newbuf->getstr = mmap_get_str;
+ newbuf->getlen = mmap_get_len;
+ newbuf->free = NULL;
+ newbuf->data = b;
+
+ return newbuf;
}
APR_EXPORT(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm)
1.4 +22 -8 apache-2.0/src/lib/apr/buckets/ap_rmem_buf.c
Index: ap_rmem_buf.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_rmem_buf.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ap_rmem_buf.c 2000/07/12 16:47:17 1.3
+++ ap_rmem_buf.c 2000/07/13 21:48:33 1.4
@@ -63,21 +63,35 @@
#define DEFAULT_RWBUF_SIZE (4096)
#endif
-APR_EXPORT(ap_bucket_rmem *) ap_rmem_create(void)
+static const char * rmem_get_str(ap_bucket *e)
{
- ap_bucket_rmem *newbuf;
- newbuf = calloc(1, sizeof(*newbuf));
- return newbuf;
+ ap_bucket_rmem *b = (ap_bucket_rmem *)e->data;
+ return b->start;
}
-APR_EXPORT(const char *) ap_rmem_get_char_str(ap_bucket_rmem *b)
+static int rmem_get_len(ap_bucket *e)
{
- return b->start;
+ ap_bucket_rmem *b = (ap_bucket_rmem *)e->data;
+ return (char *)b->end - (char *)b->start;
}
-APR_EXPORT(int) ap_rmem_get_len(ap_bucket_rmem *b)
+APR_EXPORT(ap_bucket *) ap_rmem_create(void)
{
- return (char *)b->end - (char *)b->start;
+ ap_bucket *newbuf;
+ ap_bucket_rmem *b;
+
+ newbuf = malloc(sizeof(*newbuf));
+ b = malloc(sizeof(*b));
+
+ b->alloc_len = 0;
+ b->start = b->end = NULL;
+
+ newbuf->color = AP_BUCKET_rmem;
+ newbuf->getstr = rmem_get_str;
+ newbuf->getlen = rmem_get_len;
+ newbuf->free = NULL;
+ newbuf->data = b;
+ return newbuf;
}
/*
1.4 +28 -15 apache-2.0/src/lib/apr/buckets/ap_rwmem_buf.c
Index: ap_rwmem_buf.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_rwmem_buf.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ap_rwmem_buf.c 2000/07/12 16:47:17 1.3
+++ ap_rwmem_buf.c 2000/07/13 21:48:33 1.4
@@ -63,31 +63,44 @@
#define DEFAULT_RWBUF_SIZE (4096)
#endif
-APR_EXPORT(ap_bucket_rwmem *) ap_rwmem_create(void)
+static const char * rwmem_get_str(ap_bucket *e)
{
- ap_bucket_rwmem *newbuf;
- newbuf = malloc(sizeof(*newbuf));
- newbuf->alloc_addr = calloc(DEFAULT_RWBUF_SIZE, 1);
- newbuf->alloc_len = DEFAULT_RWBUF_SIZE;
- newbuf->start = newbuf->alloc_addr;
- newbuf->end = newbuf->alloc_addr;
- return newbuf;
+ ap_bucket_rwmem *b = (ap_bucket_rwmem *)e->data;
+ return b->start;
}
-APR_EXPORT(void) ap_rwmem_destroy(void *e)
+static int rwmem_get_len(ap_bucket *e)
{
- ap_bucket_rwmem *d = (ap_bucket_rwmem *)e;
- free(d->alloc_addr);
+ ap_bucket_rwmem *b = (ap_bucket_rwmem *)e->data;
+ return (char *)b->end - (char *)b->start;
}
-APR_EXPORT(char *) ap_rwmem_get_char_str(ap_bucket_rwmem *b)
+static void rwmem_destroy(void *e)
{
- return b->start;
+ ap_bucket_rwmem *d = (ap_bucket_rwmem *)e;
+ free(d->alloc_addr);
}
-APR_EXPORT(int) ap_rwmem_get_len(ap_bucket_rwmem *b)
+APR_EXPORT(ap_bucket *) ap_rwmem_create(void)
{
- return (char *)b->end - (char *)b->start;
+ ap_bucket *newbuf;
+ ap_bucket_rwmem *b;
+
+ newbuf = malloc(sizeof(*newbuf));
+ b = malloc(sizeof(*b));
+
+ b->alloc_addr = calloc(DEFAULT_RWBUF_SIZE, 1);
+ b->alloc_len = DEFAULT_RWBUF_SIZE;
+ b->start = b->alloc_addr;
+ b->end = b->alloc_addr;
+
+ newbuf->color = AP_BUCKET_rwmem;
+ newbuf->getstr = rwmem_get_str;
+ newbuf->getlen = rwmem_get_len;
+ newbuf->free = rwmem_destroy;
+ newbuf->data = b;
+
+ return newbuf;
}
/*
1.12 +14 -31 apache-2.0/src/lib/apr/buckets/apr_buf.h
Index: apr_buf.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/apr_buf.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- apr_buf.h 2000/07/13 16:26:38 1.11
+++ apr_buf.h 2000/07/13 21:48:34 1.12
@@ -62,7 +62,7 @@
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h> /* for struct iovec */
#endif
-#ifdef APR_HAVE_STDARG_H
+#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
@@ -81,9 +81,11 @@
typedef struct ap_bucket ap_bucket;
struct ap_bucket {
- ap_bucket_color_e color; /* what type of bucket is it */
- void (*free)(void *e); /* can be NULL */
- void *data; /* for use by free() */
+ ap_bucket_color_e color; /* what type of bucket is it */
+ void (*free)(void *e); /* can be NULL */
+ void *data; /* for use by free() */
+ const char *(*getstr)(ap_bucket *e); /* Get the string */
+ int (*getlen)(ap_bucket *e); /* Get the length of the string */
};
typedef struct ap_bucket_list ap_bucket_list;
@@ -183,17 +185,8 @@
};
/* Create a read/write memory bucket */
-APR_EXPORT(ap_bucket_rwmem *) ap_rwmem_create(void);
+APR_EXPORT(ap_bucket *) ap_rwmem_create(void);
-/* destroy a read/write memory bucket */
-APR_EXPORT(void) ap_rwmem_destroy(void *e);
-
-/* Convert a rwmem bucket into a char * */
-APR_EXPORT(char *) ap_rwmem_get_char_str(ap_bucket_rwmem *b);
-
-/* get the length of the data in the rwmem bucket */
-APR_EXPORT(int) ap_rwmem_get_len(ap_bucket_rwmem *b);
-
APR_EXPORT(int) ap_rwmem_write(ap_bucket_rwmem *b, const void *buf,
ap_size_t nbyte, ap_ssize_t *bytes_written);
@@ -207,14 +200,8 @@
};
/* Create a mmap memory bucket */
-APR_EXPORT(ap_bucket_mmap *) ap_mmap_bucket_create(void);
+APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void);
-/* Convert a mmap bucket into a char * */
-APR_EXPORT(char *) ap_mmap_get_char_str(ap_bucket_mmap *b);
-
-/* get the length of the data in the mmap bucket */
-APR_EXPORT(int) ap_mmap_get_len(ap_bucket_mmap *b);
-
APR_EXPORT(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm);
/* ****** RMEM Functions ***** */
@@ -228,21 +215,17 @@
};
/* Create a read only memory bucket */
-APR_EXPORT(ap_bucket_rmem *) ap_rmem_create(void);
-
-/* destroy a read only memory bucket */
-APR_EXPORT(void) ap_rmem_destroy(void *e);
+APR_EXPORT(ap_bucket *) ap_rmem_create(void);
-/* Convert a read only bucket into a char * */
-APR_EXPORT(const char *) ap_rmem_get_char_str(ap_bucket_rmem *b);
-
-/* get the length of the data in the rmem bucket */
-APR_EXPORT(int) ap_rmem_get_len(ap_bucket_rmem *b);
-
APR_EXPORT(int) ap_rmem_write(ap_bucket_rmem *b, const void *buf,
ap_size_t nbyte, ap_ssize_t *bytes_written);
APR_EXPORT(int) ap_rmem_vputstrs(ap_bucket_rmem *b, va_list va);
+
+/* ****** RMEM Functions ***** */
+
+/* Create an End of Stream bucket */
+APR_EXPORT(ap_bucket *) ap_eos_create(void);
#endif
1.1 apache-2.0/src/lib/apr/buckets/ap_eos_buf.c
Index: ap_eos_buf.c
===================================================================
/* ====================================================================
* Copyright (c) 1996-1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#include "apr_private.h"
#include "apr_buf.h"
#include <stdlib.h>
static const char * eos_get_str(ap_bucket *e)
{
return NULL;
}
static int eos_get_len(ap_bucket *e)
{
return 0;
}
APR_EXPORT(ap_bucket *) ap_eos_create(void)
{
ap_bucket *newbuf;
newbuf = malloc(sizeof(*newbuf));
newbuf->color = AP_BUCKET_eos;
newbuf->getstr = eos_get_str;
newbuf->getlen = eos_get_len;
newbuf->free = NULL;
newbuf->data = NULL;
return newbuf;
}
Re: cvs commit: apache-2.0/src/lib/apr/buckets ap_eos_buf.c ap_buf.c ap_mmap_buf.c ap_rmem_buf.c ap_rwmem_buf.c apr_buf.h
Posted by Greg Stein <gs...@lyra.org>.
You don't need those functions since a NULL in getstr/getlen will return the
right values.
Cheers,
-g
On Thu, Jul 13, 2000 at 09:48:39PM -0000, rbb@locus.apache.org wrote:
>...
> static const char * eos_get_str(ap_bucket *e)
> {
> return NULL;
> }
>
> static int eos_get_len(ap_bucket *e)
> {
> return 0;
> }
>
> APR_EXPORT(ap_bucket *) ap_eos_create(void)
> {
> ap_bucket *newbuf;
>
> newbuf = malloc(sizeof(*newbuf));
>
> newbuf->color = AP_BUCKET_eos;
> newbuf->getstr = eos_get_str;
> newbuf->getlen = eos_get_len;
> newbuf->free = NULL;
> newbuf->data = NULL;
>
> return newbuf;
> }
--
Greg Stein, http://www.lyra.org/