dreid 99/11/20 03:56:15
Modified: src/include http_protocol.h
src/main http_core.c http_protocol.c
Log:
Next stage of ap_mmap support. Tested on FreeBSD and BeOS.
Revision Changes Path
1.8 +2 -1 apache-2.0/src/include/http_protocol.h
Index: http_protocol.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/http_protocol.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- http_protocol.h 1999/11/05 15:45:03 1.7
+++ http_protocol.h 1999/11/20 11:56:11 1.8
@@ -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
1.25 +17 -40 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.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- http_core.c 1999/11/18 23:07:15 1.24
+++ http_core.c 1999/11/20 11:56:12 1.25
@@ -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
@@ -83,16 +84,16 @@
* 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 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 @@
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 @@
&& (!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 @@
#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));
}
1.38 +5 -3 apache-2.0/src/main/http_protocol.c
Index: http_protocol.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- http_protocol.c 1999/11/16 18:30:40 1.37
+++ http_protocol.c 1999/11/20 11:56:13 1.38
@@ -2170,14 +2170,15 @@
#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 @@
}
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;