nginx-0.0.1-2003-04-15-19:06:52 import
diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c
index fe26a33..d2c31d5 100644
--- a/src/core/ngx_hunk.c
+++ b/src/core/ngx_hunk.c
@@ -18,8 +18,10 @@
h->post_end = h->end + after;
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
- h->tag = 0;
h->file = NULL;
+ h->shadow = NULL;
+
+ h->tag = 0;
return h;
}
@@ -38,8 +40,10 @@
h->file_pos = h->file_last = 0;
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
- h->tag = 0;
h->file = NULL;
+ h->shadow = NULL;
+
+ h->tag = 0;
} else {
ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL);
@@ -48,8 +52,10 @@
h->file_pos = h->file_last = 0;
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
- h->tag = 0;
h->file = NULL;
+ h->shadow = NULL;
+
+ h->tag = 0;
}
return h;
@@ -71,8 +77,10 @@
h->file_pos = h->file_last = 0;
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
- h->tag = 0;
h->file = NULL;
+ h->shadow = NULL;
+
+ h->tag = 0;
} else {
ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL);
@@ -81,8 +89,10 @@
h->file_pos = h->file_last = 0;
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
- h->tag = 0;
h->file = NULL;
+ h->shadow = NULL;
+
+ h->tag = 0;
}
return h;
diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h
index ddf4d04..c097289 100644
--- a/src/core/ngx_hunk.h
+++ b/src/core/ngx_hunk.h
@@ -79,7 +79,7 @@
#define ngx_add_hunk_to_chain(chain, h, pool, error) \
do { \
- ngx_test_null(chain, ngx_create_chain_entry(pool), error); \
+ ngx_test_null(chain, ngx_alloc_chain_entry(pool), error); \
chain->hunk = h; \
chain->next = NULL; \
} while (0);
diff --git a/src/event/ngx_event_proxy.c b/src/event/ngx_event_proxy.c
index 191aa30..d9f4ebf 100644
--- a/src/event/ngx_event_proxy.c
+++ b/src/event/ngx_event_proxy.c
@@ -2,12 +2,29 @@
#include <ngx_event_proxy.h>
+#define NGX_EVENT_COPY_FILTER 0
+
+#if (NGX_EVENT_COPY_FILTER)
+static int ngx_event_proxy_copy_input_filter(ngx_event_proxy_t *p,
+ ngx_chain_t *chain);
+#endif
+
+
+
int ngx_event_proxy_read_upstream(ngx_event_proxy_t *p)
{
int n, rc, size;
ngx_hunk_t *h, *nh;
ngx_chain_t *chain, *temp, *entry, *next;
+#if (NGX_EVENT_COPY_FILTER)
+
+ if (p->input_filter == NULL) {
+ p->input_filter = ngx_event_proxy_copy_input_filter;
+ }
+
+#endif
+
p->level++;
ngx_log_debug(p->log, "read upstream");
@@ -45,7 +62,8 @@
chain = p->shadow_hunks;
p->shadow_hunks = NULL;
-ngx_log_debug(p->log, "shadow hunk: %08X" _ chain->hunk);
+ngx_log_debug(p->log, "shadow hunk: %08X" _ chain->hunk _
+ chain->hunk->end - chain->hunk->last);
/* if it's allowed then save the incoming hunks to a temporary file,
move the saved hunks to a shadow chain,
@@ -63,7 +81,8 @@
chain = p->shadow_hunks;
p->shadow_hunks = NULL;
-ngx_log_debug(p->log, "new shadow hunk: %08X" _ chain->hunk);
+ngx_log_debug(p->log, "new shadow hunk: %08X:%d" _ chain->hunk _
+ chain->hunk->end - chain->hunk->last);
/* if there're no hunks to read in then disable a level event */
@@ -97,7 +116,9 @@
}
if (n == 0) {
- p->free_hunks = chain;
+ if (chain->hunk->shadow == NULL) {
+ p->free_hunks = chain;
+ }
p->upstream_eof = 1;
p->block_upstream = 0;
break;
@@ -147,29 +168,35 @@
n -= size;
- /* the copy input filter */
+#if !(NGX_EVENT_COPY_FILTER)
- if (p->input_filter == NULL) {
- ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR);
- ngx_memcpy(h, entry->hunk, sizeof(ngx_hunk_t));
- h->shadow = entry->hunk;
- h->type |= NGX_HUNK_LAST_SHADOW;
-
- ngx_test_null(temp, ngx_alloc_chain_entry(p->pool),
- NGX_ERROR);
- temp->hunk = h;
- temp->next = NULL;
-
- if (p->in_hunks) {
- p->last_in_hunk->next = temp;
-
- } else {
- p->in_hunks = temp;
- }
-
- p->last_in_hunk = temp;
+ if (p->input_filter) {
+ continue;
}
+ /* the inline copy input filter */
+
+ ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR);
+ ngx_memcpy(h, entry->hunk, sizeof(ngx_hunk_t));
+ h->shadow = entry->hunk;
+ h->type |= NGX_HUNK_LAST_SHADOW;
+ entry->hunk->shadow = h;
+
+ ngx_test_null(temp, ngx_alloc_chain_entry(p->pool),
+ NGX_ERROR);
+ temp->hunk = h;
+ temp->next = NULL;
+
+ if (p->in_hunks) {
+ p->last_in_hunk->next = temp;
+
+ } else {
+ p->in_hunks = temp;
+ }
+
+ p->last_in_hunk = temp;
+#endif
+
} else {
entry->hunk->last += n;
p->free_hunks = entry;
@@ -178,6 +205,19 @@
}
}
+ if (chain == p->free_hunks) {
+ chain = NULL;
+ }
+
+ /* the input filter i.e. that moves HTTP/1.1 chunks
+ from a read chain to an incoming chain */
+
+ if (p->input_filter) {
+ if (p->input_filter(p, chain) == NGX_ERROR) {
+ return NGX_ERROR;
+ }
+ }
+
ngx_log_debug(p->log, "rest chain: %08X" _ entry);
/* if the rest hunks are shadow then move them to a shadow chain
@@ -199,15 +239,6 @@
p->block_upstream = 0;
break;
}
-
- /* the input filter i.e. that moves HTTP/1.1 chunks
- from a read chain to an incoming chain */
-
- if (p->input_filter) {
- if (p->input_filter(p) == NGX_ERROR) {
- return NGX_ERROR;
- }
- }
}
ngx_log_debug(p->log, "eof: %d block: %d" _
@@ -222,8 +253,15 @@
if (p->free_hunks
&& p->free_hunks->hunk->pos < p->free_hunks->hunk->last)
{
+
+#if (NGX_EVENT_COPY_FILTER)
+
+ if (p->input_filter(p, NULL) == NGX_ERROR) {
+ return NGX_ERROR;
+ }
+#else
if (p->input_filter) {
- if (p->input_filter(p) == NGX_ERROR) {
+ if (p->input_filter(p, NULL) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -242,6 +280,7 @@
p->free_hunks = entry->next;
entry->next = NULL;
+#endif
}
#if 0
@@ -314,6 +353,7 @@
entry = p->out_hunks;
p->out_hunks = entry->next;
h = entry->hunk;
+ entry->next = NULL;
if (p->shadow_hunks) {
if (p->shadow_hunks->hunk == h->shadow) {
@@ -321,16 +361,24 @@
}
}
- entry->next = NULL;
} else if (p->cachable == 0 && p->in_hunks) {
entry = p->in_hunks;
p->in_hunks = entry->next;
h = entry->hunk;
entry->next = NULL;
+
+ if (p->read_hunks) {
+ if (p->read_hunks->hunk == h->shadow) {
+ p->read_hunks = p->read_hunks->next;
+
+ } else {
+ ngx_log_error(NGX_LOG_CRIT, p->log, 0, "ERROR !!!");
+ }
+ }
}
-ngx_log_debug(p->log, "event proxy write hunk: %08X:%08X" _ h _ h->pos);
+ngx_log_debug(p->log, "event proxy write hunk: %08X" _ h);
if (h == NULL) {
if (p->upstream->read->ready) {
@@ -341,7 +389,9 @@
}
}
+#if 0
ngx_log_debug(p->log, "event proxy write: %d" _ h->last - h->pos);
+#endif
rc = p->output_filter(p->output_data, h);
@@ -485,10 +535,10 @@
p->temp_offset += h->last - h->pos;
h->file_last = p->temp_offset;
-ngx_log_debug(p->log, "event proxy file hunk: %08X:%08X" _ h _ h->pos);
+ngx_log_debug(p->log, "event proxy file hunk: %08X:%08X" _ h _ h->shadow);
- if (entry->hunk->type & NGX_HUNK_LAST_SHADOW) {
- entry->hunk->shadow->last = entry->hunk->shadow->pos;
+ if (h->type & NGX_HUNK_LAST_SHADOW) {
+ h->shadow->last = h->shadow->pos;
}
if (p->out_hunks) {
@@ -508,3 +558,57 @@
return NGX_OK;
}
+
+#if (NGX_EVENT_COPY_FILTER)
+
+/* the copy input filter */
+
+static int ngx_event_proxy_copy_input_filter(ngx_event_proxy_t *p,
+ ngx_chain_t *chain)
+{
+ ngx_hunk_t *h;
+ ngx_chain_t *entry, *temp;
+
+ if (p->upstream_eof) {
+ entry = p->free_hunks;
+
+ if (p->in_hunks) {
+ p->last_in_hunk->next = entry;
+
+ } else {
+ p->in_hunks = entry;
+ }
+
+ p->last_in_hunk = entry;
+
+ p->free_hunks = entry->next;
+ entry->next = NULL;
+
+ return NGX_OK;
+ }
+
+ for (entry = chain; entry; entry = entry->next) {
+ ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR);
+ ngx_memcpy(h, entry->hunk, sizeof(ngx_hunk_t));
+ h->shadow = entry->hunk;
+ h->type |= NGX_HUNK_LAST_SHADOW;
+ entry->hunk->shadow = h;
+
+ ngx_test_null(temp, ngx_alloc_chain_entry(p->pool), NGX_ERROR);
+ temp->hunk = h;
+ temp->next = NULL;
+
+ if (p->in_hunks) {
+ p->last_in_hunk->next = temp;
+
+ } else {
+ p->in_hunks = temp;
+ }
+
+ p->last_in_hunk = temp;
+ }
+
+ return NGX_OK;
+}
+
+#endif
diff --git a/src/event/ngx_event_proxy.h b/src/event/ngx_event_proxy.h
index c1d7d1e..c563ea8 100644
--- a/src/event/ngx_event_proxy.h
+++ b/src/event/ngx_event_proxy.h
@@ -12,7 +12,8 @@
typedef struct ngx_event_proxy_s ngx_event_proxy_t;
-typedef int (*ngx_event_proxy_input_filter_pt)(ngx_event_proxy_t *p);
+typedef int (*ngx_event_proxy_input_filter_pt)(ngx_event_proxy_t *p,
+ ngx_chain_t *chain);
typedef int (*ngx_event_proxy_output_filter_pt)(void *data, ngx_hunk_t *hunk);
diff --git a/src/http/modules/proxy/ngx_http_event_proxy_handler.c b/src/http/modules/proxy/ngx_http_event_proxy_handler.c
index 3d76668..874295c 100644
--- a/src/http/modules/proxy/ngx_http_event_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_event_proxy_handler.c
@@ -871,7 +871,7 @@
ep->number = 10;
ep->random = 5;
- ep->max_temp_size = 6000;
+ ep->max_temp_size = p->lcf->max_temp_file_size;
ep->temp_file_warn = "an upstream response is buffered "
"to a temporary file";
@@ -1763,9 +1763,18 @@
conf->send_timeout = 10000;
conf->read_timeout = 10000;
conf->header_size = 1024;
+
+#if 0
conf->block_size = 4096;
conf->max_block_size = 4096 * 3;
- conf->file_block_size = 4096;
+ conf->max_temp_file_size = 4096 * 5;
+ conf->file_block_size = 4096 * 2;
+#else
+ conf->block_size = 2048;
+ conf->max_block_size = 4096 * 6;
+ conf->max_temp_file_size = 4096 * 5;
+ conf->file_block_size = 4096 * 5;
+#endif
ngx_test_null(conf->temp_path, ngx_pcalloc(pool, sizeof(ngx_path_t)), NULL);
diff --git a/src/http/modules/proxy/ngx_http_event_proxy_handler.h b/src/http/modules/proxy/ngx_http_event_proxy_handler.h
index bf159d6..f0fcd97 100644
--- a/src/http/modules/proxy/ngx_http_event_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_event_proxy_handler.h
@@ -71,6 +71,7 @@
int block_size;
int max_block_size;
+ int max_temp_file_size;
int file_block_size;
ngx_path_t *temp_path;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 310f940..3ae8017 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -157,7 +157,7 @@
r->connection->unexpected_eof = 0;
- r->keepalive = 1;
+ r->keepalive = 0;
r->lingering_close = 1;
#if 0
diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c
index 426e921..485aae3 100644
--- a/src/http/ngx_http_output_filter.c
+++ b/src/http/ngx_http_output_filter.c
@@ -65,7 +65,7 @@
#define need_to_copy(r, hunk) \
(((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \
- && (hunk->type & NGX_HUNK_FILE)) \
+ && (hunk->type & NGX_HUNK_IN_MEMORY) == 0) \
|| ((r->filter & NGX_HTTP_FILTER_NEED_TEMP) \
&& (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))))
@@ -257,12 +257,12 @@
}
if (src->type & NGX_HUNK_IN_MEMORY) {
- ngx_memcpy(src->pos, dst->pos, size);
+ ngx_memcpy(dst->pos, src->pos, size);
src->pos += size;
dst->last += size;
if (src->type & NGX_HUNK_FILE) {
- src->file_pos += n;
+ src->file_pos += size;
}
if ((src->type & NGX_HUNK_LAST) && src->pos == src->last) {