httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/buckets ap_buf.c ap_mmap_buf.c ap_rmem_buf.c ap_rwmem_buf.c apr_buf.h
Date Fri, 14 Jul 2000 00:24:34 GMT
rbb         00/07/13 17:24:33

  Modified:    src/lib/apr/buckets ap_buf.c ap_mmap_buf.c ap_rmem_buf.c
                        ap_rwmem_buf.c apr_buf.h
  Log:
  The write functions are now also function pointers.  This allows people
  to easily insert data to a bucket brigade.  I need to re-write the brigade
  insert routines, but that can come tomorrow.
  
  Revision  Changes    Path
  1.12      +23 -8     apache-2.0/src/lib/apr/buckets/ap_buf.c
  
  Index: ap_buf.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_buf.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ap_buf.c	2000/07/13 21:48:33	1.11
  +++ ap_buf.c	2000/07/14 00:24:33	1.12
  @@ -56,14 +56,15 @@
    */
   
   #include "apr_private.h"
  +#include "apr_pools.h"
   #include "apr_lib.h"
   #include "apr_errno.h"
   #include <stdlib.h>
   #include <sys/uio.h>
   #include "apr_buf.h"
   
  -/* We are creating a new bucket here.  We could replace the switch with a
  - * function pointer if we want to.  I'm not sure it's a real win though.
  +/* We are creating a new bucket here.  The buckets that are created
  + * have the correct function pointers and types when they are created. 
    */
   APR_EXPORT(ap_bucket *) ap_bucket_new(ap_bucket_color_e color)
   {
  @@ -110,7 +111,7 @@
   {
       ap_bucket_brigade *b;
   
  -    b = malloc(sizeof(*b));
  +    b = ap_palloc(p, sizeof(*b));
       b->p = p;
       b->head = b->tail = NULL;
   
  @@ -276,15 +277,29 @@
   
       if (b->tail && b->tail->bucket && 
           b->tail->bucket->color == AP_BUCKET_rwmem) {
  -        ap_bucket_rwmem *rw;
  -        rw = b->tail->bucket->data;
  +        ap_bucket *rw;
  +        rw = b->tail->bucket;
           /* I have no idea if this is a good idea or not.  Probably not.
            * Basically, if the last bucket in the list is a rwmem bucket,
            * then we just add to it instead of allocating a new read only
            * bucket.  This is incredibly easy to take out if it is a bad 
            * idea.  RBB
            */
  -        ap_rwmem_vputstrs(rw, va);
  +        for (k = 0;;) {
  +            x = va_arg(va, const char *);
  +            if (x == NULL)
  +                break;
  +            j = strlen(x);
  +           
  +            rv = rw->insert(rw, x, j, &i);
  +            if (i != j) {
  +                /* Do we need better error reporting?  */
  +                return -1;
  +            }
  +            k += i;
  +
  +            ap_bucket_brigade_append_bucket(b, rw);
  +        }        
       }
       
       for (k = 0;;) {
  @@ -294,7 +309,7 @@
               break;
           j = strlen(x);
          
  -        rv = ap_rwmem_write(r->data, x, j, &i);
  +        rv = r->insert(r, x, j, &i);
           if (i != j) {
               /* Do we need better error reporting?  */
               return -1;
  @@ -330,7 +345,7 @@
       res = ap_vsnprintf(buf, 4096, fmt, va);
   
       r = ap_bucket_new(AP_BUCKET_rwmem);
  -    res = ap_rwmem_write(r->data, buf, strlen(buf), &i);
  +    res = r->insert(r, buf, strlen(buf), &i);
       ap_bucket_brigade_append_bucket(b, r);
   
       return res;
  
  
  
  1.4       +16 -6     apache-2.0/src/lib/apr/buckets/ap_mmap_buf.c
  
  Index: ap_mmap_buf.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_mmap_buf.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ap_mmap_buf.c	2000/07/13 21:48:33	1.3
  +++ ap_mmap_buf.c	2000/07/14 00:24:33	1.4
  @@ -68,9 +68,22 @@
   static int mmap_get_len(ap_bucket *e)
   {
       ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
  -    return b->data->size;
  +    return b->len;
   }
   
  +static ap_status_t mmap_bucket_insert(ap_bucket *e, const void *buf, 
  +                                      ap_size_t nbytes, ap_ssize_t *w)
  +{
  +    ap_bucket_mmap *b = (ap_bucket_mmap *)e->data;
  +    const ap_mmap_t *mm = buf;
  +
  +    b->data = mm;
  +    b->len = nbytes;
  +    *w = nbytes;
  +    return APR_SUCCESS;
  +}
  +    
  +
   APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void)
   {
       ap_bucket *newbuf;
  @@ -80,18 +93,15 @@
       b                 = malloc(sizeof(*b));
   
       b->data      = NULL;
  +    b->len       = 0;
   
       newbuf->color     = AP_BUCKET_mmap;
       newbuf->getstr    = mmap_get_str;
       newbuf->getlen    = mmap_get_len;
  +    newbuf->insert    = mmap_bucket_insert;
       newbuf->free      = NULL;
       newbuf->data      = b;
       
       return newbuf;
   }
   
  -APR_EXPORT(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm)
  -{
  -    b->data = mm;
  -}
  -    
  
  
  
  1.5       +26 -23    apache-2.0/src/lib/apr/buckets/ap_rmem_buf.c
  
  Index: ap_rmem_buf.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_rmem_buf.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ap_rmem_buf.c	2000/07/13 21:48:33	1.4
  +++ ap_rmem_buf.c	2000/07/14 00:24:33	1.5
  @@ -75,25 +75,6 @@
       return (char *)b->end - (char *)b->start;
   }
   
  -APR_EXPORT(ap_bucket *) ap_rmem_create(void)
  -{
  -    ap_bucket *newbuf;
  -    ap_bucket_rmem *b;
  -
  -    newbuf                = malloc(sizeof(*newbuf));
  -    b                     = malloc(sizeof(*b)); 
  -
  -    b->alloc_len          = 0;
  -    b->start = b->end     = NULL;
  -
  -    newbuf->color         = AP_BUCKET_rmem;
  -    newbuf->getstr        = rmem_get_str;
  -    newbuf->getlen        = rmem_get_len;
  -    newbuf->free          = NULL;
  -    newbuf->data          = b;
  -    return newbuf;
  -}
  -
   /*
    * save nbyte bytes to the bucket.
    * Only returns fewer than nbyte if an error ocurred.
  @@ -101,11 +82,13 @@
    * It is worth noting that if an error occurs, the buffer is in an unknown
    * state.
    */
  -APR_EXPORT(int) ap_rmem_write(ap_bucket_rmem *b, const void *buf,
  -                               ap_size_t nbyte, ap_ssize_t *bytes_written)
  +static ap_status_t rmem_insert(ap_bucket *e, const void *buf,
  +                               ap_size_t nbyte, ap_ssize_t *w)
   {
  +    ap_bucket_rmem *b = (ap_bucket_rmem *)e->data;
  +
       if (nbyte == 0) {
  -        *bytes_written = 0;
  +        *w = 0;
           return APR_SUCCESS;
       }
   
  @@ -114,7 +97,27 @@
        */
       b->start = buf;
       b->end = (char *)b->start + nbyte;
  -    *bytes_written = nbyte;
  +    *w = nbyte;
       return APR_SUCCESS;
  +}
  +
  +APR_EXPORT(ap_bucket *) ap_rmem_create(void)
  +{
  +    ap_bucket *newbuf;
  +    ap_bucket_rmem *b;
  +
  +    newbuf                = malloc(sizeof(*newbuf));
  +    b                     = malloc(sizeof(*b)); 
  +
  +    b->alloc_len          = 0;
  +    b->start = b->end     = NULL;
  +
  +    newbuf->color         = AP_BUCKET_rmem;
  +    newbuf->getstr        = rmem_get_str;
  +    newbuf->getlen        = rmem_get_len;
  +    newbuf->insert        = rmem_insert;
  +    newbuf->free          = NULL;
  +    newbuf->data          = b;
  +    return newbuf;
   }
   
  
  
  
  1.5       +25 -45    apache-2.0/src/lib/apr/buckets/ap_rwmem_buf.c
  
  Index: ap_rwmem_buf.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/ap_rwmem_buf.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ap_rwmem_buf.c	2000/07/13 21:48:33	1.4
  +++ ap_rwmem_buf.c	2000/07/14 00:24:33	1.5
  @@ -81,28 +81,6 @@
       free(d->alloc_addr);
   }
   
  -APR_EXPORT(ap_bucket *) ap_rwmem_create(void)
  -{
  -    ap_bucket *newbuf;
  -    ap_bucket_rwmem *b;
  -
  -    newbuf = malloc(sizeof(*newbuf));
  -    b = malloc(sizeof(*b));
  -    
  -    b->alloc_addr = calloc(DEFAULT_RWBUF_SIZE, 1);
  -    b->alloc_len  = DEFAULT_RWBUF_SIZE;
  -    b->start      = b->alloc_addr;
  -    b->end        = b->alloc_addr;
  -
  -    newbuf->color      = AP_BUCKET_rwmem;
  -    newbuf->getstr     = rwmem_get_str;
  -    newbuf->getlen     = rwmem_get_len;
  -    newbuf->free       = rwmem_destroy;
  -    newbuf->data       = b;
  -
  -    return newbuf;
  -}
  -
   /*
    * save nbyte bytes to the bucket.
    * Only returns fewer than nbyte if an error occurred.
  @@ -110,14 +88,15 @@
    * It is worth noting that if an error occurs, the buffer is in an unknown
    * state.
    */
  -APR_EXPORT(int) ap_rwmem_write(ap_bucket_rwmem *b, const void *buf,
  -                               ap_size_t nbyte, ap_ssize_t *bytes_written)
  +static ap_status_t rwmem_insert(ap_bucket *e, const void *buf,
  +                                ap_size_t nbyte, ap_ssize_t *w)
   {
       int amt;
       int total;
  +    ap_bucket_rwmem *b = (ap_bucket_rwmem *)e->data;
   
       if (nbyte == 0) {
  -        *bytes_written = 0;
  +        *w = 0;
           return APR_SUCCESS;
       }
   
  @@ -136,29 +115,30 @@
       /* now we know that nbyte < b->alloc_len */
       memcpy(b->end, buf, nbyte);
       b->end = (char *)b->end + nbyte;
  -    *bytes_written = total + nbyte;
  +    *w = total + nbyte;
       return APR_SUCCESS;
   }
   
  -APR_EXPORT(int) ap_rwmem_vputstrs(ap_bucket_rwmem *b, va_list va)
  +APR_EXPORT(ap_bucket *) ap_rwmem_create(void)
   {
  -    int j, k;
  -    ap_ssize_t i;
  -    const char *x;
  -    int rv;
  -
  -    for (k = 0;;) {
  -        x = va_arg(va, const char *);
  -        if (x == NULL)
  -            break;
  -        j = strlen(x);
  -        rv = ap_rwmem_write(b, x, j, &i);
  -        if (i != j) {
  -            /* Do we need better error reporting?  */
  -            return -1;
  -        }
  -        k += i;
  -    }
  +    ap_bucket *newbuf;
  +    ap_bucket_rwmem *b;
   
  -    return k;
  +    newbuf = malloc(sizeof(*newbuf));
  +    b = malloc(sizeof(*b));
  +    
  +    b->alloc_addr = calloc(DEFAULT_RWBUF_SIZE, 1);
  +    b->alloc_len  = DEFAULT_RWBUF_SIZE;
  +    b->start      = b->alloc_addr;
  +    b->end        = b->alloc_addr;
  +
  +    newbuf->color      = AP_BUCKET_rwmem;
  +    newbuf->getstr     = rwmem_get_str;
  +    newbuf->getlen     = rwmem_get_len;
  +    newbuf->insert     = rwmem_insert;
  +    newbuf->free       = rwmem_destroy;
  +    newbuf->data       = b;
  +
  +    return newbuf;
   }
  +
  
  
  
  1.13      +39 -43    apache-2.0/src/lib/apr/buckets/apr_buf.h
  
  Index: apr_buf.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/buckets/apr_buf.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- apr_buf.h	2000/07/13 21:48:34	1.12
  +++ apr_buf.h	2000/07/14 00:24:33	1.13
  @@ -86,6 +86,15 @@
       void *data;				  /* for use by free() */
       const char *(*getstr)(ap_bucket *e);  /* Get the string */
       int (*getlen)(ap_bucket *e);          /* Get the length of the string */
  +    /* Insert into a bucket.  The buf is a different type based on the
  +     * bucket type used.  For example, with AP_BUCKET_mmap it is an ap_mmap_t
  +     * for AP_BUCKET_file it is an ap_file_t, and for AP_BUCKET_rwmem it is
  +     * a char *.  The nbytes is the amount of actual data in buf.  This is
  +     * not the sizeof(buf), it is the actual number of bytes in the char *
  +     * that buf resolves to.  written is how much of that data was inserted
  +     * into the bucket.
  +     */ 
  +    int (*insert)(ap_bucket *e, const void *buf, ap_size_t nbytes, ap_ssize_t *w);
   };
   
   typedef struct ap_bucket_list ap_bucket_list;
  @@ -106,6 +115,35 @@
       ap_bucket_list *tail;               /* The end of the brigade */
   };
   
  +/*    ******  Different bucket types   *****/
  +
  +typedef struct ap_bucket_rmem ap_bucket_rmem;
  +struct ap_bucket_rmem {
  +    size_t  alloc_len;                  /* how much was allocated */
  +    const void    *start;               /* Where does the actual data start
  +                                           in the alloc'ed block */
  +    const void    *end;                 /* where does the data actually end? */
  +};
  +
  +typedef struct ap_bucket_rwmem ap_bucket_rwmem;
  +struct ap_bucket_rwmem {
  +    void    *alloc_addr;                /* Where does the data start */
  +    size_t  alloc_len;                  /* how much was allocated */
  +    void    *start;                     /* Where does the actual data start
  +                                           in the alloc'ed block */
  +    void    *end;                       /* where does the data actually end? */
  +};
  +
  +typedef struct ap_bucket_mmap ap_bucket_mmap;
  +struct ap_bucket_mmap {
  +    const ap_mmap_t *data;
  +    int       len;           /* The amount of data in the mmap that we are 
  +                              * referencing with this bucket.  This may be 
  +                              * smaller than the length in the data object, 
  +                              * but it may not be bigger.
  +                              */
  +};
  +
   /*   ******  Bucket Brigade Functions  *****  */
   
   /* Create a new bucket brigade */
  @@ -173,56 +211,14 @@
   /* get the length of the data in the bucket */
   APR_EXPORT(int) ap_get_bucket_len(ap_bucket *b);
   
  -/*   ******  RWMEM Functions  *****  */
  -
  -typedef struct ap_bucket_rwmem ap_bucket_rwmem;
  -struct ap_bucket_rwmem {
  -    void    *alloc_addr;                /* Where does the data start */
  -    size_t  alloc_len;                  /* how much was allocated */
  -    void    *start;                     /* Where does the actual data start
  -                                           in the alloc'ed block */
  -    void    *end;                       /* where does the data actually end? */
  -};
  -
   /* Create a read/write memory bucket */
   APR_EXPORT(ap_bucket *) ap_rwmem_create(void);
   
  -APR_EXPORT(int) ap_rwmem_write(ap_bucket_rwmem *b, const void *buf,
  -                               ap_size_t nbyte, ap_ssize_t *bytes_written);
  -
  -APR_EXPORT(int) ap_rwmem_vputstrs(ap_bucket_rwmem *b, va_list va);
  -
  -/*   ******  MMAP Functions  *****  */
  -
  -typedef struct ap_bucket_mmap ap_bucket_mmap;
  -struct ap_bucket_mmap {
  -    ap_mmap_t *data;
  -};
  -
   /* Create a mmap memory bucket */
   APR_EXPORT(ap_bucket *) ap_mmap_bucket_create(void);
   
  -APR_EXPORT(void) ap_mmap_bucket_insert(ap_bucket_mmap *b, ap_mmap_t *mm);
  -
  -/*   ******  RMEM Functions  *****  */
  -
  -typedef struct ap_bucket_rmem ap_bucket_rmem;
  -struct ap_bucket_rmem {
  -    size_t  alloc_len;                  /* how much was allocated */
  -    const void    *start;               /* Where does the actual data start
  -                                           in the alloc'ed block */
  -    const void    *end;                 /* where does the data actually end? */
  -};
  -
  -/* Create a read only memory bucket */
  +/* Create a read only memory bucket. */
   APR_EXPORT(ap_bucket *) ap_rmem_create(void);
  -
  -APR_EXPORT(int) ap_rmem_write(ap_bucket_rmem *b, const void *buf,
  -                               ap_size_t nbyte, ap_ssize_t *bytes_written);
  -
  -APR_EXPORT(int) ap_rmem_vputstrs(ap_bucket_rmem *b, va_list va);
  -
  -/*   ******  RMEM Functions  *****  */
   
   /* Create an End of Stream bucket */
   APR_EXPORT(ap_bucket *) ap_eos_create(void);
  
  
  

Mime
View raw message