]> granicus.if.org Git - apache/commitdiff
Next stage of ap_mmap support. Tested on FreeBSD and BeOS.
authorDavid Reid <dreid@apache.org>
Sat, 20 Nov 1999 11:56:13 +0000 (11:56 +0000)
committerDavid Reid <dreid@apache.org>
Sat, 20 Nov 1999 11:56:13 +0000 (11:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84139 13f79535-47bb-0310-9956-ffa450edef68

include/http_protocol.h
modules/http/http_core.c
modules/http/http_protocol.c

index 8a5e75396fa5fe1c331ec470fa9614244d27067a..24dae34ec1d2a830cd8f35092fdb73e03b37e14b 100644 (file)
@@ -60,6 +60,7 @@
 
 #include "ap_hooks.h"
 #include "apr_portable.h"
+#include "apr_mmap.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -140,7 +141,7 @@ API_EXPORT(long) ap_send_fd_length(ap_file_t *fd, request_rec *r, long length);
 API_EXPORT(long) ap_send_fb(BUFF *f, request_rec *r);
 API_EXPORT(long) ap_send_fb_length(BUFF *f, request_rec *r, long length);
 
-API_EXPORT(size_t) ap_send_mmap(void *mm, request_rec *r, size_t offset,
+API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t offset,
                              size_t length);
 
 /* Hmmm... could macrofy these for now, and maybe forever, though the
index ccf6d38c81e473ba84630c153509813c0713611f..3dc26270af5ffbf317e38ede489f9b845173ebf4 100644 (file)
@@ -70,8 +70,9 @@
 #include "fnmatch.h"
 #include "http_connection.h"
 
+/* Allow Apache to use ap_mmap */
 #ifdef USE_MMAP_FILES
-#include <sys/mman.h>
+#include "apr_mmap.h"
 
 /* mmap support for static files based on ideas from John Heidemann's
  * patch against 1.0.5.  See
  * 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
-#endif
-#endif
+  #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 /* USE_MMAP_FILES */
 
 /* Server core module... This module provides support for really basic
  * server operations, including options and commands which control the
@@ -2440,25 +2441,6 @@ static int core_translate(request_rec *r)
 
 static int do_nothing(request_rec *r) { return OK; }
 
-#ifdef USE_MMAP_FILES
-struct mmap_rec {
-    void *mm;
-    size_t length;
-};
-
-static ap_status_t mmap_cleanup(void *mmv)
-{
-    struct mmap_rec *mmd = mmv;
-
-    if (munmap(mmd->mm, mmd->length) == -1) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, errno, NULL,
-                     "Failed to munmap memory of length %ld at 0x%lx",
-                     (long) mmd->length, (long) mmd->mm);
-    }
-    return APR_SUCCESS;
-}
-#endif
-
 /*
  * Default handler for MIME types without other handlers.  Only GET
  * and OPTIONS at this point... anyone who wants to write a generic
@@ -2476,7 +2458,7 @@ static int default_handler(request_rec *r)
     ap_os_file_t fd_os;
     ap_status_t status;
 #ifdef USE_MMAP_FILES
-    caddr_t mm;
+    ap_mmap_t *mm = NULL;
 #endif
 #ifdef CHARSET_EBCDIC
     /* To make serving of "raw ASCII text" files easy (they serve faster
@@ -2544,18 +2526,17 @@ static int default_handler(request_rec *r)
        && (!r->header_only || (d->content_md5 & 1))) {
        /* we need to protect ourselves in case we die while we've got the
         * file mmapped */
-       mm = mmap(NULL, r->finfo.st_size, PROT_READ, MAP_PRIVATE,
-                 fd_os, 0);
-       if (mm == (caddr_t)-1) {
+    if (ap_mmap_create(&mm, fd, 0, r->finfo.st_size, r->pool) != APR_SUCCESS){
            ap_log_rerror(APLOG_MARK, APLOG_CRIT, errno, r,
                         "default_handler: mmap failed: %s", r->filename);
+           mm = NULL;
        }
     }
     else {
-       mm = (caddr_t)-1;
+       mm = NULL;
     }
 
-    if (mm == (caddr_t)-1) {
+    if (mm == NULL) {
 #endif
 
 #ifdef CHARSET_EBCDIC
@@ -2597,18 +2578,14 @@ static int default_handler(request_rec *r)
 #ifdef USE_MMAP_FILES
     }
     else {
-       struct mmap_rec *mmd;
-
-       mmd = ap_palloc(r->pool, sizeof(*mmd));
-       mmd->mm = mm;
-       mmd->length = r->finfo.st_size;
-       ap_register_cleanup(r->pool, (void *)mmd, mmap_cleanup, mmap_cleanup);
+       char *addr;
+    ap_mmap_offset((void**)&addr, mm ,0);
 
        if (d->content_md5 & 1) {
            AP_MD5_CTX context;
            
            ap_MD5Init(&context);
-           ap_MD5Update(&context, (void *)mm, (unsigned int)r->finfo.st_size);
+           ap_MD5Update(&context, addr, (unsigned int)r->finfo.st_size);
            ap_table_setn(r->headers_out, "Content-MD5",
                          ap_md5contextTo64(r->pool, &context));
        }
index 8ced100721665420c2419ae9dc856404410bd36f..6f7bfc79eab98e7959fb304f0bddcde5e0e3b539 100644 (file)
@@ -2170,14 +2170,15 @@ API_EXPORT(long) ap_send_fb_length(BUFF *fb, request_rec *r, long length)
 #endif
 
 /* send data from an in-memory buffer */
-API_EXPORT(size_t) ap_send_mmap(void *mm, request_rec *r, size_t offset,
+API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t offset,
                              size_t length)
 {
     size_t total_bytes_sent = 0;
     int n;
     ap_ssize_t w;
     ap_status_t rv;
-
+    char *addr;
+    
     if (length == 0)
         return 0;
 
@@ -2192,7 +2193,8 @@ API_EXPORT(size_t) ap_send_mmap(void *mm, request_rec *r, size_t offset,
         }
 
         while (n && !r->connection->aborted) {
-            rv = ap_bwrite(r->connection->client, (char *) mm + offset, n, &w);
+            ap_mmap_offset((void**)&addr, mm, offset);
+            rv = ap_bwrite(r->connection->client, addr, n, &w);
             if (w > 0) {
                 total_bytes_sent += w;
                 n -= w;