httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Reid" <ab...@dial.pipex.com>
Subject APR MMAP support
Date Thu, 04 Nov 1999 12:58:39 GMT
What follows is a CVS diff -u of the changes to add apr mmap support into
Apache.  If I don't hear any objections than I'll commit tomorrow evening
(UK time).  I've removed the put_statinfo stuff and added a new function for
creating an mmap in keeping with Manoj's comments.  It's been tested on
FreeBSD 3.3 and BeOS.

I know we don't normally post cvs diff's but as I had all the files sitting
there I couldn't be bothered doing a normal diff... :-)

david

Index: apache-2.0/src/include/http_protocol.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/http_protocol.h,v
retrieving revision 1.6
diff -u -u -r1.6 http_protocol.h
--- http_protocol.h 1999/10/05 05:14:41 1.6
+++ http_protocol.h 1999/11/04 12:50:09
@@ -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_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: apache-2.0/src/main/http_core.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_core.c,v
retrieving revision 1.21
diff -u -u -r1.21 http_core.c
--- http_core.c 1999/10/21 18:28:14 1.21
+++ http_core.c 1999/11/04 12:50:20
@@ -71,7 +71,7 @@
 #include "http_connection.h"

 #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
@@ -2442,25 +2442,6 @@

 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
@@ -2478,7 +2459,7 @@
     int 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
@@ -2529,7 +2510,7 @@
         return FORBIDDEN;
     }
     else
-       ap_get_os_file(&fd_os, fd);
+        ap_get_os_file(&fd_os, fd);

     ap_update_mtime(r, r->finfo.st_mtime);
     ap_set_last_modified(r);
@@ -2543,22 +2524,21 @@

 #ifdef USE_MMAP_FILES
     if ((r->finfo.st_size >= MMAP_THRESHOLD)
- && (r->finfo.st_size < MMAP_LIMIT)
- && (!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) {
-     ap_log_rerror(APLOG_MARK, APLOG_CRIT, errno, r,
+     && (r->finfo.st_size < MMAP_LIMIT)
+   && (!r->header_only || (d->content_md5 & 1))) {
+   /* we need to protect ourselves in case we die while we've got the
+     * file mmapped */
+        if ((ap_mmap_size_create(&mm, fd, 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
@@ -2600,18 +2580,13 @@
 #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: apache-2.0/src/main/http_protocol.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
retrieving revision 1.35
diff -u -u -r1.35 http_protocol.c
--- http_protocol.c 1999/11/03 12:47:23 1.35
+++ http_protocol.c 1999/11/04 12:50:22
@@ -2172,15 +2172,17 @@
 #define MMAP_SEGMENT_SIZE       32768
 #endif

+#ifdef USE_MMAP_FILES
 /* 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;

@@ -2195,7 +2197,8 @@
         }

         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;
@@ -2220,6 +2223,7 @@
     SET_BYTES_SENT(r);
     return total_bytes_sent;
 }
+#endif /* USE_MMAP_FILES */

 API_EXPORT(int) ap_rputc(int c, request_rec *r)
 {



Mime
View raw message