[nginx] Stream: common handler for upstream and downstream.

Roman Arutyunyan arut at nginx.com
Tue Jun 23 17:19:40 UTC 2015


details:   http://hg.nginx.org/nginx/rev/abee77018d3a
branches:  
changeset: 6200:abee77018d3a
user:      Roman Arutyunyan <arut at nginx.com>
date:      Tue Jun 23 20:17:47 2015 +0300
description:
Stream: common handler for upstream and downstream.

diffstat:

 src/stream/ngx_stream_proxy_module.c |  49 +++++++++++++++--------------------
 1 files changed, 21 insertions(+), 28 deletions(-)

diffs (80 lines):

diff -r 4b703a5a4631 -r abee77018d3a src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c	Thu Jun 18 03:36:41 2015 -0700
+++ b/src/stream/ngx_stream_proxy_module.c	Tue Jun 23 20:17:47 2015 +0300
@@ -52,6 +52,8 @@ static void ngx_stream_proxy_connect(ngx
 static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s);
 static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev);
 static void ngx_stream_proxy_downstream_handler(ngx_event_t *ev);
+static void ngx_stream_proxy_process_connection(ngx_event_t *ev,
+    ngx_uint_t from_upstream);
 static void ngx_stream_proxy_connect_handler(ngx_event_t *ev);
 static ngx_int_t ngx_stream_proxy_test_connect(ngx_connection_t *c);
 static ngx_int_t ngx_stream_proxy_process(ngx_stream_session_t *s,
@@ -815,12 +817,27 @@ done:
 static void
 ngx_stream_proxy_downstream_handler(ngx_event_t *ev)
 {
+    ngx_stream_proxy_process_connection(ev, ev->write);
+}
+
+
+static void
+ngx_stream_proxy_upstream_handler(ngx_event_t *ev)
+{
+    ngx_stream_proxy_process_connection(ev, !ev->write);
+}
+
+
+static void
+ngx_stream_proxy_process_connection(ngx_event_t *ev, ngx_uint_t from_upstream)
+{
     ngx_connection_t       *c;
     ngx_stream_session_t   *s;
     ngx_stream_upstream_t  *u;
 
     c = ev->data;
     s = c->data;
+    u = s->upstream;
 
     if (ev->timedout) {
         ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out");
@@ -828,35 +845,11 @@ ngx_stream_proxy_downstream_handler(ngx_
         return;
     }
 
-    u = s->upstream;
+    if (from_upstream && u->upstream_buf.start == NULL) {
+        return;
+    }
 
-    if (!ev->write) {
-        ngx_stream_proxy_process(s, 0, 0);
-
-    } else if (u->upstream_buf.start) {
-        ngx_stream_proxy_process(s, 1, 1);
-    }
-}
-
-
-static void
-ngx_stream_proxy_upstream_handler(ngx_event_t *ev)
-{
-    ngx_connection_t       *c;
-    ngx_stream_session_t   *s;
-    ngx_stream_upstream_t  *u;
-
-    c = ev->data;
-    s = c->data;
-
-    u = s->upstream;
-
-    if (ev->write) {
-        ngx_stream_proxy_process(s, 0, 1);
-
-    } else if (u->upstream_buf.start) {
-        ngx_stream_proxy_process(s, 1, 0);
-    }
+    ngx_stream_proxy_process(s, from_upstream, ev->write);
 }
 
 



More information about the nginx-devel mailing list