You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@locus.apache.org on 2000/09/10 22:45:18 UTC

cvs commit: apache-2.0/src/modules/file_cache cache_util.c file_cache.c mod_cache.c mod_cache.h

rbb         00/09/10 13:45:18

  Modified:    src      CHANGES
               src/ap   ap_cache.c
               src/include ap_cache.h buff.h
               src/main buff.c
               src/modules/file_cache cache_util.c file_cache.c mod_cache.c
                        mod_cache.h
  Log:
  Remove ap_bopenf from buff.[ch].  This required changing the cache code to
  use apr files directly instead of going through BUFFs.  I have compiled
  this code, and run a few tests with it.  It seems to work, but somebody
  with a better understanding of the cache code should probably run more
  thorough tests with it as well.
  
  Revision  Changes    Path
  1.217     +4 -0      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.216
  retrieving revision 1.217
  diff -u -r1.216 -r1.217
  --- CHANGES	2000/09/08 20:34:33	1.216
  +++ CHANGES	2000/09/10 20:45:15	1.217
  @@ -1,4 +1,8 @@
   Changes with Apache 2.0a7
  +  *) Remove ap_bopenf from buff code.  This required modifying the file_cache
  +     code to use APR file's directly instead of going through BUFFs.
  +     [Ryan Bloom]
  +
     *) Fix compile break on some platforms for mod_mime_magic.c
        [John K. Sterling <st...@covalent.net>]
   
  
  
  
  1.9       +7 -5      apache-2.0/src/ap/ap_cache.c
  
  Index: ap_cache.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/ap/ap_cache.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ap_cache.c	2000/08/14 00:55:20	1.8
  +++ ap_cache.c	2000/09/10 20:45:15	1.9
  @@ -175,26 +175,28 @@
       VERIFY_IMPL(el->cache, cache_el_reset);
       return el->cache->meth.cache_el_reset(el, AP_CACHE_HEADER);
   }
  -apr_status_t ap_cache_el_data(ap_cache_el *el, BUFF **b)
  +apr_status_t ap_cache_el_data(ap_cache_el *el, apr_file_t **b)
   {
       if(!b || !el) return APR_BADARG;
       *b = NULL;
       VERIFY_IMPL(el->cache, cache_el_data);
       return el->cache->meth.cache_el_data(el, b);
   }
  -apr_status_t ap_cache_el_data_append(ap_cache_el *el, BUFF *data)
  +apr_status_t ap_cache_el_data_append(ap_cache_el *el, apr_file_t *data)
   {
  -    BUFF *place;
  +    apr_file_t *place;
       char buffer[HUGE_STRING_LEN];
       apr_status_t ret = APR_SUCCESS;
       apr_ssize_t nbytes, i, o;
       
       if((ret = ap_cache_el_data(el, &place)) != APR_SUCCESS) return ret;
  -    while(ap_bread(data, buffer, HUGE_STRING_LEN, &nbytes) == APR_SUCCESS && nbytes) {
  +    nbytes = HUGE_STRING_LEN;
  +    while(apr_read(data, buffer, &nbytes) == APR_SUCCESS && nbytes) {
           o = 0;
           while(nbytes)
           {
  -            ap_bwrite(place, buffer + o, nbytes, &i);
  +            i = nbytes;
  +            apr_write(place, buffer + o, &i);
               o += i;
               nbytes -= i;
           }
  
  
  
  1.8       +12 -12    apache-2.0/src/include/ap_cache.h
  
  Index: ap_cache.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/include/ap_cache.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ap_cache.h	2000/08/14 00:59:11	1.7
  +++ ap_cache.h	2000/09/10 20:45:16	1.8
  @@ -94,7 +94,7 @@
    *
    *  ap_cache_handle_t *my_cache;
    *  ap_cache_el *element;
  - *  BUFF *element_buff;
  + *  apr_file_t *element_buff;
    *
    *  ap_cache_create(&my_cache, "Cache of Farm Animals");
    *
  @@ -274,27 +274,27 @@
   
   /* (E) Works on the data section */
   /**
  - * Retrieve a BUFF for a given cache element, where this data goes is opaque to all
  - * clients of this API. You can do all operations on the BUFF and trust the underlying
  + * Retrieve a apr_file_t for a given cache element, where this data goes is opaque to all
  + * clients of this API. You can do all operations on the apr_file_t and trust the underlying
    * caching module will accept the data and put it in the appropriate place.
    * @param  The element to retrieve data
  - * @param  Where to put the BUFF structure when it comes back. In some cases this
  + * @param  Where to put the apr_file_t structure when it comes back. In some cases this
    *         will be a normal buff that will either write to a network, or disk - but
    *         you should not rely on it going anywhere in a caching module as the destination
    *         for all data is opaque.
  - * @deffunc apr_status_t ap_cache_el_data(ap_cache_el *el, BUFF **)
  + * @deffunc apr_status_t ap_cache_el_data(ap_cache_el *el, apr_file_t **)
    */
  -apr_status_t ap_cache_el_data(ap_cache_el *el, BUFF **);
  +apr_status_t ap_cache_el_data(ap_cache_el *el, apr_file_t **);
   
   /**
  - * Convenience function to put an existing BUFF into a cache_el's data section. This
  - * function will probably not be fully optimal - and will actually just pipe one BUFF
  + * Convenience function to put an existing apr_file_t into a cache_el's data section. This
  + * function will probably not be fully optimal - and will actually just pipe one apr_file_t
    * to another.
    * @param  The element to append to
  - * @param  An existing BUFF to append onto the ap_cache_el's stream of data.
  - * @deffunc apr_status_t ap_cache_el_data_append(ap_cache_el *el, BUFF *data)
  + * @param  An existing apr_file_t to append onto the ap_cache_el's stream of data.
  + * @deffunc apr_status_t ap_cache_el_data_append(ap_cache_el *el, apr_file_t *data)
    */
  -apr_status_t ap_cache_el_data_append(ap_cache_el *el, BUFF *data);
  +apr_status_t ap_cache_el_data_append(ap_cache_el *el, apr_file_t *data);
   
   /**
    * Clear the data section of an existing cache_el. You may use this if you are 
  @@ -350,7 +350,7 @@
       apr_status_t (*cache_el_header_walk)(ap_cache_el *el, 
                                        int (*comp)(void *, const char *, const char *), void *rec, va_list);
       apr_status_t (*cache_el_hdr)(ap_cache_el *el, const char *name, const char *val, ap_cache_query flag);
  -    apr_status_t (*cache_el_data)(ap_cache_el *el, BUFF **);
  +    apr_status_t (*cache_el_data)(ap_cache_el *el, apr_file_t **);
       apr_status_t (*cache_el_reset)(ap_cache_el *, ap_cache_part flag);
       apr_status_t (*cache_el_final)(ap_cache_el *el);
   } ap_cache_methods;
  
  
  
  1.36      +0 -3      apache-2.0/src/include/buff.h
  
  Index: buff.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/include/buff.h,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- buff.h	2000/08/23 00:01:51	1.35
  +++ buff.h	2000/09/10 20:45:16	1.36
  @@ -224,9 +224,6 @@
   API_EXPORT(void) ap_bpush_socket(BUFF *fb, apr_socket_t *sock);
   API_EXPORT(void) ap_bpop_socket(apr_socket_t **sock, BUFF *fb);
   
  -/* XXX - unused right now - mvsk */
  -API_EXPORT(BUFF *) ap_bopenf(apr_pool_t *a, const char *name, int flg, int mode);
  -
   API_EXPORT(apr_status_t) ap_bsetopt(BUFF *fb, int optname, const void *optval);
   API_EXPORT(apr_status_t) ap_bgetopt(BUFF *fb, int optname, void *optval);
   API_EXPORT(int) ap_bsetflag(BUFF *fb, int flag, int value);
  
  
  
  1.62      +0 -19     apache-2.0/src/main/buff.c
  
  Index: buff.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/buff.c,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- buff.c	2000/09/09 11:54:44	1.61
  +++ buff.c	2000/09/10 20:45:16	1.62
  @@ -1266,22 +1266,3 @@
       return res;
   }
   
  -#if APR_FILES_AS_SOCKETS
  -API_EXPORT(BUFF *) ap_bopenf(apr_pool_t *a, const char *name, int flg, int mode)
  -{
  -    BUFF *fb;
  -    apr_status_t rv;
  -    apr_file_t *file = NULL;
  -    apr_socket_t *sock = NULL;
  -    rv = apr_open(&file, name, flg, 0, a);
  -    if ((rv != APR_SUCCESS) || (file == NULL)) {
  -        return NULL;
  -    }
  -    apr_socket_from_file(&sock, file);
  -    fb = ap_bcreate(a, ((flg &(B_RD|B_RDWR)) ? B_RD : 0)
  -                     | ((flg & (B_WR|B_RDWR)) ? B_WR : 0));
  -    ap_bpush_socket(fb, sock);
  -    return fb;
  -}
  -#endif
  -
  
  
  
  1.5       +41 -23    apache-2.0/src/modules/file_cache/cache_util.c
  
  Index: cache_util.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/file_cache/cache_util.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- cache_util.c	2000/08/06 06:07:38	1.4
  +++ cache_util.c	2000/09/10 20:45:17	1.5
  @@ -60,6 +60,7 @@
   #include "http_conf_globals.h"
   #include "http_log.h"
   #include "http_main.h"
  +#include "apr_strings.h"
   #include "apr_md5.h"
   
   int file_cache_get_hdrs(cache_req *cq)
  @@ -80,7 +81,7 @@
               mode |= APR_CREATE | APR_EXCL;
           }
           if(!file ||
  -           !(cq->fp = ap_bopenf(cq->el.cache->pool, file, mode, APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD)))
  +           (apr_open(&cq->fp, file, mode, APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, cq->el.cache->pool) != APR_SUCCESS))
           {
               ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
                            "cache: error opening file %s",
  @@ -132,6 +133,17 @@
       }
       y[sizeof(j) * 2] = '\0';
   }
  +
  +static int flookc(apr_file_t *in)
  +{
  +    char c;
  +
  +    if (apr_getc(&c, in) == APR_SUCCESS) {
  +        apr_ungetc(c, in);
  +    }
  +    return c;
  +}
  +
   /* NOTE: This routine is taken from http_protocol::getline()
    * because the old code found in the proxy module was too
    * difficult to understand and maintain.
  @@ -149,7 +161,7 @@
    *       then the actual input line exceeded the buffer length,
    *       and it would be a good idea for the caller to puke 400 or 414.
    */
  -static int cache_getline(char *s, int n, BUFF *in, int fold)
  +static int cache_getline(char *s, int n, apr_file_t *in, int fold)
   {
       char *pos, next;
       int retval;
  @@ -158,10 +170,10 @@
       pos = s;
   
       do {
  -        retval = ap_bgets(pos, n, in);     /* retval == -1 if error, 0 if EOF */
  +        retval = apr_fgets(pos, n, in); /* retval == -1 if error, 0 if EOF */
   
  -        if (retval <= 0)
  -            return ((retval < 0) && (total == 0)) ? -1 : total;
  +        if (retval != 0)
  +            return (retval == APR_EOF) ? -1 : total;
   
           /* retval is the number of characters read, not including NUL      */
   
  @@ -182,7 +194,7 @@
            * the next line begins with a continuation character.
            */
       } while (fold && (retval != 1) && (n > 1)
  -                  && (next = ap_blookc(in))
  +                  && (next = flookc(in))
                     && ((next == ' ') || (next == '\t')));
   
       return total;
  @@ -190,7 +202,7 @@
   
   /* These two functions get and put state information into the data file for an ap_cache_el, this state
      informatino will be read and written transparent to clients of this module */
  -static int file_cache_read_mydata(BUFF *fp, cache_req *cq)
  +static int file_cache_read_mydata(apr_file_t *fp, cache_req *cq)
   {
       char urlbuff[1034];
       int len, offset=0;
  @@ -203,7 +215,7 @@
        * date SP expire SP count CRLF
        * dates are stored as hex seconds since 1970
        */
  -    len = ap_bgets(urlbuff, sizeof urlbuff, fp);
  +    len = apr_fgets(urlbuff, sizeof urlbuff, fp);
       if (len == -1)
           return -1;
       if (len == 0 || urlbuff[len - 1] != '\n')
  @@ -220,7 +232,7 @@
       cq->version = ap_cache_hex2msec(urlbuff + offset);
       
       /* check that we have the same URL */
  -    len = ap_bgets(urlbuff, sizeof urlbuff, fp);
  +    len = apr_fgets(urlbuff, sizeof urlbuff, fp);
       if (len == -1)
           return 0;
       if (len == 0 || strncmp(urlbuff, "X-NAME: ", 7) != 0 || urlbuff[len - 1] != '\n')
  @@ -246,7 +258,7 @@
       char *value, *end;
       char field[MAX_STRING_LEN];
       char buffer[1034];
  -    BUFF *f;
  +    apr_file_t *f = NULL;
       if(cq->state & FC_READ_HEADERS)
           return 1;
       
  @@ -257,11 +269,11 @@
           return 1; 
       }
       
  -    if(!cq->hdrsfile || !(f = ap_bopenf(cq->el.cache->pool, cq->hdrsfile, APR_READ | APR_BINARY, 0)))
  +    if(!cq->hdrsfile || (apr_open(&f, cq->hdrsfile, APR_READ | APR_BINARY, 0, cq->el.cache->pool) != APR_SUCCESS))
           return 0;
       if(!file_cache_read_mydata(f, cq))
       {
  -        ap_bclose(f);
  +        apr_close(f);
           return 0;
       }
       
  @@ -297,12 +309,12 @@
                   break;
           }
       }
  -    ap_bclose(f);
  +    apr_close(f);
       cq->state |= FC_READ_HEADERS;
       return 1;
   }
   
  -static int file_cache_write_mydata(BUFF *fp, cache_req *cq)
  +static int file_cache_write_mydata(apr_file_t *fp, cache_req *cq)
   {
       char buff[sizeof(apr_time_t) * 2];
       cache_server_conf *conf = (cache_server_conf *)
  @@ -371,13 +383,17 @@
       }
   
       ap_cache_msec2hex(cq->date, buff);
  -    ap_bvputs(fp, buff, " ", NULL);
  +    apr_puts(buff, fp);
  +    apr_puts(" ", fp);
       ap_cache_msec2hex(cq->expire, buff);
  -    ap_bvputs(fp, buff, " ", NULL);
  +    apr_puts(buff, fp);
  +    apr_puts(" ", fp);
       ap_cache_msec2hex(cq->version++, buff);
  -    ap_bvputs(fp, buff, "\n", NULL);
  +    apr_puts(buff, fp);
  +    apr_puts("\n", fp);
   
  -    if (ap_bvputs(fp, "X-NAME: ", cq->el.name, "\n", NULL) == -1) {
  +    if (apr_puts(apr_pstrcat(cq->el.cache->pool, "X-NAME: ", 
  +                         cq->el.name, "\n", NULL), fp) != APR_SUCCESS) {
           ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
                        "cache: error writing (my_data) in cache");
           return 0;
  @@ -386,7 +402,7 @@
   }
   int file_cache_write_hdrs(cache_req *cq)
   {
  -    BUFF *fp;
  +    apr_file_t *fp = NULL;
       cache_server_conf *conf = (cache_server_conf *)
           ap_get_module_config(cq->el.cache->server->module_config, &cache_module);
   
  @@ -395,8 +411,9 @@
           if(!cq->hdrsfile) cq->hdrsfile = header_file(cq->el.cache, cq->el.name);
           if(unlink(cq->hdrsfile)) /* if we can remove it, we clearly don't have to build the dirs */
               mkdir_structure(cq->hdrsfile, conf->root);
  -        if(!(fp = ap_bopenf(cq->el.cache->pool, cq->hdrsfile, APR_WRITE | APR_CREATE | APR_BINARY | APR_EXCL,
  -                            APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD))) {
  +        if(apr_open(&fp, cq->hdrsfile, APR_WRITE | APR_CREATE | APR_BINARY | APR_EXCL,
  +                      APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, 
  +                      cq->el.cache->pool) != APR_SUCCESS) {
               ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
                            "cache: error creating cache header file %s",
                            cq->hdrsfile);
  @@ -410,11 +427,12 @@
               apr_table_entry_t *elts = (apr_table_entry_t *) apr_table_elts(cq->hdrs)->elts;
               for (i = 0; i < apr_table_elts(cq->hdrs)->nelts; ++i) {
                   if (elts[i].key != NULL) {
  -                    ap_bvputs(fp, elts[i].key, ": ", elts[i].val, CRLF, NULL);
  +                    apr_puts(apr_pstrcat(cq->el.cache->pool, elts[i].key, 
  +                                          ": ", elts[i].val, CRLF, NULL), fp);
                   }
               }
           }
  -        ap_bclose(fp); /* flush and close */
  +        apr_close(fp); /* flush and close */
       }
       return 1;
   }
  
  
  
  1.4       +5 -3      apache-2.0/src/modules/file_cache/file_cache.c
  
  Index: file_cache.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/file_cache/file_cache.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- file_cache.c	2000/08/02 05:27:02	1.3
  +++ file_cache.c	2000/09/10 20:45:17	1.4
  @@ -57,6 +57,7 @@
    */
   
   #include "mod_cache.h"
  +#include "apr_strings.h"
   #include "http_conf_globals.h"
   #include "http_log.h"
   #include "http_main.h"
  @@ -101,11 +102,12 @@
       }
       case AP_CACHE_SEEK:
       {
  -        BUFF *fp;
  +        apr_file_t *fp = NULL;
           apr_status_t ret = APR_ENOENT;
           char *data = data_file(h, name);
           *el_in = NULL;
  -        if((fp = ap_bopenf(h->pool, data, APR_WRITE | APR_READ | APR_BINARY, 0)))
  +        if((apr_open(&fp, data, APR_WRITE | APR_READ | APR_BINARY, 0, h->pool)
  +            == APR_SUCCESS))
           {
               cache_req *cq = create_cache_el(h, name);
               cq->fp = fp;
  @@ -190,7 +192,7 @@
   #endif
       }
       if(cq->fp)
  -        ap_bclose(cq->fp); /* if you finalize, you are done writing, so close it */
  +        apr_close(cq->fp); /* if you finalize, you are done writing, so close it */
   
       memset(el, '\0', sizeof(ap_cache_el)); /* clear it out, for the sake of clarity */
       return APR_SUCCESS;
  
  
  
  1.3       +2 -2      apache-2.0/src/modules/file_cache/mod_cache.c
  
  Index: mod_cache.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/file_cache/mod_cache.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- mod_cache.c	2000/08/02 05:27:02	1.2
  +++ mod_cache.c	2000/09/10 20:45:17	1.3
  @@ -98,7 +98,7 @@
       }
       return APR_SUCCESS;
   }
  -apr_status_t file_cache_el_data(ap_cache_el *el, BUFF **b)
  +apr_status_t file_cache_el_data(ap_cache_el *el, apr_file_t **b)
   {
       cache_req *cq = (cache_req *)el;
       *b = NULL;
  @@ -113,7 +113,7 @@
       if(f == AP_CACHE_DATA && cq->fp)
       {
           cq->state &= ~FC_READ_MY_DATA; /* re-read my data later */
  -        ap_bclose(cq->fp);
  +        apr_close(cq->fp);
           cq->fp = NULL;
       }
       else if(f == AP_CACHE_HEADER && cq->hdrs)
  
  
  
  1.5       +2 -2      apache-2.0/src/modules/file_cache/mod_cache.h
  
  Index: mod_cache.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/file_cache/mod_cache.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- mod_cache.h	2000/08/06 06:07:39	1.4
  +++ mod_cache.h	2000/09/10 20:45:17	1.5
  @@ -130,7 +130,7 @@
   
       /* stuff the API uses */
       apr_table_t *hdrs;        /* the HTTP headers of the file */
  -    BUFF *fp;                /* the cache file descriptors */
  +    apr_file_t *fp;                /* the cache file descriptors */
   } cache_req;
   
   /* in mod_cache.c */
  @@ -140,7 +140,7 @@
            void *rec, va_list args);
   apr_status_t file_cache_el_hdr(ap_cache_el *el, const char *name,
            const char *val, ap_cache_query flag);
  -apr_status_t file_cache_el_data(ap_cache_el *el, BUFF **b);
  +apr_status_t file_cache_el_data(ap_cache_el *el, apr_file_t **b);
   apr_status_t file_cache_reset(ap_cache_el *el, ap_cache_part f);
   
   /* in file_garbage.c */