#include "ap_hooks.h"
#include "apr_portable.h"
+#include "apr_mmap.h"
#ifdef __cplusplus
extern "C" {
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
#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
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
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
&& (!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
#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));
}
#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;
}
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;