apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr-util/buckets apr_brigade.c
Date Sun, 26 Aug 2001 03:15:37 GMT
rbb         01/08/25 20:15:37

  Modified:    .        CHANGES
               buckets  apr_brigade.c
  Log:
  Fix apr_brigade_vprintf so that it can handle more than
  4k of data at one time.
  
  Submitted by:	Cody Sherr <csherr@covalent.net>
  
  Revision  Changes    Path
  1.32      +3 -0      apr-util/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr-util/CHANGES,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- CHANGES	2001/08/19 16:08:36	1.31
  +++ CHANGES	2001/08/26 03:15:36	1.32
  @@ -1,5 +1,8 @@
   Changes with APR-util b1  
   
  +  *) Fix apr_brigade_vprintf so that it can handle more than
  +     4k of data at one time.  [Cody Sherr <csherr@covalent.net>]
  +
     *) prefix UNP_* flags with APR_URI_
   
        rename:
  
  
  
  1.24      +59 -9     apr-util/buckets/apr_brigade.c
  
  Index: apr_brigade.c
  ===================================================================
  RCS file: /home/cvs/apr-util/buckets/apr_brigade.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- apr_brigade.c	2001/08/16 07:13:07	1.23
  +++ apr_brigade.c	2001/08/26 03:15:37	1.24
  @@ -53,6 +53,7 @@
    */
   
   #include "apr.h"
  +#include "apr_lib.h"
   #include "apr_strings.h"
   #include "apr_pools.h"
   #include "apr_tables.h"
  @@ -383,18 +384,67 @@
       return rv;
   }
   
  -APU_DECLARE(apr_status_t) apr_brigade_vprintf(apr_bucket_brigade *b, 
  +struct bridgade_vprintf_data_t {
  +    apr_vformatter_buff_t vbuff;
  +
  +    apr_bucket_brigade *b;  /* associated brigade */
  +    apr_brigade_flush *flusher; /* flushing function */
  +    void *ctx;
  +
  +    char *cbuff; /* buffer to flush from */
  +};
  +
  +static apr_status_t brigade_flush(apr_vformatter_buff_t *buff)
  +{
  +    /* callback function passed to ap_vformatter to be
  +     * called when vformatter needs to buff and
  +     * buff.curpos > buff.endpos
  +     */
  +
  +    /* "downcast," have really passed a bridgade_vprintf_data_t* */
  +    struct bridgade_vprintf_data_t *vd = (struct bridgade_vprintf_data_t*)buff;
  +    apr_status_t res = APR_SUCCESS;
  +
  +    res = apr_brigade_write(vd->b, *vd->flusher, vd->ctx, vd->cbuff,
  +                          APR_BUCKET_BUFF_SIZE);
  +
  +    if(res != APR_SUCCESS) {
  +      return -1;
  +    }
  +
  +    vd->vbuff.curpos = vd->cbuff;
  +    vd->vbuff.endpos = vd->cbuff + APR_BUCKET_BUFF_SIZE;
  +
  +    return res;
  +}
  +
  +APU_DECLARE(apr_status_t) apr_brigade_vprintf(apr_bucket_brigade *b,
                                                 apr_brigade_flush flush,
  -                                              void *ctx, 
  +                                              void *ctx,
                                                 const char *fmt, va_list va)
   {
  -    /* XXX:  This needs to be replaced with a function to printf
  -     * directly into a bucket.  I'm being lazy right now.  RBB
  -     */
  -    char buf[4096];
  +    /* the cast, in order of appearance */
  +    struct bridgade_vprintf_data_t vd;
  +    char buf[APR_BUCKET_BUFF_SIZE];
  +    apr_size_t written;
  +
  +    vd.vbuff.curpos = buf;
  +    vd.vbuff.endpos = buf + APR_BUCKET_BUFF_SIZE;
  +    vd.b = b;
  +    vd.flusher = &flush;
  +    vd.ctx = ctx;
  +    vd.cbuff = buf;
   
  -    apr_vsnprintf(buf, sizeof(buf), fmt, va);
  +    written = apr_vformatter(brigade_flush, &vd.vbuff, fmt, va);
   
  -    return apr_brigade_puts(b, flush, ctx, buf);
  -} 
  +    if (written == -1) {
  +      return -1;
  +    }
  +
  +    /* tack on null terminator to remaining string */
  +    *(vd.vbuff.curpos) = '\0';
  +
  +    /* write out what remains in the buffer */
  +    return apr_brigade_write(b, flush, ctx, buf, vd.vbuff.curpos - buf);
  +}
   
  
  
  

Mime
View raw message