You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Cliff Woolley <cl...@yahoo.com> on 2000/11/13 06:29:57 UTC

RE: [PATCH(revised)] bucket split compromise

--- rbb@covalent.net wrote:
> > +1 here too.  And I'd suggest we start an ap_buckets_util.c for these
> > sorts of accessors that would otherwise polute the buckets themselves
> > (making them non-atomic) but don't do anything but provide bucket
> > utility functions.
> I could go along with that.  I would ask that it go in ap/.

Okay, here it is.  I tweaked some of the docs a little further... nothing major. 
I'm not exactly sure how to submit a patch for a new file since I can't cvs add... I
just tacked the file on to the end as-is.

--Cliff


Index: src/include/ap_buckets.h
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/include/ap_buckets.h,v
retrieving revision 1.50
diff -u -r1.50 ap_buckets.h
--- src/include/ap_buckets.h	2000/11/10 04:53:24	1.50
+++ src/include/ap_buckets.h	2000/11/13 05:19:01
@@ -492,7 +492,7 @@
 
 /**
  * free the resources used by a bucket. If multiple buckets refer to
- * the same resource it is freed when the last one goes away.
+ *    the same resource it is freed when the last one goes away.
  * @param e The bucket to destroy
  * @deffunc void ap_bucket_destroy(ap_bucket *e)
  */
@@ -503,7 +503,8 @@
     }
 
 /**
- * read the data from the bucket
+ * read the data from the bucket.  This is guaranteed to be
+ *    implemented for all bucket types.
  * @param e The bucket to read from
  * @param str The location to store the data in
  * @param len The amount of data read
@@ -514,20 +515,35 @@
 
 /**
  * Setaside data so that stack data is not destroyed on returning from
- * the function
+ *    the function.  If this doesn't make sense for the bucket type,
+ *    then APR_ENOTIMPL is returned.
  * @param e The bucket to setaside
  * @deffunc apr_status_t ap_bucket_setaside(ap_bucket *e)
  */
 #define ap_bucket_setaside(e) e->type->setaside(e)
 
 /**
- * Split one bucket in two.
+ * Split one bucket in two by duplicating the bucket (not the data) and
+ *    modifying any necessary start/end/offset information.  If it's not
+ *    possible to do this (perhaps the length of the data is indeterminate,
+ *    as with pipe and socket buckets), then APR_ENOTIMPL is returned.
  * @param e The bucket to split
  * @param point The location to split the bucket at
  * @deffunc apr_status_t ap_bucket_split(ap_bucket *e, apr_off_t point)
  */
 #define ap_bucket_split(e,point) e->type->split(e, point)
 
+/**
+ * Split a bucket into two using ap_bucket_split() if possible on the
+ *    bucket's type.  If split() is not implemented for the bucket's
+ *    type, then we perform a blocking read on the bucket, thereby
+ *    morphing the bucket into a splittable bucket, and then split
+ *    that bucket.
+ * @param e The bucket to split
+ * @param point The location to split the bucket at
+ * @deffunc apr_status_t ap_bucket_split_any(ap_bucket *e, apr_off_t point)
+ */
+AP_DECLARE(apr_status_t) ap_bucket_split_any(ap_bucket *e, apr_off_t point);
 
 /* Bucket type handling */
 
Index: src/ap/Makefile.in
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/ap/Makefile.in,v
retrieving revision 1.13
diff -u -r1.13 Makefile.in
--- src/ap/Makefile.in	2000/10/17 21:53:42	1.13
+++ src/ap/Makefile.in	2000/11/13 05:19:01
@@ -4,6 +4,6 @@
 	ap_buckets_eos.c ap_buckets_simple.c ap_buckets_refcount.c \
 	ap_buckets_heap.c ap_buckets_mmap.c ap_buckets_pipe.c \
 	ap_buckets_file.c ap_buckets_socket.c ap_buckets_flush.c \
-	ap_buckets_pool.c
+	ap_buckets_pool.c ap_buckets_util.c
 
 include $(top_srcdir)/build/ltlib.mk

-------------begin new file ap_buckets_util.c----------------/*
====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  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. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" 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 name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``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 SOFTWARE FOUNDATION 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 Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

#include "apr_lib.h"
#include "ap_buckets.h"

AP_DECLARE(apr_status_t) ap_bucket_split_any(ap_bucket *e, apr_off_t point)
{
    apr_status_t rv;
    const char *str;
    apr_size_t len;

    /* try to split this bucket directly */
    rv = ap_bucket_split(e, point);
    if (rv != APR_ENOTIMPL) {
        return rv;
    }

    /* if the bucket cannot be split, we must read from it,
     * changing its type to one that can be split */
    if (point < 0) {
        return APR_EINVAL;
    }
    rv = ap_bucket_read(e, &str, &len, AP_BLOCK_READ);
    if (rv != APR_SUCCESS) {
        return rv;
    }
    if (point > len) {
        return APR_EINVAL;
    }
    return ap_bucket_split(e, point);
}



__________________________________________________
Do You Yahoo!?
Yahoo! Calendar - Get organized for the holidays!
http://calendar.yahoo.com/