You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by gs...@locus.apache.org on 2000/12/12 13:18:50 UTC

cvs commit: apr-util/src/buckets ap_buckets.c

gstein      00/12/12 04:18:48

  Modified:    include  ap_buckets.h
               src/buckets ap_buckets.c
  Log:
  drop the split_any function and add ap_brigade_partition()
  
  Submitted by: Cliff Woolley <cl...@yahoo.com>
  
  Revision  Changes    Path
  1.60      +12 -12    apr-util/include/ap_buckets.h
  
  Index: ap_buckets.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/ap_buckets.h,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -u -r1.59 -r1.60
  --- ap_buckets.h	2000/12/09 21:22:43	1.59
  +++ ap_buckets.h	2000/12/12 12:18:42	1.60
  @@ -583,6 +583,18 @@
   APR_DECLARE(ap_bucket_brigade *) ap_brigade_split(ap_bucket_brigade *b,
   						 ap_bucket *e);
   
  +/**
  + * Partition a bucket brigade at a given offset (in bytes from the start of
  + * the brigade).  This is useful whenever a filter wants to use known ranges
  + * of bytes from the brigade; the ranges can even overlap.
  + * @param b The brigade to partition
  + * @param point The offset at which to partition the brigade
  + * @return A pointer to the first bucket after the partition;
  + *         or NULL in any error condition (including partition past the end)
  + * @deffunc ap_bucket *ap_brigade_partition(ap_bucket_brigade *b, apr_off_t point)
  + */
  +APR_DECLARE(ap_bucket *) ap_brigade_partition(ap_bucket_brigade *b, apr_off_t point);
  +
   #if APR_NOT_DONE_YET
   /**
    * consume nbytes from beginning of b -- call ap_bucket_destroy as
  @@ -704,18 +716,6 @@
    * @deffunc apr_status_t ap_bucket_copy(ap_bucket *e, ap_bucket **c)
    */
   #define ap_bucket_copy(e,c) e->type->copy(e, c)
  -
  -/**
  - * Split a bucket into two, using ap_bucket_split() if that's possible
  - * for the given bucket type. If split() is not implemented for the
  - * bucket's type, then we perform a blocking read on the bucket. That
  - * morphs the bucket into a splittable bucket (eg, pipe becomes heap),
  - * and we then split the result.
  - * @param e The bucket to split
  - * @param point The offset to split the bucket at
  - * @deffunc apr_status_t ap_bucket_split_any(ap_bucket *e, apr_off_t point)
  - */
  -APR_DECLARE(apr_status_t) ap_bucket_split_any(ap_bucket *e, apr_off_t point);
   
   /* Bucket type handling */
   
  
  
  
  1.37      +37 -20    apr-util/src/buckets/ap_buckets.c
  
  Index: ap_buckets.c
  ===================================================================
  RCS file: /home/cvs/apr-util/src/buckets/ap_buckets.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -u -r1.36 -r1.37
  --- ap_buckets.c	2000/12/09 21:22:44	1.36
  +++ ap_buckets.c	2000/12/12 12:18:46	1.37
  @@ -122,31 +122,48 @@
       return a;
   }
   
  -APR_DECLARE(apr_status_t) ap_bucket_split_any(ap_bucket *e, apr_off_t point)
  +APR_DECLARE(ap_bucket *) ap_brigade_partition(ap_bucket_brigade *b, apr_off_t point)
   {
  -    apr_status_t rv;
  -    const char *str;
  +    ap_bucket *e;
  +    const char *s;
       apr_size_t len;
   
  -    /* try to split this bucket directly */
  -    rv = ap_bucket_split(e, point);
  -    if (rv != APR_ENOTIMPL) {
  -        return rv;
  -    }
  +    if (point < 0)
  +        return NULL;
   
  -    /* 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;
  +    AP_BRIGADE_FOREACH(e, b) {
  +        /* bucket is of a known length */
  +        if ((point > e->length) && (e->length != -1)) {
  +            if (AP_BUCKET_IS_EOS(e))
  +                return NULL;
  +            point -= e->length;
  +        }
  +        else if (point == e->length) {
  +            return AP_BUCKET_NEXT(e);
  +        }
  +        else {
  +            /* try to split the bucket natively */
  +            if (ap_bucket_split(e, point) != APR_ENOTIMPL)
  +                return AP_BUCKET_NEXT(e);
  +
  +            /* if the bucket cannot be split, we must read from it,
  +             * changing its type to one that can be split */
  +            if (ap_bucket_read(e, &s, &len, AP_BLOCK_READ) != APR_SUCCESS)
  +                return NULL;
  +
  +            if (point < len) {
  +                if (ap_bucket_split(e, point) == APR_SUCCESS)
  +                    return AP_BUCKET_NEXT(e);
  +                else
  +                    return NULL;
  +            }
  +            else if (point == len)
  +                return AP_BUCKET_NEXT(e);
  +            else
  +                point -= len;
  +        }
       }
  -    return ap_bucket_split(e, point);
  +    return NULL;
   }
   
   APR_DECLARE(int) ap_brigade_to_iovec(ap_bucket_brigade *b,