/* use the pre-read hunks if they exist */
- p->read = 1;
chain = p->preread_hunks;
p->preread_hunks = NULL;
n = p->preread_size;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
"pipe preread: %d", n);
+ if (n) {
+ p->read = 1;
+ }
+
} else {
/*
p->free_raw_hunks = cl;
}
+#if (NGX_DEBUG0)
+
+ if (p->in || p->busy || p->free_raw_hunks) {
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe buf");
+ }
+
+ for (cl = p->in; cl; cl = cl->next) {
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
+ "pipe buf in " PTR_FMT ", pos " PTR_FMT ", size: %d",
+ cl->hunk->start, cl->hunk->pos,
+ cl->hunk->last - cl->hunk->pos);
+ }
+
+ for (cl = p->busy; cl; cl = cl->next) {
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
+ "pipe buf busy " PTR_FMT ", pos " PTR_FMT ", size: %d",
+ cl->hunk->start, cl->hunk->pos,
+ cl->hunk->last - cl->hunk->pos);
+ }
+
+ for (cl = p->free_raw_hunks; cl; cl = cl->next) {
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
+ "pipe buf free " PTR_FMT ", last " PTR_FMT ", size: %d",
+ cl->hunk->start, cl->hunk->last,
+ cl->hunk->end - cl->hunk->last);
+ }
+
+#endif
+
if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) {
/* STUB */ p->free_raw_hunks->hunk->num = p->num++;
int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
{
- size_t bsize, to_write;
+ size_t bsize;
+ ngx_uint_t flush;
ngx_hunk_t *h;
ngx_chain_t *out, **ll, *cl, *tl;
break;
}
- /*
- * bsize is the size of the busy hunks,
- * to_write is the size of data in these hunks that
- * would be written to a socket
- */
+ /* bsize is the size of the busy hunks */
bsize = 0;
- to_write = 0;
-#if 0
- if (!(p->upstream_eof || p->upstream_error || p->upstream_done)) {
-#endif
- for (cl = p->busy; cl; cl = cl->next) {
- bsize += cl->hunk->end - cl->hunk->start;
- to_write += ngx_hunk_size(cl->hunk);
- }
-#if 0
+ for (cl = p->busy; cl; cl = cl->next) {
+ bsize += cl->hunk->end - cl->hunk->start;
}
-#endif
+
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
+ "pipe write busy: " SIZE_T_FMT, bsize);
out = NULL;
ll = NULL;
+ flush = 0;
for ( ;; ) {
if (p->out) {
cl = p->out;
-#if 0
- if (!(p->upstream_eof || p->upstream_error || p->upstream_done)
- && (bsize + ngx_hunk_size(cl->hunk) > p->busy_size))
- {
- break;
- }
-#else
if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) {
+ flush = 1;
break;
}
-#endif
p->out = p->out->next;
ngx_event_pipe_free_shadow_raw_hunk(&p->free_raw_hunks,
} else if (!p->cachable && p->in) {
cl = p->in;
-#if 0
- if (!(p->upstream_eof || p->upstream_error || p->upstream_done)
- && (bsize + ngx_hunk_size(cl->hunk) > p->busy_size))
- {
- break;
- }
-#else
if (bsize + ngx_hunk_size(cl->hunk) > p->busy_size) {
+ flush = 1;
break;
}
-#endif
p->in = p->in->next;
ngx_chain_add_link(out, ll, cl);
}
- if (out == NULL) {
-
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe busy hunk data to write: %d", to_write);
-
- if (!(p->upstream_blocked && to_write)) {
- break;
- }
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
+ "pipe write: out:" PTR_FMT ", f:%d", out, flush);
+ if (out == NULL && !flush) {
+ break;
}
- /*
- * if the upstream is blocked and there are the busy hunks
- * to write then write these hunks
- */
-
if (p->output_filter(p->output_ctx, out) == NGX_ERROR) {
p->downstream_error = 1;
return ngx_event_pipe_drain_chains(p);
do {
hsize = cl->hunk->last - cl->hunk->pos;
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe hunk size: %d", hsize);
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
+ "pipe buf " PTR_FMT ", pos " PTR_FMT ", size: %d",
+ cl->hunk->start, cl->hunk->pos, hsize);
if ((size + hsize > p->temp_file_write_size)
|| (p->temp_file->offset + size + hsize > p->max_temp_file_size))
ngx_http_proxy_loc_conf_t *prev = parent;
ngx_http_proxy_loc_conf_t *conf = child;
+ size_t size;
+
ngx_conf_merge_msec_value(conf->connect_timeout,
prev->connect_timeout, 60000);
ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 30000);
ngx_conf_merge_value(conf->add_x_forwarded_for,
prev->add_x_forwarded_for, 0);
+ ngx_conf_merge_msec_value(conf->read_timeout, prev->read_timeout, 30000);
+
ngx_conf_merge_size_value(conf->header_buffer_size,
prev->header_buffer_size, 4096);
- ngx_conf_merge_msec_value(conf->read_timeout, prev->read_timeout, 30000);
ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 8, 4096);
+
+ size = conf->header_buffer_size;
+ if (size < conf->bufs.size) {
+ size = conf->bufs.size;
+ }
+
+
ngx_conf_merge_size_value(conf->busy_buffers_size,
- prev->busy_buffers_size, 8192);
+ prev->busy_buffers_size, NGX_CONF_UNSET_SIZE);
-#if 0
- if (conf->max_temp_file_size > conf->bufs.size) {
- return "\"proxy_max_temp_file\" must be greater "
- "than one of the \"proxy_buffers\"";
+ if (conf->busy_buffers_size == NGX_CONF_UNSET_SIZE) {
+ conf->busy_buffers_size = 2 * size;
+
+ } else if (conf->busy_buffers_size < size) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"proxy_busy_buffers_size\" must be equal or bigger than "
+ "maximum of the value of \"proxy_header_buffer_size\" and "
+ "one of the \"proxy_buffers\"");
+
+ return NGX_CONF_ERROR;
}
-#endif
+
ngx_conf_merge_size_value(conf->temp_file_write_size,
- prev->temp_file_write_size, 16384);
+ prev->temp_file_write_size, NGX_CONF_UNSET_SIZE);
+
+ if (conf->temp_file_write_size == NGX_CONF_UNSET_SIZE) {
+ conf->temp_file_write_size = 2 * size;
+
+ } else if (conf->temp_file_write_size < size) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"proxy_temp_file_write_size\" must be equal or bigger than "
+ "maximum of the value of \"proxy_header_buffer_size\" and "
+ "one of the \"proxy_buffers\"");
+
+ return NGX_CONF_ERROR;
+ }
+
+
+ ngx_conf_merge_size_value(conf->max_temp_file_size,
+ prev->max_temp_file_size, NGX_CONF_UNSET_SIZE);
+
+ if (conf->max_temp_file_size == NGX_CONF_UNSET_SIZE) {
+ conf->max_temp_file_size = 2 * size;
+
+ } else if (conf->max_temp_file_size < size) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"proxy_max_temp_file_size\" must be equal or bigger than "
+ "maximum of the value of \"proxy_header_buffer_size\" and "
+ "one of the \"proxy_buffers\"");
+
+ return NGX_CONF_ERROR;
+ }
+
ngx_conf_merge_bitmask_value(conf->next_upstream, prev->next_upstream,
(NGX_CONF_BITMASK_SET