changeset 146:5ac79e574285

nginx-0.0.1-2003-10-14-09:26:00 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 14 Oct 2003 05:26:00 +0000
parents 58557d0cccd1
children be71fca7f9d7
files src/event/ngx_event_proxy.c src/http/ngx_http_output_filter.c
diffstat 2 files changed, 83 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/event/ngx_event_proxy.c
+++ b/src/event/ngx_event_proxy.c
@@ -110,7 +110,7 @@ ngx_log_debug(p->log, "new hunk: %08X" _
 ngx_log_debug(p->log, "file hunk: %08X" _ chain->hunk _
               chain->hunk->end - chain->hunk->last);
 
-            } else if (p->cachable == 0 && p->downstream->write->ready) {
+            } else if (!p->cachable && p->downstream->write->ready) {
 
                 /*
                  * if the hunks are not needed to be saved in a cache and
@@ -394,6 +394,80 @@ ngx_log_debug(p->log, "upstream level: %
 
 int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
 {
+    ngx_chain_t                   *out, *ce;
+    ngx_event_proxy_downstream_t  *d;
+
+    d = &p->downstream;
+
+    for ( ;; ) {
+
+        if (!d->write->ready || p->busy_hunks_num == p->max_busy_hunks) {
+            break;
+        }
+
+        if (p->out) {
+            out = p->out;
+            p->out = p->out->next;
+
+        } else if (!p->cachable && p->in) {
+            out = p->in;
+            p->in = p->in->next;
+
+        } else {
+            break;
+        }
+
+        out->next = NULL;
+
+        rc = p->output_filter(p->output_data, out->hunk);
+
+        ngx_chain_update_chains(p->shadow_free, p->busy, out);
+
+        for (ce = p->shadow_free; ce; ce = ce->next) {
+
+            if (ce->hunk->type & NGX_LAST_SHADOW_HUNK) {
+                h = ce->hunk->shadow;
+                h->type = (NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY|NGX_HUNK_RECYCLED);
+                h->pos = p->last = h->start;
+                h->shadow = NULL;
+
+                ngx_alloc_ce_and_set_hunk(te, h, p->pool, NGX_ABORT);
+                te->next = p->free;
+                p->free = te;
+            }
+        }
+
+        p->busy_hunks_num = 0;
+        for (ce = p->busy; ce; ce = ce->next) {
+            if (ce->hunk->type & NGX_LAST_SHADOW_HUNK) {
+                p->busy_hunks_num++;
+            }
+        }
+
+        if (p->upstream.read->ready)
+            if (ngx_event_proxy_read_upstream(p) == NGX_ERROR) {
+                return NGX_ABORT;
+            }
+        }
+    }
+
+    if (d->level == 0) {
+        if (ngx_handler_write_event(d->write) == NGX_ERROR) {
+            return NGX_ABORT;
+        }
+    }
+
+    if (p->upstream_done && p->in == NULL && p->out == NULL) {
+        p->downstream_done = 1;
+    }
+
+    return NGX_OK;
+}
+
+
+
+int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
+{
     int           rc;
     ngx_hunk_t   *h;
     ngx_chain_t  *entry;
@@ -686,7 +760,7 @@ static int ngx_event_proxy_copy_input_fi
 
     if (p->upstream_eof) {
 
-        /* THINK comment */
+        /* TODO: comment */
 
         ce = p->free_hunks;
 
--- a/src/http/ngx_http_output_filter.c
+++ b/src/http/ngx_http_output_filter.c
@@ -19,8 +19,12 @@ typedef struct {
     ngx_hunk_t    *hunk;
 
     ngx_chain_t   *in;
+
+    /* TODO: out and last_out should be local variables */
     ngx_chain_t   *out;
     ngx_chain_t  **last_out;
+    /* */
+
     ngx_chain_t   *free;
     ngx_chain_t   *busy;
 
@@ -180,6 +184,9 @@ int ngx_http_output_filter(ngx_http_requ
 
 #if (NGX_FILE_AIO_READ)
             if (rc == NGX_AGAIN) {
+                if (ctx->out) {
+                    break;
+                }
                 return rc;
             }
 #endif