You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rb...@apache.org on 2001/06/15 00:56:14 UTC
cvs commit: apr-util/buckets apr_buckets_file.c apr_buckets_mmap.c
rbb 01/06/14 15:56:14
Modified: server core.c protocol.c
buckets apr_buckets_file.c apr_buckets_mmap.c
Log:
Back out the change to allocate files out of the main request pool, and
implement pool-based setaside for FILE and MMAP buckets.
Revision Changes Path
1.21 +1 -3 httpd-2.0/server/core.c
Index: core.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/core.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -b -w -u -r1.20 -r1.21
--- core.c 2001/06/13 20:11:45 1.20
+++ core.c 2001/06/14 22:56:12 1.21
@@ -2930,7 +2930,6 @@
* when the charset is translated).
*/
int bld_content_md5;
- apr_pool_t *main_pool;
/*
* The old way of doing handlers meant that this handler would
@@ -2975,9 +2974,8 @@
if (r->method_number != M_GET && r->method_number != M_POST) {
return HTTP_METHOD_NOT_ALLOWED;
}
- main_pool = (r->main) ? (r->main->pool) : (r->pool);
- if ((status = apr_file_open(&fd, r->filename, APR_READ | APR_BINARY, 0, main_pool)) != APR_SUCCESS) {
+ if ((status = apr_file_open(&fd, r->filename, APR_READ | APR_BINARY, 0, r->pool)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
"file permissions deny server access: %s", r->filename);
return HTTP_FORBIDDEN;
1.27 +1 -1 httpd-2.0/server/protocol.c
Index: protocol.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/protocol.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -b -w -u -r1.26 -r1.27
--- protocol.c 2001/06/13 13:44:39 1.26
+++ protocol.c 2001/06/14 22:56:12 1.27
@@ -881,7 +881,7 @@
}
if ((ctx->curr_len < AP_MIN_BYTES_TO_WRITE) && !send_it) {
- return ap_save_brigade(f, &ctx->saved, &b, r->pool);
+ return ap_save_brigade(f, &ctx->saved, &b, (r->main) ? r->main->pool : r->pool);
}
/* We will compute a content length if:
1.43 +45 -14 apr-util/buckets/apr_buckets_file.c
Index: apr_buckets_file.c
===================================================================
RCS file: /home/cvs/apr-util/buckets/apr_buckets_file.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -b -w -u -r1.42 -r1.43
--- apr_buckets_file.c 2001/06/04 21:20:33 1.42
+++ apr_buckets_file.c 2001/06/14 22:56:13 1.43
@@ -83,7 +83,6 @@
#endif /* APR_HAS_MMAP */
-
static void file_destroy(void *data)
{
if (apr_bucket_shared_destroy(data)) {
@@ -93,27 +92,18 @@
}
}
-static apr_status_t file_read(apr_bucket *e, const char **str,
- apr_size_t *len, apr_read_type_e block)
+static int file_make_mmap(apr_bucket *e, apr_off_t filelength,
+ apr_off_t fileoffset, apr_pool_t *p)
{
apr_bucket_file *a = e->data;
apr_file_t *f = a->fd;
- apr_bucket *b = NULL;
- char *buf;
- apr_status_t rv;
- apr_off_t filelength = e->length; /* bytes remaining in file past offset */
- apr_off_t fileoffset = e->start;
-#if APR_HAS_MMAP
- apr_mmap_t *mm = NULL;
-#endif
+ apr_mmap_t *mm;
-#if APR_HAS_MMAP
if ((filelength >= MMAP_THRESHOLD)
&& (filelength < MMAP_LIMIT)) {
/* we need to protect ourselves in case we die while we've got the
* file mmapped */
apr_status_t status;
- apr_pool_t *p = apr_file_pool_get(f);
if ((status = apr_mmap_create(&mm, f, fileoffset, filelength,
APR_MMAP_READ, p)) != APR_SUCCESS) {
mm = NULL;
@@ -125,6 +115,24 @@
if (mm) {
apr_bucket_mmap_make(e, mm, 0, filelength); /*XXX: check for failure? */
file_destroy(a);
+ return 1;
+ }
+ return 0;
+}
+
+static apr_status_t file_read(apr_bucket *e, const char **str,
+ apr_size_t *len, apr_read_type_e block)
+{
+ apr_bucket_file *a = e->data;
+ apr_file_t *f = a->fd;
+ apr_bucket *b = NULL;
+ char *buf;
+ apr_status_t rv;
+ apr_off_t filelength = e->length; /* bytes remaining in file past offset */
+ apr_off_t fileoffset = e->start;
+
+#if APR_HAS_MMAP
+ if (file_make_mmap(e, filelength, fileoffset, apr_file_pool_get(f))) {
return apr_bucket_read(e, str, len, block);
}
#endif
@@ -200,11 +208,34 @@
return apr_bucket_file_make(b, fd, offset, len);
}
+static apr_status_t file_setaside(apr_bucket *data, apr_pool_t *pool)
+{
+ apr_bucket_file *a = data->data;
+ apr_file_t *fd;
+ apr_file_t *f = a->fd;
+ apr_pool_t *p = apr_file_pool_get(f);
+ apr_off_t filelength = data->length; /* bytes remaining in file past offset */
+ apr_off_t fileoffset = data->start;
+
+ if (apr_pool_is_ancestor(p, pool)) {
+ return APR_SUCCESS;
+ }
+
+#if APR_HAS_MMAP
+ if (file_make_mmap(data, filelength, fileoffset, p)) {
+ return APR_SUCCESS;
+ }
+#endif
+ apr_file_dup(&fd, f, p);
+ a->fd = fd;
+ return APR_SUCCESS;
+}
+
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_file = {
"FILE", 5,
file_destroy,
file_read,
- apr_bucket_setaside_notimpl,
+ file_setaside,
apr_bucket_shared_split,
apr_bucket_shared_copy
};
1.36 +25 -1 apr-util/buckets/apr_buckets_mmap.c
Index: apr_buckets_mmap.c
===================================================================
RCS file: /home/cvs/apr-util/buckets/apr_buckets_mmap.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -b -w -u -r1.35 -r1.36
--- apr_buckets_mmap.c 2001/04/30 04:11:20 1.35
+++ apr_buckets_mmap.c 2001/06/14 22:56:13 1.36
@@ -115,11 +115,35 @@
return apr_bucket_mmap_make(b, mm, start, length);
}
+static apr_status_t mmap_setaside(apr_bucket *data, apr_pool_t *p)
+{
+ apr_bucket_mmap *m;
+ apr_mmap_t *mm;
+ char *base;
+ void *addr;
+ apr_status_t ok;
+
+ m = data->data;
+ mm = m->mmap;
+ if (apr_pool_is_ancestor(mm->cntxt, p)) {
+ return APR_SUCCESS;
+ }
+
+ base = apr_pcalloc(p, data->length);
+ ok = apr_mmap_offset(&addr, m->mmap, data->start);
+ if (ok != APR_SUCCESS) {
+ return ok;
+ }
+ memcpy(base, addr, data->length);
+ data = apr_bucket_pool_make(data, base, data->length, p);
+ return APR_SUCCESS;
+}
+
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_mmap = {
"MMAP", 5,
mmap_destroy,
mmap_read,
- apr_bucket_setaside_notimpl,
+ mmap_setaside,
apr_bucket_shared_split,
apr_bucket_shared_copy
};