apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: apr-util CHANGES
Date Sat, 21 Sep 2002 23:40:41 GMT
brianp      2002/09/21 16:40:41

  Modified:    include  apr_buckets.h
               buckets  apr_brigade.c
               .        CHANGES
  Log:
  Added apr_brigade_writev() function
  
  Revision  Changes    Path
  1.144     +15 -0     apr-util/include/apr_buckets.h
  
  Index: apr_buckets.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/apr_buckets.h,v
  retrieving revision 1.143
  retrieving revision 1.144
  diff -u -r1.143 -r1.144
  --- apr_buckets.h	3 Jul 2002 00:15:07 -0000	1.143
  +++ apr_buckets.h	21 Sep 2002 23:40:41 -0000	1.144
  @@ -820,6 +820,21 @@
                                               const char *str, apr_size_t nbyte);
   
   /**
  + * This function writes multiple strings into a bucket brigade.
  + * @param b The bucket brigade to add to
  + * @param flush The flush function to use if the brigade is full
  + * @param ctx The structure to pass to the flush function
  + * @param iovec The strings to add (address plus length for each)
  + * @param nvec The number of entries in iovec
  + * @return APR_SUCCESS or error code
  + */
  +APU_DECLARE(apr_status_t) apr_brigade_writev(apr_bucket_brigade *b,
  +                                             apr_brigade_flush flush,
  +                                             void *ctx,
  +                                             const struct iovec *vec,
  +                                             apr_size_t nvec);
  +
  +/**
    * This function writes a string into a bucket brigade.
    * @param bb The bucket brigade to add to
    * @param flush The flush function to use if the brigade is full
  
  
  
  1.50      +65 -0     apr-util/buckets/apr_brigade.c
  
  Index: apr_brigade.c
  ===================================================================
  RCS file: /home/cvs/apr-util/buckets/apr_brigade.c,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- apr_brigade.c	21 Sep 2002 16:30:43 -0000	1.49
  +++ apr_brigade.c	21 Sep 2002 23:40:41 -0000	1.50
  @@ -452,6 +452,71 @@
       return APR_SUCCESS;
   }
   
  +APU_DECLARE(apr_status_t) apr_brigade_writev(apr_bucket_brigade *b,
  +                                             apr_brigade_flush flush,
  +                                             void *ctx,
  +                                             const struct iovec *vec,
  +                                             apr_size_t nvec)
  +{
  +    apr_bucket *e = APR_BRIGADE_LAST(b);
  +    apr_size_t remaining;
  +    char *buf;
  +    apr_size_t bytes_written = 0;
  +    apr_size_t i;
  +
  +    /* Step 1: check if there is a heap bucket at the end
  +     * of the brigade already
  +     */
  +    if (!APR_BRIGADE_EMPTY(b) && APR_BUCKET_IS_HEAP(e)) {
  +        apr_bucket_heap *h = e->data;
  +        remaining = h->alloc_len - (e->length + (apr_size_t)e->start);
  +        buf = h->base + e->start + e->length;
  +    }
  +    else {
  +        remaining = 0;
  +        buf = NULL;
  +    }
  +
  +    /* Step 2: copy the data into the heap bucket, appending
  +     * a new heap bucket each time the old one becomes full
  +     */
  +    for (i = 0; i < nvec; i++) {
  +        apr_size_t nbyte = vec[i].iov_len;
  +        const char *str = (const char *)(vec[i].iov_base);
  +
  +        bytes_written += nbyte;
  +        if (nbyte <= remaining) {
  +            memcpy(buf, str, nbyte);
  +            e->length += nbyte;
  +            buf += nbyte;
  +            remaining -= nbyte;
  +        }
  +        else if (nbyte < APR_BUCKET_BUFF_SIZE) {
  +            buf = apr_bucket_alloc(APR_BUCKET_BUFF_SIZE, b->bucket_alloc);
  +            e = apr_bucket_heap_create(buf, APR_BUCKET_BUFF_SIZE,
  +                                       apr_bucket_free, b->bucket_alloc);
  +            APR_BRIGADE_INSERT_TAIL(b, e);
  +            memcpy(buf, str, nbyte);
  +            e->length = nbyte;
  +            buf += nbyte;
  +            remaining = APR_BUCKET_BUFF_SIZE - nbyte;
  +        }
  +        else { /* String larger than APR_BUCKET_BUFF_SIZE */
  +            e = apr_bucket_transient_create(str, nbyte, b->bucket_alloc);
  +            APR_BRIGADE_INSERT_TAIL(b, e);
  +            remaining = 0; /* create a new heap bucket for the next write */
  +        }
  +    }
  +
  +    /* Step 3: if necessary, output the brigade contents now
  +     */
  +    if (bytes_written >= APR_BUCKET_BUFF_SIZE) {
  +        return flush(b, ctx);
  +    }
  +
  +    return APR_SUCCESS;
  +}
  +
   APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
                                              apr_brigade_flush flush, void *ctx,
                                              const char *str)
  
  
  
  1.81      +2 -0      apr-util/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr-util/CHANGES,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- CHANGES	19 Sep 2002 08:04:17 -0000	1.80
  +++ CHANGES	21 Sep 2002 23:40:41 -0000	1.81
  @@ -1,5 +1,7 @@
   Changes with APR-util 0.9.2
   
  +  *) Add apr_brigade_writev()  [Brian Pane]
  +
     *) Add support for Berkeley DB 4.1.  [Justin Erenkrantz]
   
     *) Add --bindir option to apu-config.  [Justin Erenkrantz]
  
  
  

Mime
View raw message