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/include apr_buf.h
Date Tue, 11 Jul 2000 21:33:36 GMT
rbb         00/07/11 14:33:36

  Modified:    src/lib/apr/buckets ap_buf.c
               src/lib/apr/include apr_buf.h
  Added:       src/lib/apr/buckets ap_rmem_buf.c
  Log:
  First pass at implementing read only memory buckets.
  
  Revision  Changes    Path
  1.3       +47 -13    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ap_buf.c	2000/07/11 17:15:50	1.2
  +++ ap_buf.c	2000/07/11 21:33:35	1.3
  @@ -81,6 +81,9 @@
               newbuf->free = NULL;
               break;
           case AP_BUCKET_rmem:
  +            newbuf->data = ap_rmem_create();
  +            newbuf->free = NULL;
  +            break;
           case AP_BUCKET_file:
           case AP_BUCKET_filename:
           case AP_BUCKET_cached_entity:
  @@ -155,7 +158,7 @@
       orig = vec;
       e = b->head;
       while (e && nvec) {
  -	vec->iov_base = ap_get_bucket_char_str(e->bucket);
  +	vec->iov_base = (void *)ap_get_bucket_char_str(e->bucket);
   	vec->iov_len = ap_get_bucket_len(e->bucket);
   	e = e->next;
   	--nvec;
  @@ -212,7 +215,7 @@
       return APR_SUCCESS;
   }
   
  -APR_EXPORT(char *) ap_get_bucket_char_str(ap_bucket *b)
  +APR_EXPORT(const char *) ap_get_bucket_char_str(ap_bucket *b)
   {
       switch (b->color) {
           case AP_BUCKET_rwmem:
  @@ -220,6 +223,7 @@
           case AP_BUCKET_mmap:
               return ap_mmap_get_char_str(b->data);
           case AP_BUCKET_rmem:
  +            return ap_rmem_get_char_str(b->data);
           case AP_BUCKET_file:
           case AP_BUCKET_filename:
           case AP_BUCKET_cached_entity:
  @@ -239,6 +243,7 @@
           case AP_BUCKET_mmap:
               return ap_mmap_get_len(b->data);
           case AP_BUCKET_rmem:
  +            return ap_rmem_get_len(b->data);
           case AP_BUCKET_file:
           case AP_BUCKET_filename:
           case AP_BUCKET_cached_entity:
  @@ -252,21 +257,50 @@
   
   APR_EXPORT(int) ap_brigade_vputs(ap_bucket_brigade *b, ...)
   {
  -    ap_bucket_list *dptr = b->tail;
  -    ap_bucket_rwmem *r;
  +    ap_bucket *r;
       va_list va;
  -    int n;
  -
  -    if (dptr->bucket->color != AP_BUCKET_rwmem) {
  -        r = ap_rwmem_create();
  +    const char *x;
  +    int n, j, k, rv;
  +    ap_ssize_t i;
  +
  +    if (b->tail->bucket->color == AP_BUCKET_rwmem) {
  +        ap_bucket_rwmem *rw;
  +        rw = b->tail->bucket->data;
  +        /* 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
  +         */
  +        va_start(va, b);
  +        ap_rwmem_vputstrs(rw, va);
  +        va_end(va);
       }
  -    else {
  -        r = dptr->bucket->data;
  -    }
       
       va_start(va, b);
  -    n = ap_rwmem_vputstrs(r, va);
  -    va_end(va);
  +    for (k = 0;;) {
  +        r = ap_bucket_new(AP_BUCKET_rmem);
  +        x = va_arg(va, const char *);
  +        if (x == NULL)
  +            break;
  +        j = strlen(x);
  +       
  +        rv = ap_rmem_write(r->data, x, j, &i);
  +        if (i != j) {
  +            /* Do we need better error reporting?  */
  +            return -1;
  +        }
  +        k += i;
  +
  +        /* This really requires an API.  Basically we are just adding
  +         * a bucket to a bucket list.
  +         */
  +        b->tail->next = ap_bucket_list_create();
  +        b->tail->next->prev = b->tail->next;
  +        b->tail = b->tail->next;
  +        b->tail->bucket = r;
  +    }
  +    va_end(v);
   
       return n;
   }
  
  
  
  1.1                  apache-2.0/src/lib/apr/buckets/ap_rmem_buf.c
  
  Index: ap_rmem_buf.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1996-1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group and was originally based
   * on public domain software written at the National Center for
   * Supercomputing Applications, University of Illinois, Urbana-Champaign.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include "apr_private.h"
  #include "apr_buf.h"
  #include <stdlib.h>
  
  #ifndef DEFAULT_RWBUF_SIZE
  #define DEFAULT_RWBUF_SIZE (4096)
  #endif
  
  APR_EXPORT(ap_bucket_rmem *) ap_rmem_create(void)
  {
      ap_bucket_rmem *newbuf;
      newbuf = calloc(1, sizeof(*newbuf));
      return newbuf;
  }
  
  APR_EXPORT(const char *) ap_rmem_get_char_str(ap_bucket_rmem *b)
  {
      return b->start;
  }
  
  APR_EXPORT(int) ap_rmem_get_len(ap_bucket_rmem *b)
  {
      return b->end - b->start;
  }
  
  /*
   * save nbyte bytes to the bucket.
   * Only returns fewer than nbyte if an error ocurred.
   * Returns -1 if no bytes were written before the error ocurred.
   * 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)
  {
      int amt;
      int total;
  
      if (nbyte == 0) {
          *bytes_written = 0;
          return APR_SUCCESS;
      }
  
      /* We should probably do some checking to make sure we don't allocate too
       * much memory, but that can wait for the second pass.
       */
      b->start = buf;
      b->end = b->start + nbyte;
      *bytes_written = nbyte;
      return APR_SUCCESS;
  }
  
  
  
  
  1.3       +30 -1     apache-2.0/src/lib/apr/include/apr_buf.h
  
  Index: apr_buf.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_buf.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- apr_buf.h	2000/07/11 17:15:51	1.2
  +++ apr_buf.h	2000/07/11 21:33:36	1.3
  @@ -155,7 +155,7 @@
   APR_EXPORT(ap_status_t) ap_bucket_destroy(ap_bucket *e);
   
   /* Convert a bucket to a char * */
  -APR_EXPORT(char *) ap_get_bucket_char_str(ap_bucket *b);
  +APR_EXPORT(const char *) ap_get_bucket_char_str(ap_bucket *b);
   
   /* get the length of the data in the bucket */
   APR_EXPORT(int) ap_get_bucket_len(ap_bucket *b);
  @@ -207,6 +207,35 @@
   APR_EXPORT(int) ap_mmap_get_len(ap_bucket_mmap *b);
   
   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 */
  +APR_EXPORT(ap_bucket_rmem *) ap_rmem_create(void);
  +
  +/* destroy a read only memory bucket */
  +APR_EXPORT(void) ap_rmem_destroy(void *e);
  +
  +/* Convert a read only bucket into a char * */
  +APR_EXPORT(const char *) ap_rmem_get_char_str(ap_bucket_rmem *b);
  +
  +/* get the length of the data in the rmem bucket */
  +APR_EXPORT(int) ap_rmem_get_len(ap_bucket_rmem *b);
  +
  +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_vputs(ap_bucket_rmem *b, va_list va);
  +
  +APR_EXPORT(int) ap_rmem_vputstrs(ap_bucket_rmem *b, va_list va);
   
   #endif
   
  
  
  

Mime
View raw message