]> granicus.if.org Git - apache/commitdiff
*) Account for the new pool parameter to apr_bucket_file_create()
authorCliff Woolley <jwoolley@apache.org>
Wed, 27 Jun 2001 20:18:09 +0000 (20:18 +0000)
committerCliff Woolley <jwoolley@apache.org>
Wed, 27 Jun 2001 20:18:09 +0000 (20:18 +0000)
   and apr_bucket_file_make().

*) Simplify mod_file_cache's sendfile_handler by taking advantage
   the new ability of file buckets to handle files opened in XTHREAD
   mode.  [Also inlined some of the brigade construction stuff in
   mod_file_cache's handlers to save a palloc() or two.]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@89438 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/arch/win32/mod_isapi.c
modules/cache/mod_file_cache.c
modules/experimental/mod_disk_cache.c
server/core.c
server/protocol.c

diff --git a/CHANGES b/CHANGES
index 8b3ae483b9ffad724788bb9653ca1c4f0073ac36..53d90fa82764437a64d435dc0e2c73531588755a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,10 +1,13 @@
 Changes with Apache 2.0.19-dev
 
+  *) mod_file_cache is now more robust to filtering and serves requests
+     slightly more efficiently.  [Cliff Woolley]
+
   *) Fix problem handling FLUSH bucket in the chunked encoding filter.
      Module was calling ap_rwrite() followed by ap_rflush() but the 
      served content was not being displayed in the browser. Inspection
      of the output stream revealed that the first data chunk was
-     missing the trailing CRLF required by the RFC.
+     missing the trailing CRLF required by the RFC.  [Bill Stoddard]
 
   *) apxs no longer generates ap_send_http_header() in the example handler
 
index 2912187f6981b2cd6d26c515bc08cf8659fbf78d..e8c49e987a03cd00c4c56abc0791d60dab26340a 100644 (file)
@@ -944,7 +944,7 @@ BOOL WINAPI ServerSupportFunction(HCONN hConn, DWORD dwHSERequest,
         }
 
         b = apr_bucket_file_create(fd, (apr_off_t)tf->Offset, 
-                                  (apr_size_t)tf->BytesToWrite);
+                                  (apr_size_t)tf->BytesToWrite, r->pool);
         APR_BRIGADE_INSERT_TAIL(bb, b);
         
         if (tf->pTail && (apr_size_t)tf->TailLength) {
index df4966595dfd1b9547a375bdcd80565926c8940b..1839ea2053bfc49b364376dd1e821f6f63530f23 100644 (file)
 #include "apr_mmap.h"
 #include "apr_strings.h"
 #include "apr_hash.h"
+#include "apr_buckets.h"
 
 #define APR_WANT_STRFUNC
 #include "apr_want.h"
@@ -206,7 +207,8 @@ static void cache_the_file(cmd_parms *cmd, const char *filename, int mmap)
        return;
     }
 
-    rc = apr_file_open(&fd, fspec, APR_READ | APR_XTHREAD, APR_OS_DEFAULT, cmd->pool);
+    rc = apr_file_open(&fd, fspec, APR_READ | APR_BINARY | APR_XTHREAD,
+                       APR_OS_DEFAULT, cmd->pool);
     if (rc != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_WARNING, rc, cmd->server,
                      "mod_file_cache: unable to open(%s, O_RDONLY), skipping", fspec);
@@ -318,7 +320,16 @@ static int file_cache_xlat(request_rec *r)
 static int mmap_handler(request_rec *r, a_file *file)
 {
 #if APR_HAS_MMAP
-    ap_send_mmap (file->mm, r, 0, file->finfo.size);
+    apr_bucket *b;
+    apr_bucket_brigade *bb = apr_brigade_create(r->pool);
+
+    b = apr_bucket_mmap_create(file->mm, 0, file->finfo.size);
+    APR_BRIGADE_INSERT_TAIL(bb, b);
+    b = apr_bucket_eos_create();
+    APR_BRIGADE_INSERT_TAIL(bb, b);
+
+    if (ap_pass_brigade(r->output_filters, bb) != APR_SUCCESS)
+        return HTTP_INTERNAL_SERVER_ERROR;
 #endif
     return OK;
 }
