apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwool...@apache.org
Subject cvs commit: apr-util/buckets apr_brigade.c
Date Mon, 04 Feb 2002 20:07:08 GMT
jwoolley    02/02/04 12:07:08

  Modified:    .        CHANGES
               buckets  apr_brigade.c
  Log:
  Deprecate check_brigade_flush(), which had several nasty bugs, and which
  was causing apr_brigade_write()'s logic to be less than obvious.  Everything
  is now done in a slightly rearranged apr_brigade_write().  For example, it
  now works to have Apache's AP_MIN_BYTES_TO_WRITE > APR_BUCKET_BUFF_SIZE
  (not desirable, but possible) without free()ing stuff not on the heap
  and other bad behavior.
  
  Revision  Changes    Path
  1.56      +5 -0      apr-util/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr-util/CHANGES,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -d -u -r1.55 -r1.56
  --- CHANGES	3 Feb 2002 15:19:20 -0000	1.55
  +++ CHANGES	4 Feb 2002 20:07:08 -0000	1.56
  @@ -1,5 +1,10 @@
   Changes with APR-util b1  
   
  +  *) Deprecate check_brigade_flush(), which had several nasty bugs, and
  +     which was causing apr_brigade_write()'s logic to be less than obvious.
  +     Everything is now done in a slightly rearranged apr_brigade_write().
  +     [Cliff Woolley]
  +
     *) Don't add /usr/include to the INCLUDES variable on expat's account.
        [Joe Orton <joe@manyfish.co.uk>]
   
  
  
  
  1.34      +28 -50    apr-util/buckets/apr_brigade.c
  
  Index: apr_brigade.c
  ===================================================================
  RCS file: /home/cvs/apr-util/buckets/apr_brigade.c,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -d -u -r1.33 -r1.34
  --- apr_brigade.c	4 Feb 2002 19:27:30 -0000	1.33
  +++ apr_brigade.c	4 Feb 2002 20:07:08 -0000	1.34
  @@ -349,41 +349,6 @@
       return APR_SUCCESS;
   }
   
  -static int check_brigade_flush(const char **str, 
  -                               apr_size_t *n, apr_bucket_brigade *bb,
  -                               apr_brigade_flush flush)
  -{
  -    apr_bucket *b = APR_BRIGADE_LAST(bb);
  -
  -    if (APR_BRIGADE_EMPTY(bb)) {
  -        if (*n > APR_BUCKET_BUFF_SIZE) {
  -            apr_bucket *e;
  -            if (flush) {
  -                e = apr_bucket_transient_create(*str, *n);
  -            }
  -            else {
  -                e = apr_bucket_heap_create(*str, *n, 0);
  -            }
  -            APR_BRIGADE_INSERT_TAIL(bb, e);
  -            return 1;
  -        }
  -    }
  -    else if (APR_BUCKET_IS_HEAP(b)) {
  -        apr_bucket_heap *h = b->data;
  -
  -        if (*n > (h->alloc_len - b->length)) {
  -            APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_transient_create(*str, *n));
  -            return 1;
  -        }
  -    }
  -    else if (*n > APR_BUCKET_BUFF_SIZE) {
  -        APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_transient_create(*str, *n));
  -        return 1;
  -    }
  -
  -    return 0;
  -}
  -
   APU_DECLARE(apr_status_t) apr_brigade_vputstrs(apr_bucket_brigade *b, 
                                                  apr_brigade_flush flush,
                                                  void *ctx,
  @@ -416,16 +381,33 @@
                                               void *ctx, 
                                               const char *str, apr_size_t nbyte)
   {
  -    if (check_brigade_flush(&str, &nbyte, b, flush)) {
  -        if (flush) {
  -            return flush(b, ctx);
  -        }
  +    apr_bucket *e = APR_BRIGADE_LAST(b);
  +    char *buf;
  +
  +    if (!APR_BRIGADE_EMPTY(b) && APR_BUCKET_IS_HEAP(e) &&
  +        (e->length + nbyte <= ((apr_bucket_heap *)e->data)->alloc_len))
  +    {
  +        /* there is a sufficiently big buffer bucket available */
  +        apr_bucket_heap *h = e->data;
  +        buf = h->base + e->start + e->length;
       }
       else {
  -        apr_bucket *e = APR_BRIGADE_LAST(b);
  -        char *buf;
  -
  -        if (APR_BRIGADE_EMPTY(b) || !APR_BUCKET_IS_HEAP(e)) {
  +        if (nbyte > APR_BUCKET_BUFF_SIZE) {
  +            /* too big to buffer */
  +            if (flush) {
  +                e = apr_bucket_transient_create(str, nbyte);
  +                APR_BRIGADE_INSERT_TAIL(b, e);
  +                return flush(b, ctx);
  +            }
  +            else {
  +                e = apr_bucket_heap_create(str, nbyte, 1);
  +                APR_BRIGADE_INSERT_TAIL(b, e);
  +                return APR_SUCCESS;
  +            }
  +        }
  +        else {
  +            /* bigger than the current buffer can handle, but we don't
  +             * mind making a new buffer */
               buf = malloc(APR_BUCKET_BUFF_SIZE);
               e = apr_bucket_heap_create(buf, APR_BUCKET_BUFF_SIZE, 0);
               APR_BRIGADE_INSERT_TAIL(b, e);
  @@ -436,14 +418,10 @@
                                 * once we put data in it below.
                                 */
           }
  -        else {
  -            apr_bucket_heap *h = e->data;
  -            buf = h->base + e->start + e->length;
  -        }
  -
  -        memcpy(buf, str, nbyte);
  -        e->length += nbyte;
       }
  +
  +    memcpy(buf, str, nbyte);
  +    e->length += nbyte;
   
       return APR_SUCCESS;
   }
  
  
  

Mime
View raw message