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/main http_core.c
Date Thu, 09 Nov 2000 22:05:41 GMT
rbb         00/11/09 14:05:40

  Modified:    src      CHANGES
               src/ap   ap_buckets_file.c
               src/main http_core.c
  Log:
  Remove MMAP handling from the default handler.  MMAPs are created by the
  file_bucket read function now.  If we try to read from a file bucket and
  it makes sense to convert that bucket to an MMAP, that just happens.
  
  Revision  Changes    Path
  1.315     +5 -0      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.314
  retrieving revision 1.315
  diff -u -r1.314 -r1.315
  --- CHANGES	2000/11/09 00:36:43	1.314
  +++ CHANGES	2000/11/09 22:05:40	1.315
  @@ -1,4 +1,9 @@
   Changes with Apache 2.0a8
  +  *) When reading from file buckets we convert to an MMAP if it makes
  +     sense.  This also simplifies the default handler because the
  +     default handler no longer needs to try to create MMAPs.
  +     [Ryan Bloom]
  +
     *) BUFF has been removed from the main server.  The BUFF code will remain
        in the code until it has been purged from the proxy module as well.
        [Ryan Bloom]
  
  
  
  1.9       +81 -29    apache-2.0/src/ap/ap_buckets_file.c
  
  Index: ap_buckets_file.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/ap/ap_buckets_file.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ap_buckets_file.c	2000/11/07 20:21:06	1.8
  +++ ap_buckets_file.c	2000/11/09 22:05:40	1.9
  @@ -57,6 +57,32 @@
   #include "ap_buckets.h"
   #include <stdlib.h>
   
  +/* Allow Apache to use ap_mmap */
  +#ifdef AP_USE_MMAP_FILES
  +#include "apr_mmap.h"
  +
  +/* mmap support for static files based on ideas from John Heidemann's
  + * patch against 1.0.5.  See
  + * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
  + */
  +
  +/* Files have to be at least this big before they're mmap()d.  This is to deal
  + * with systems where the expense of doing an mmap() and an munmap() outweighs
  + * the benefit for small files.  It shouldn't be set lower than 1.
  + */
  +#ifndef MMAP_THRESHOLD
  +#  ifdef SUNOS4
  +#  define MMAP_THRESHOLD                (8*1024)
  +#  else
  +#  define MMAP_THRESHOLD                1
  +#  endif /* SUNOS4 */
  +#endif /* MMAP_THRESHOLD */
  +#ifndef MMAP_LIMIT
  +#define MMAP_LIMIT              (4*1024*1024)
  +#endif
  +#endif /* AP_USE_MMAP_FILES */
  +
  +
   /* XXX: We should obey the block flag */
   static apr_status_t file_read(ap_bucket *e, const char **str,
   			      apr_size_t *len, ap_read_type block)
  @@ -66,44 +92,70 @@
       ap_bucket *b = NULL;
       char *buf;
       apr_status_t rv;
  -
  -    buf = malloc(IOBUFSIZE);
  -    *str = buf;
  +#ifdef AP_USE_MMAP_FILES
  +    apr_mmap_t *mm = NULL;
  +#endif
   
  -    if (e->length > IOBUFSIZE) {
  -        *len = IOBUFSIZE;
  +#ifdef AP_USE_MMAP_FILES
  +    if ((e->length >= MMAP_THRESHOLD)
  +        && (e->length < MMAP_LIMIT)) {
  +        /* we need to protect ourselves in case we die while we've got the
  +         * file mmapped */
  +        apr_status_t status;
  +        if ((status = apr_mmap_create(&mm, f, a->offset, e->length, NULL)) !=
APR_SUCCESS) {
  +            mm = NULL;
  +        }
       }
       else {
  -        *len = e->length;
  +        mm = NULL;
  +    }
  +    if (mm) {
  +        ap_bucket_make_mmap(e, mm, 0, e->length); /*XXX: check for failure? */
  +        return ap_bucket_read(e, str, len, block);
       }
  +    else {
  +#endif
  +
  +        buf = malloc(IOBUFSIZE);
  +        *str = buf;
   
  -    /* Handle offset ... */
  -    if (a->offset) {
  -        rv = apr_seek(f, APR_SET, &a->offset);
  -        if (rv != APR_SUCCESS) {
  -            free(buf);
  +        if (e->length > IOBUFSIZE) {
  +            *len = IOBUFSIZE;
  +        }
  +        else {
  +            *len = e->length;
  +        }
  +
  +        /* Handle offset ... */
  +        if (a->offset) {
  +            rv = apr_seek(f, APR_SET, &a->offset);
  +            if (rv != APR_SUCCESS) {
  +                free(buf);
  +                return rv;
  +            }
  +            /* Only need to do seek the first time through */
  +            a->offset = 0;
  +        }
  +        rv = apr_read(f, buf, len);
  +        if (rv != APR_SUCCESS && rv != APR_EOF) {
  +	    free(buf);
               return rv;
           }
  -        /* Only need to do seek the first time through */
  -        a->offset = 0;
  -    }
  -    rv = apr_read(f, buf, len);
  -    if (rv != APR_SUCCESS && rv != APR_EOF) {
  -	free(buf);
  -        return rv;
  -    }
   
  -    /*
  -     * Change the current bucket to refer to what we read,
  -     * even if we read nothing because we hit EOF.
  -     */
  -    ap_bucket_make_heap(e, buf, *len, 0, NULL);  /* XXX: check for failure? */
  -
  -    /* If we have more to read from the file, then create another bucket */
  -    if (*len > 0) {
  -        b = ap_bucket_create_file(f, 0, e->length);
  -        AP_BUCKET_INSERT_AFTER(e, b);
  +        /*
  +         * Change the current bucket to refer to what we read,
  +         * even if we read nothing because we hit EOF.
  +         */
  +        ap_bucket_make_heap(e, buf, *len, 0, NULL); /*XXX: check for failure? */
  +
  +        /* If we have more to read from the file, then create another bucket */
  +        if (*len > 0) {
  +            b = ap_bucket_create_file(f, 0, e->length);
  +            AP_BUCKET_INSERT_AFTER(e, b);
  +        }
  +#ifdef AP_USE_MMAP_FILES
       }
  +#endif
       return APR_SUCCESS;
   }
   
  
  
  
  1.212     +8 -79     apache-2.0/src/main/http_core.c
  
  Index: http_core.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/http_core.c,v
  retrieving revision 1.211
  retrieving revision 1.212
  diff -u -r1.211 -r1.212
  --- http_core.c	2000/11/09 13:36:01	1.211
  +++ http_core.c	2000/11/09 22:05:40	1.212
  @@ -93,31 +93,6 @@
    */
   #define MIN_SIZE_TO_WRITE  9000
   
  -/* Allow Apache to use ap_mmap */
  -#ifdef AP_USE_MMAP_FILES
  -#include "apr_mmap.h"
  -
  -/* mmap support for static files based on ideas from John Heidemann's
  - * patch against 1.0.5.  See
  - * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
  - */
  -
  -/* Files have to be at least this big before they're mmap()d.  This is to deal
  - * with systems where the expense of doing an mmap() and an munmap() outweighs
  - * the benefit for small files.  It shouldn't be set lower than 1.
  - */
  -#ifndef MMAP_THRESHOLD
  -#  ifdef SUNOS4
  -#  define MMAP_THRESHOLD		(8*1024)
  -#  else
  -#  define MMAP_THRESHOLD		1
  -#  endif /* SUNOS4 */
  -#endif /* MMAP_THRESHOLD */
  -#ifndef MMAP_LIMIT
  -#define MMAP_LIMIT              (4*1024*1024)
  -#endif
  -#endif /* AP_USE_MMAP_FILES */
  -
   /* LimitXMLRequestBody handling */
   #define AP_LIMIT_UNSET                  ((long) -1)
   #define AP_DEFAULT_LIMIT_XML_BODY       ((size_t)1000000)
  @@ -2915,9 +2890,6 @@
       int errstatus;
       apr_file_t *fd = NULL;
       apr_status_t status;
  -#ifdef AP_USE_MMAP_FILES
  -    apr_mmap_t *mm = NULL;
  -#endif
       /* XXX if/when somebody writes a content-md5 filter we either need to
        *     remove this support or coordinate when to use the filter vs.
        *     when to use this code
  @@ -2957,7 +2929,7 @@
           return HTTP_METHOD_NOT_ALLOWED;
       }
   	
  -    if ((status = apr_open(&fd, r->filename, APR_READ | APR_BINARY, 0, r->pool))
!= APR_SUCCESS) {
  +    if ((status = apr_open(&fd, r->filename, APR_READ | APR_BINARY, 0, r->connection->pool))
!= APR_SUCCESS) {
           ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
   		     "file permissions deny server access: %s", r->filename);
           return HTTP_FORBIDDEN;
  @@ -2972,61 +2944,18 @@
           return errstatus;
       }
   
  -#ifdef AP_USE_MMAP_FILES
  -    if ((r->finfo.size >= MMAP_THRESHOLD)
  -	&& (r->finfo.size < MMAP_LIMIT)
  -	&& (!r->header_only || bld_content_md5)) {
  -	/* we need to protect ourselves in case we die while we've got the
  - 	 * file mmapped */
  -        apr_status_t status;
  -        if ((status = apr_mmap_create(&mm, fd, 0, r->finfo.size, r->connection->pool))
!= APR_SUCCESS) {
  -	    ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
  -			 "default_handler: mmap failed: %s", r->filename);
  -	    mm = NULL;
  -	}
  -    }
  -    else {
  -	mm = NULL;
  +    if (bld_content_md5) {
  +        apr_table_setn(r->headers_out, "Content-MD5",
  +                       ap_md5digest(r->pool, fd));
       }
  -
  -    if (mm == NULL) {
  -#endif
  -
  -        if (bld_content_md5) {
  -	    apr_table_setn(r->headers_out, "Content-MD5",
  -                           ap_md5digest(r->pool, fd));
  -	}
   
  -	ap_send_http_header(r);
  +    ap_send_http_header(r);
   	
  -	if (!r->header_only) {
  -            apr_size_t nbytes;
  -
  -            ap_send_fd(fd, r, 0, r->finfo.size, &nbytes);
  -	}
  -
  -#ifdef AP_USE_MMAP_FILES
  -    }
  -    else {
  -	unsigned char *addr;
  -        apr_mmap_offset((void**)&addr, mm ,0);
  +    if (!r->header_only) {
  +        apr_size_t nbytes;
   
  -	if (bld_content_md5) {
  -	    apr_md5_ctx_t context;
  -	    
  -	    apr_MD5Init(&context);
  -	    apr_MD5Update(&context, addr, (unsigned int)r->finfo.size);
  -	    apr_table_setn(r->headers_out, "Content-MD5",
  -			  ap_md5contextTo64(r->pool, &context));
  -	}
  -
  -	ap_send_http_header(r);
  -	
  -	if (!r->header_only) {
  -            ap_send_mmap(mm, r, 0, r->finfo.size);
  -	}
  +        ap_send_fd(fd, r, 0, r->finfo.size, &nbytes);
       }
  -#endif
   
       apr_close(fd);
       return OK;
  
  
  

Mime
View raw message