Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-10-20 21:14:07 +0400
committerIgor Sysoev <igor@sysoev.ru>2003-10-20 21:14:07 +0400
commit54276be80c35fcff04da8cd129452995e9ba8ba5 (patch)
tree78288161f5b678ca73acc281e64302034cf3e54a /src
parent13829b7316411fa13c848015e1011a53405f37be (diff)
nginx-0.0.1-2003-10-20-21:14:07 import
Diffstat (limited to 'src')
-rw-r--r--src/core/ngx_hunk.c19
-rw-r--r--src/event/ngx_event_proxy.c56
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c113
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h1
-rw-r--r--src/http/ngx_http_request.c1
-rw-r--r--src/http/ngx_http_request.h1
-rw-r--r--src/os/unix/ngx_readv_chain.c2
7 files changed, 118 insertions, 75 deletions
diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c
index 517a1af23..df213c7b3 100644
--- a/src/core/ngx_hunk.c
+++ b/src/core/ngx_hunk.c
@@ -144,16 +144,31 @@ void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
*out = NULL;
while (*busy) {
- if ((*busy)->hunk->pos != (*busy)->hunk->last) {
+ if (ngx_hunk_size((*busy)->hunk) > 0) {
break;
}
+#if 0
+ if ((*busy)->hunk->type & NGX_HUNK_IN_MEMORY) {
+ if ((*busy)->hunk->pos != (*busy)->hunk->last) {
+ break;
+ }
+
+ } else {
+ if ((*busy)->hunk->file_pos != (*busy)->hunk->file_last) {
+ break;
+ }
+ }
+#endif
#if (HAVE_WRITE_ZEROCOPY)
if ((*busy)->hunk->type & NGX_HUNK_ZEROCOPY_BUSY) {
break;
}
#endif
- if (((*busy)->hunk->type & NGX_HUNK_TEMP) == 0) {
+
+ /* TODO: change to hunk->tag */
+
+ if (!((*busy)->hunk->type & NGX_HUNK_TEMP)) {
*busy = (*busy)->next;
continue;
}
diff --git a/src/event/ngx_event_proxy.c b/src/event/ngx_event_proxy.c
index 97c1cbe7a..dae5809dc 100644
--- a/src/event/ngx_event_proxy.c
+++ b/src/event/ngx_event_proxy.c
@@ -12,7 +12,6 @@ ngx_inline static void ngx_add_after_partially_filled_hunk(ngx_chain_t **chain,
ngx_chain_t *ce);
-
int ngx_event_proxy(ngx_event_proxy_t *p, int do_write)
{
for ( ;; ) {
@@ -105,6 +104,7 @@ int ngx_event_proxy_read_upstream(ngx_event_proxy_t *p)
chain = p->free_raw_hunks;
p->free_raw_hunks = NULL;
+ngx_log_debug(p->log, "FREE: %08X:%d" _ chain->hunk->pos _ chain->hunk->end - chain->hunk->last);
} else if (p->hunks < p->bufs.num) {
@@ -173,6 +173,8 @@ int ngx_event_proxy_read_upstream(ngx_event_proxy_t *p)
ngx_log_debug(p->log, "recv_chain: %d" _ n);
+ p->free_raw_hunks = chain;
+
if (n == NGX_ERROR) {
p->upstream_error = 1;
return NGX_ERROR;
@@ -186,15 +188,15 @@ int ngx_event_proxy_read_upstream(ngx_event_proxy_t *p)
p->read = 1;
if (n == 0) {
- p->free_raw_hunks = chain;
p->upstream_eof = 1;
-
break;
}
}
- for (ce = chain; ce && n > 0; ce = ce->next) {
+ ce = chain;
+
+ while (ce && n > 0) {
ngx_remove_shadow_links(ce->hunk);
@@ -208,16 +210,17 @@ int ngx_event_proxy_read_upstream(ngx_event_proxy_t *p)
}
n -= size;
-
- chain = ce->next;
+ ce = ce->next;
} else {
+ngx_log_debug(p->log, "PART: %08X:%d:%d" _ ce->hunk->pos _ ce->hunk->last - ce->hunk->pos _ n);
ce->hunk->last += n;
+ngx_log_debug(p->log, "PART: %08X:%d" _ ce->hunk->pos _ ce->hunk->end - ce->hunk->last);
n = 0;
}
}
- p->free_raw_hunks = chain;
+ p->free_raw_hunks = ce;
}
if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) {
@@ -290,7 +293,8 @@ int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
rc = p->output_filter(p->output_ctx, out->hunk);
if (rc == NGX_ERROR) {
- /* TODO */
+ p->downstream_error = 1;
+ return NGX_ERROR;
}
ngx_chain_update_chains(&p->free, &p->busy, &out);
@@ -305,14 +309,16 @@ int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
/* add the free shadow raw hunks to p->free_raw_hunks */
for (ce = p->free; ce; ce = ce->next) {
+ngx_log_debug(p->log, "SHADOW %08X" _ ce->hunk->shadow);
if (ce->hunk->type & NGX_HUNK_LAST_SHADOW) {
h = ce->hunk->shadow;
/* THINK NEEDED ??? */ h->pos = h->last = h->start;
h->shadow = NULL;
- ngx_alloc_ce_and_set_hunk(te, ce->hunk->shadow, p->pool,
- NGX_ABORT);
+ ngx_alloc_ce_and_set_hunk(te, h, p->pool, NGX_ABORT);
ngx_add_after_partially_filled_hunk(&p->free_raw_hunks, te);
+ngx_log_debug(p->log, "RAW %08X" _ h->pos);
+
ce->hunk->type &= ~NGX_HUNK_LAST_SHADOW;
}
ce->hunk->shadow = NULL;
@@ -326,7 +332,17 @@ int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
}
- if (p->upstream_done && p->in == NULL && p->out == NULL) {
+ ngx_log_debug(p->log, "STATE %d:%d:%d:%X:%X" _
+ p->upstream_eof _
+ p->upstream_error _
+ p->upstream_done _
+ p->in _
+ p->out
+ );
+
+ if ((p->upstream_eof || p->upstream_error || p->upstream_done)
+ && p->in == NULL && p->out == NULL)
+ {
p->downstream_done = 1;
}
@@ -365,17 +381,25 @@ static int ngx_event_proxy_write_chain_to_temp_file(ngx_event_proxy_t *p)
ce = p->in;
do {
- size += ce->hunk->last - ce->hunk->pos;
- if (size >= p->temp_file_write_size) {
+ if (size + ce->hunk->last - ce->hunk->pos
+ >= p->temp_file_write_size)
+ {
break;
}
+ size += ce->hunk->last - ce->hunk->pos;
ce = ce->next;
} while (ce);
- in = ce->next;
- last = &ce->next;
- ce->next = NULL;
+ if (ce) {
+ in = ce->next;
+ last = &ce->next;
+ ce->next = NULL;
+
+ } else {
+ in = NULL;
+ last = &p->in;
+ }
} else {
in = NULL;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 5f50563be..87d472c34 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -17,8 +17,7 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev);
static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev);
static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *);
static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p);
-static void ngx_http_proxy_process_upstream(ngx_event_t *rev);
-static void ngx_http_proxy_process_downstream(ngx_event_t *wev);
+static void ngx_http_proxy_process_body(ngx_event_t *ev);
static int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p);
static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p);
@@ -235,7 +234,9 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
continue;
}
- /* TODO: delete "Keep-Alive" header */
+ if (&header[i] == r->headers_in.keep_alive) {
+ continue;
+ }
h->last = ngx_cpymem(h->last, header[i].key.data, header[i].key.len);
@@ -741,6 +742,8 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
ep->preread_size = p->header_in->last - p->header_in->pos;
+ /* STUB */ ep->cachable = 0;
+
p->event_proxy = ep;
#if 0
@@ -748,83 +751,81 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
lcx->action = "reading an upstream";
#endif
- p->upstream.connection->read->event_handler =
- ngx_http_proxy_process_upstream;
- r->connection->write->event_handler =
- ngx_http_proxy_process_downstream;
+ p->upstream.connection->read->event_handler = ngx_http_proxy_process_body;
+ r->connection->write->event_handler = ngx_http_proxy_process_body;
- ngx_http_proxy_process_upstream(p->upstream.connection->read);
+ ngx_http_proxy_process_body(p->upstream.connection->read);
return;
}
-static void ngx_http_proxy_process_upstream(ngx_event_t *rev)
+static void ngx_http_proxy_process_body(ngx_event_t *ev)
{
ngx_connection_t *c;
+ ngx_http_request_t *r;
ngx_http_proxy_ctx_t *p;
+ ngx_event_proxy_t *ep;
- c = rev->data;
- p = c->data;
+ c = ev->data;
- ngx_log_debug(rev->log, "http proxy process upstream");
-
- if (rev->timedout) {
- ngx_http_proxy_close_connection(c);
- p->upstream.connection = NULL;
- return;
- }
+ if (ev->write) {
+ ngx_log_debug(ev->log, "http proxy process downstream");
+ r = c->data;
+ p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
- if (ngx_event_proxy(p->event_proxy, 0) == NGX_ABORT) {
- ngx_http_proxy_finalize_request(p, 0);
- return;
+ } else {
+ ngx_log_debug(ev->log, "http proxy process upstream");
+ p = c->data;
+ r = p->request;
}
- if (p->event_proxy->upstream_eof
- || p->event_proxy->upstream_error
- || p->event_proxy->upstream_done)
- {
- ngx_http_proxy_close_connection(c);
- p->upstream.connection = NULL;
- return;
- }
+ ep = p->event_proxy;
- return;
-}
+ if (ev->timedout) {
+ if (ev->write) {
+ ep->downstream_error = 1;
+ } else {
+ ep->upstream_error = 1;
+ }
-static void ngx_http_proxy_process_downstream(ngx_event_t *wev)
-{
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_proxy_ctx_t *p;
+ } else {
+ if (ngx_event_proxy(ep, ev->write) == NGX_ABORT) {
+ ngx_http_proxy_finalize_request(p, 0);
+ return;
+ }
+ }
- c = wev->data;
- r = c->data;
- p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
-
- ngx_log_debug(wev->log, "http proxy process downstream");
+ if (p->upstream.connection) {
+ if (ep->upstream_done) {
+ /* TODO: update cache */
- if (wev->timedout) {
- ngx_http_close_connection(c);
- return;
- }
+ } else if (ep->upstream_eof) {
+ /* TODO: check length & update cache */
+ }
- if (ngx_event_proxy(p->event_proxy, 1) == NGX_ABORT) {
- ngx_http_proxy_finalize_request(p, 0);
- return;
+ if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
+ ngx_http_proxy_close_connection(c);
+ p->upstream.connection = NULL;
+ }
}
- if (p->event_proxy->downstream_done) {
-ngx_log_debug(wev->log, "http proxy downstream done");
- ngx_http_proxy_finalize_request(p, r->main ? 0:
- ngx_http_send_last(p->request));
+ if (ep->downstream_done) {
+ ngx_log_debug(ev->log, "http proxy downstream done");
+ ngx_http_proxy_finalize_request(p, r->main ? 0 : ngx_http_send_last(r));
return;
}
- if (p->event_proxy->downstream_error) {
- ngx_http_close_connection(c);
- return;
+ if (ep->downstream_error) {
+ if (!p->cachable && p->upstream.connection) {
+ ngx_http_proxy_close_connection(c);
+ p->upstream.connection = NULL;
+ }
+
+ if (p->upstream.connection == NULL) {
+ ngx_http_close_connection(c);
+ }
}
return;
@@ -1151,7 +1152,7 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
conf->bufs.num = 10;
conf->bufs.size = 4096;
conf->max_busy_len = 8192 + 4096;
- conf->max_temp_file_size = 4096 * 5;
+ conf->max_temp_file_size = 4096 * 6;
conf->temp_file_write_size = 4096 * 2;
ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)),
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 795373adf..207b6480e 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -77,6 +77,7 @@ struct ngx_http_proxy_ctx_s {
ngx_event_proxy_t *event_proxy;
unsigned accel:1;
+ unsigned cachable:1;
unsigned fatal_error:1;
unsigned header_sent:1;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index f972402b7..fb5bf2c48 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -59,6 +59,7 @@ static ngx_http_header_t headers_in[] = {
#endif
{ ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) },
+ { ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
{ ngx_null_string, 0 }
};
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index c3029909f..f47ea6cd0 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -75,6 +75,7 @@ typedef struct {
ngx_table_elt_t *accept_encoding;
ngx_table_elt_t *user_agent;
+ ngx_table_elt_t *keep_alive;
ngx_table_t *headers;
} ngx_http_headers_in_t;
diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c
index 7fa7d84f5..fe9a505c7 100644
--- a/src/os/unix/ngx_readv_chain.c
+++ b/src/os/unix/ngx_readv_chain.c
@@ -21,7 +21,7 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *entry)
while (entry) {
ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR);
- iov->iov_base = entry->hunk->pos;
+ iov->iov_base = entry->hunk->last;
iov->iov_len = entry->hunk->end - entry->hunk->last;
entry = entry->next;
}