@@ -326,44 +337,16 @@ static int mmap_handler(request_rec *r, a_file *file)
 static int sendfile_handler(request_rec *r, a_file *file)
 {
 #if APR_HAS_SENDFILE
-    apr_size_t nbytes;
-    apr_status_t rv = APR_EINIT;
-    apr_file_t *rfile;
-    apr_os_file_t fd;
-
-    /* A cached file handle (more importantly, its file pointer) is 
-     * shared by all threads in the process. The file pointer will 
-     * be corrupted if multiple threads attempt to read from the 
-     * cached file handle. The sendfile API does not rely on the position 
-     * of the file pointer instead taking explicit file offset and 
-     * length arguments. 
-     *
-     * We should call ap_send_fd with a cached file handle IFF 
-     * we are CERTAIN the file will be served with apr_sendfile(). 
-     * The presense of an AP_FTYPE_FILTER in the filter chain nearly
-     * guarantees that apr_sendfile will NOT be used to send the file.
-     * Furthermore, AP_FTYPE_CONTENT filters will be at the beginning
-     * of the chain, so it should suffice to just check the first 
-     * filter in the chain. If the first filter is not a content filter, 
-     * assume apr_sendfile() will be used to send the content.
-     */
-    if (r->output_filters && r->output_filters->frec) {
-        if (r->output_filters->frec->ftype == AP_FTYPE_CONTENT)
-            return DECLINED;
-    }
+    apr_bucket *b;
+    apr_bucket_brigade *bb = apr_brigade_create(r->pool);
 
-    /* Create an apr_file_t anchored out of the request pool to use 
-     * on the call to ap_send_fd(). The cached apr_file_t is allocated 
-     * out of pconf (a life of the server pool) and sending it down
-     * the filter chain could cause memory leaks.
-     */
-    apr_os_file_get(&fd, file->file);
-    apr_os_file_put(&rfile, &fd, r->pool);
-    rv = ap_send_fd(rfile, r, 0, file->finfo.size, &nbytes);
-    if (rv != APR_SUCCESS) {
-        /* ap_send_fd will log the error */
+    b = apr_bucket_file_create(file->file, 0, file->finfo.size, r->pool);
+    APR_BRIGADE_INSERT_TAIL(bb, b);
+    b = apr_bucket_eos_create();
+    APR_BRIGADE_INSERT_TAIL(bb, b);
+
+    if (ap_pass_brigade(r->output_filters, bb) != APR_SUCCESS)
         return HTTP_INTERNAL_SERVER_ERROR;
-    }
 #endif
     return OK;
 }
index cbd28bf04a7ffdca7e96c79f703444abb29d2d00..8b5b60cf22bae273e350bff3b2cf4855d2ec4f82 100644 (file)
@@ -98,7 +98,7 @@ static int disk_serve(request_rec *r)
         }
     }
 
-    e = apr_bucket_file_create(fd, offset, r->finfo.size);
+    e = apr_bucket_file_create(fd, offset, r->finfo.size, r->pool);
 
     APR_BRIGADE_INSERT_HEAD(bb, e);
     e = apr_bucket_eos_create();
index af35e4339f4c0cb01da6edd085dba4f1801afa4e..1aedb3c8e88e5f33a287a81eef9fe512cb60b2f2 100644 (file)
@@ -2996,7 +2996,7 @@ static int default_handler(request_rec *r)
     }
 
     bb = apr_brigade_create(r->pool);
-    e = apr_bucket_file_create(fd, 0, r->finfo.size);
+    e = apr_bucket_file_create(fd, 0, r->finfo.size, r->pool);
 
     APR_BRIGADE_INSERT_HEAD(bb, e);
     e = apr_bucket_eos_create();
index 09d40c02424dd1a588fa8498bc26c6ce1e3d175c..31c60d97b5a77f0cd671c8e284f5feb5ed5e2b43 100644 (file)
@@ -938,7 +938,7 @@ AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t of
     apr_status_t rv;
 
     bb = apr_brigade_create(r->pool);
-    b = apr_bucket_file_create(fd, offset, len);
+    b = apr_bucket_file_create(fd, offset, len, r->pool);
     APR_BRIGADE_INSERT_TAIL(bb, b);
 
     rv = ap_pass_brigade(r->output_filters, bb);