]> git.kaiwu.me - nginx.git/commitdiff
Upstream: u->request_body_blocked flag.
authorMaxim Dounin <mdounin@mdounin.ru>
Sat, 17 Mar 2018 20:04:22 +0000 (23:04 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Sat, 17 Mar 2018 20:04:22 +0000 (23:04 +0300)
The flag indicates whether last ngx_output_chain() returned NGX_AGAIN
or not.  If the flag is set, we arm the u->conf->send_timeout timer.
The flag complements c->write->ready test, and allows to stop sending
the request body in an output filter due to protocol-specific flow
control.

src/http/ngx_http_upstream.c
src/http/ngx_http_upstream.h

index 6d91c7cf52fa6d88aa2d49c5de1c7d66833afefe..bc98f81bcb2e59b9063c0ffcdec8b2172cff364a 100644 (file)
@@ -1616,6 +1616,7 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
 
     u->request_sent = 0;
     u->request_body_sent = 0;
+    u->request_body_blocked = 0;
 
     if (rc == NGX_AGAIN) {
         ngx_add_timer(c->write, u->conf->connect_timeout);
@@ -1994,7 +1995,7 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
     }
 
     if (rc == NGX_AGAIN) {
-        if (!c->write->ready) {
+        if (!c->write->ready || u->request_body_blocked) {
             ngx_add_timer(c->write, u->conf->send_timeout);
 
         } else if (c->write->timer_set) {
@@ -2071,7 +2072,16 @@ ngx_http_upstream_send_request_body(ngx_http_request_t *r,
             out = NULL;
         }
 
-        return ngx_output_chain(&u->output, out);
+        rc = ngx_output_chain(&u->output, out);
+
+        if (rc == NGX_AGAIN) {
+            u->request_body_blocked = 1;
+
+        } else {
+            u->request_body_blocked = 0;
+        }
+
+        return rc;
     }
 
     if (!u->request_sent) {
@@ -2112,6 +2122,13 @@ ngx_http_upstream_send_request_body(ngx_http_request_t *r,
                 ngx_free_chain(r->pool, ln);
             }
 
+            if (rc == NGX_AGAIN) {
+                u->request_body_blocked = 1;
+
+            } else {
+                u->request_body_blocked = 0;
+            }
+
             if (rc == NGX_OK && !r->reading_body) {
                 break;
             }
index a56238d37d6a4df21c9867c5708e62770d128698..80fa8b3cba9061e080f6c95a927ad4e341a8616a 100644 (file)
@@ -391,6 +391,7 @@ struct ngx_http_upstream_s {
 
     unsigned                         request_sent:1;
     unsigned                         request_body_sent:1;
+    unsigned                         request_body_blocked:1;
     unsigned                         header_sent:1;
 };