On Tue, Oct 23, 2018 at 3:52 PM Yann Ylavic <[email protected]> wrote:
>
> Yeah, I have a version which checks only for
> (APR_BUCKET_IS_FLUSH(bucket) || cumulative_tmp_bb_len >=
> ap_get_core_module_config()->flush_max_threshold)
See attached.
Index: server/request.c
===================================================================
--- server/request.c (revision 1843207)
+++ server/request.c (working copy)
@@ -2066,9 +2066,13 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_ou
AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_core_filter(ap_filter_t *f,
apr_bucket_brigade *bb)
{
+ apr_status_t status = APR_SUCCESS;
+ apr_read_type_e block = APR_NONBLOCK_READ;
+ conn_rec *c = f->r->connection;
apr_bucket *flush_upto = NULL;
- apr_status_t status = APR_SUCCESS;
apr_bucket_brigade *tmp_bb;
+ apr_size_t tmp_bb_len = 0;
+ core_server_config *conf;
int seen_eor = 0;
/*
@@ -2080,6 +2084,8 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_co
return ap_pass_brigade(f->next, bb);
}
+ conf = ap_get_core_module_config(f->r->server->module_config);
+
/* Reinstate any buffered content */
ap_filter_reinstate_brigade(f, bb, &flush_upto);
@@ -2092,6 +2098,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_co
/* Don't touch *bb after seen_eor */
while (status == APR_SUCCESS && !seen_eor && !APR_BRIGADE_EMPTY(bb)) {
apr_bucket *bucket = APR_BRIGADE_FIRST(bb);
+ int do_pass = 0;
if (AP_BUCKET_IS_EOR(bucket)) {
/* pass out everything and never come back again,
@@ -2099,7 +2106,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_co
*/
APR_BRIGADE_CONCAT(tmp_bb, bb);
ap_remove_output_filter(f);
- seen_eor = 1;
+ seen_eor = do_pass = 1;
}
else {
/* if the core has set aside data, back off and try later */
@@ -2116,31 +2123,61 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_request_co
* something safe to pass down to the connection filters without
* needing to be set aside.
*/
- if (!APR_BUCKET_IS_METADATA(bucket)
- && bucket->length == (apr_size_t)-1) {
+ if (bucket->length == (apr_size_t)-1) {
const char *data;
apr_size_t size;
- status = apr_bucket_read(bucket, &data, &size, APR_BLOCK_READ);
+
+ status = apr_bucket_read(bucket, &data, &size, block);
if (status != APR_SUCCESS) {
- break;
+ if (!APR_STATUS_IS_EAGAIN(status)
+ || block != APR_NONBLOCK_READ) {
+ break;
+ }
+ /* Flush everything so far and retry in blocking mode */
+ bucket = apr_bucket_flush_create(c->bucket_alloc);
+ block = APR_BLOCK_READ;
}
+ else {
+ block = APR_NONBLOCK_READ;
+ tmp_bb_len += size;
+ }
}
+ else {
+ tmp_bb_len += bucket->length;
+ }
- /* pass each bucket down the chain */
+ /* move the bucket to tmp_bb and check whether it exhausts bb or
+ * brings tmp_bb above the limit; in both cases it's time to pass
+ * everything down the chain.
+ */
APR_BUCKET_REMOVE(bucket);
APR_BRIGADE_INSERT_TAIL(tmp_bb, bucket);
+ if (APR_BRIGADE_EMPTY(bb)
+ || APR_BUCKET_IS_FLUSH(bucket)
+ || tmp_bb_len >= conf->flush_max_threshold) {
+ do_pass = 1;
+ }
}
- status = ap_pass_brigade(f->next, tmp_bb);
- apr_brigade_cleanup(tmp_bb);
+ if (do_pass) {
+ status = ap_pass_brigade(f->next, tmp_bb);
+ apr_brigade_cleanup(tmp_bb);
+ tmp_bb_len = 0;
+ }
}
+ /* Don't touch *bb after seen_eor */
+ if (!seen_eor) {
+ apr_status_t rv;
+ APR_BRIGADE_PREPEND(bb, tmp_bb);
+ rv = ap_filter_setaside_brigade(f, bb);
+ if (status == APR_SUCCESS) {
+ status = rv;
+ }
+ }
+
ap_release_brigade(f->c, tmp_bb);
- /* Don't touch *bb after seen_eor */
- if (status == APR_SUCCESS && !seen_eor) {
- status = ap_filter_setaside_brigade(f, bb);
- }
return status;
}