# HG changeset patch # User Igor Sysoev # Date 1050419212 0 # Node ID 6127d707547114ca6f5e62e4cc76e25fa009f718 # Parent 869b10be682f6320e9fdc6a7d6a4c28dab60613f 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 --- a/src/core/ngx_hunk.c +++ b/src/core/ngx_hunk.c @@ -18,8 +18,10 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_poo h->post_end = h->end + after; h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; + h->file = NULL; + h->shadow = NULL; + h->tag = 0; - h->file = NULL; return h; } @@ -38,8 +40,10 @@ ngx_hunk_t *ngx_create_hunk_before(ngx_p h->file_pos = h->file_last = 0; h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; + h->file = NULL; + h->shadow = NULL; + h->tag = 0; - h->file = NULL; } else { ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL); @@ -48,8 +52,10 @@ ngx_hunk_t *ngx_create_hunk_before(ngx_p h->file_pos = h->file_last = 0; h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; + h->file = NULL; + h->shadow = NULL; + h->tag = 0; - h->file = NULL; } return h; @@ -71,8 +77,10 @@ ngx_hunk_t *ngx_create_hunk_after(ngx_po h->file_pos = h->file_last = 0; h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; + h->file = NULL; + h->shadow = NULL; + h->tag = 0; - h->file = NULL; } else { ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL); @@ -81,8 +89,10 @@ ngx_hunk_t *ngx_create_hunk_after(ngx_po h->file_pos = h->file_last = 0; h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; + h->file = NULL; + h->shadow = NULL; + h->tag = 0; - h->file = NULL; } return h; diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h --- a/src/core/ngx_hunk.h +++ b/src/core/ngx_hunk.h @@ -79,7 +79,7 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_poo #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 --- a/src/event/ngx_event_proxy.c +++ b/src/event/ngx_event_proxy.c @@ -2,12 +2,29 @@ #include +#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 @@ ngx_log_debug(p->log, "new hunk: %08X" _ 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 @@ ngx_log_debug(p->log, "temp offset: %d" 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 @@ ngx_log_debug(p->log, "recv_chain: %d" _ } 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,28 +168,34 @@ ngx_log_debug(p->log, "recv_chain: %d" _ n -= size; - /* the copy input filter */ +#if !(NGX_EVENT_COPY_FILTER) + + if (p->input_filter) { + continue; + } - 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; + /* 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; + 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; + if (p->in_hunks) { + p->last_in_hunk->next = temp; - } else { - p->in_hunks = temp; - } + } else { + p->in_hunks = temp; + } - p->last_in_hunk = temp; - } + p->last_in_hunk = temp; +#endif } else { entry->hunk->last += n; @@ -178,6 +205,19 @@ ngx_log_debug(p->log, "recv_chain: %d" _ } } + 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 @@ ngx_log_debug(p->log, "rest chain: %08X" 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 @@ ngx_log_debug(p->log, "eof: %d block: %d 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 @@ ngx_log_debug(p->log, "eof: %d block: %d p->free_hunks = entry->next; entry->next = NULL; +#endif } #if 0 @@ -314,6 +353,7 @@ ngx_log_debug(p->log, "write to client") 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 @@ ngx_log_debug(p->log, "write to client") } } - 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 @@ ngx_log_debug(p->log, "event proxy write } } +#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 @@ ngx_log_debug(p->log, "write to file"); 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 @@ ngx_log_debug(p->log, "event proxy file 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 --- 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 --- 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 @@ static int ngx_http_proxy_read_upstream_ 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 @@ static void *ngx_http_proxy_create_loc_c 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 --- 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 @@ typedef struct { 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 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -157,7 +157,7 @@ int ngx_http_handler(ngx_http_request_t 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 --- a/src/http/ngx_http_output_filter.c +++ b/src/http/ngx_http_output_filter.c @@ -65,7 +65,7 @@ static int (*next_filter) (ngx_http_requ #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 @@ static int ngx_http_output_filter_copy_h } 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) {