diff src/event/ngx_event_pipe.c @ 518:86dad910eeb6 NGINX_0_8_11

nginx 0.8.11 *) Change: directive "gzip_disable msie6" enables gzipping for MSIE 6.0 SV1. *) Feature: file AIO support on FreeBSD and Linux. *) Feature: the "directio_alignment" directive.
author Igor Sysoev <http://sysoev.ru>
date Fri, 28 Aug 2009 00:00:00 +0400
parents 6484cbba0222
children 943566b4d82e
line wrap: on
line diff
--- a/src/event/ngx_event_pipe.c
+++ b/src/event/ngx_event_pipe.c
@@ -24,15 +24,22 @@ ngx_int_t
 ngx_event_pipe(ngx_event_pipe_t *p, ngx_int_t do_write)
 {
     u_int         flags;
+    ngx_int_t     rc;
     ngx_event_t  *rev, *wev;
 
     for ( ;; ) {
         if (do_write) {
             p->log->action = "sending to client";
 
-            if (ngx_event_pipe_write_to_downstream(p) == NGX_ABORT) {
+            rc = ngx_event_pipe_write_to_downstream(p);
+
+            if (rc == NGX_ABORT) {
                 return NGX_ABORT;
             }
+
+            if (rc == NGX_BUSY) {
+                return NGX_OK;
+            }
         }
 
         p->read = 0;
@@ -422,7 +429,7 @@ ngx_event_pipe_write_to_downstream(ngx_e
     u_char            *prev;
     size_t             bsize;
     ngx_int_t          rc;
-    ngx_uint_t         flush, prev_last_shadow;
+    ngx_uint_t         flush, flushed, prev_last_shadow;
     ngx_chain_t       *out, **ll, *cl, file;
     ngx_connection_t  *downstream;
 
@@ -431,6 +438,8 @@ ngx_event_pipe_write_to_downstream(ngx_e
     ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
                    "pipe write downstream: %d", downstream->write->ready);
 
+    flushed = 0;
+
     for ( ;; ) {
         if (p->downstream_error) {
             return ngx_event_pipe_drain_chains(p);
@@ -454,10 +463,6 @@ ngx_event_pipe_write_to_downstream(ngx_e
 
                 rc = p->output_filter(p->output_ctx, p->out);
 
-                if (downstream->destroyed) {
-                    return NGX_ABORT;
-                }
-
                 if (rc == NGX_ERROR) {
                     p->downstream_error = 1;
                     return ngx_event_pipe_drain_chains(p);
@@ -476,10 +481,6 @@ ngx_event_pipe_write_to_downstream(ngx_e
 
                 rc = p->output_filter(p->output_ctx, p->in);
 
-                if (downstream->destroyed) {
-                    return NGX_ABORT;
-                }
-
                 if (rc == NGX_ERROR) {
                     p->downstream_error = 1;
                     return ngx_event_pipe_drain_chains(p);
@@ -618,16 +619,20 @@ ngx_event_pipe_write_to_downstream(ngx_e
         ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
                        "pipe write: out:%p, f:%d", out, flush);
 
-        if (out == NULL && !flush) {
-            break;
+        if (out == NULL) {
+
+            if (!flush) {
+                break;
+            }
+
+            /* a workaround for AIO */
+            if (flushed++ > 10) {
+                return NGX_BUSY;
+            }
         }
 
         rc = p->output_filter(p->output_ctx, out);
 
-        if (downstream->destroyed) {
-            return NGX_ABORT;
-        }
-
         if (rc == NGX_ERROR) {
             p->downstream_error = 1;
             return ngx_event_pipe_drain_chains(p);