Commit c700dab8 authored by Cliff Woolley's avatar Cliff Woolley
Browse files

*) Account for the new pool parameter to apr_bucket_file_create()

   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
parent 3bd8cfc4
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
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

+1 −1
Original line number Diff line number Diff line
@@ -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) {
+21 −38
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@
#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;
}
+1 −1
Original line number Diff line number Diff line
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -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();
Loading