]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stream-int: add si_opposite() to find the other stream interface
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Nov 2014 12:59:31 +0000 (13:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2015 19:41:47 +0000 (20:41 +0100)
At a few places we need to find one stream interface from the other one.
Instead of passing via the channel, we simply use the session as an
intermediary, which simply results in applying an offset to the pointer.

include/proto/stream_interface.h
src/hlua.c
src/stream_interface.c

index 889a8557b55ac39c23aefe9409994cdf4dd7d966..70b2ac8d86543e2c95320c48b62526436d3ec431 100644 (file)
@@ -94,6 +94,15 @@ static inline struct task *si_task(struct stream_interface *si)
                return LIST_ELEM(si, struct session *, si[0])->task;
 }
 
+/* returns the stream interface on the other side. Used during forwarding. */
+static inline struct stream_interface *si_opposite(struct stream_interface *si)
+{
+       if (si->flags & SI_FL_ISBACK)
+               return &LIST_ELEM(si, struct session *, si[1])->si[0];
+       else
+               return &LIST_ELEM(si, struct session *, si[0])->si[1];
+}
+
 /* Initializes all required fields for a new appctx. Note that it does the
  * minimum acceptable initialization for an appctx. This means only the
  * 3 integer states st0, st1, st2 are zeroed.
index b003750979752368ca5c0b4113f4f386391de87f..0aa92e9be3457dbb6d7c04db06ff802ca28cdf82 100644 (file)
@@ -1095,7 +1095,7 @@ __LJMP static struct hlua_socket *hlua_checksocket(lua_State *L, int ud)
 static void hlua_socket_handler(struct stream_interface *si)
 {
        struct appctx *appctx = objt_appctx(si->end);
-       struct connection *c = objt_conn(si_ic(si)->cons->end);
+       struct connection *c = objt_conn(si_opposite(si)->end);
 
        /* Wakeup the main session if the client connection is closed. */
        if (!c || channel_output_closed(si_ic(si)) || channel_input_closed(si_oc(si))) {
index f45678fe2b10b86bcca7eca3aff5b6bd84ad8f88..87df334b2d14a74898ecca38101e2c572f90b247 100644 (file)
@@ -176,13 +176,13 @@ static void stream_int_update_embedded(struct stream_interface *si)
        old_flags = si->flags;
        if (likely((si_oc(si)->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL &&
                   channel_may_recv(si_oc(si)) &&
-                  (si_oc(si)->prod->flags & SI_FL_WAIT_ROOM)))
-               si_chk_rcv(si_oc(si)->prod);
+                  (si_opposite(si)->flags & SI_FL_WAIT_ROOM)))
+               si_chk_rcv(si_opposite(si));
 
        if (((si_ic(si)->flags & CF_READ_PARTIAL) && !channel_is_empty(si_ic(si))) &&
            (si_ic(si)->pipe /* always try to send spliced data */ ||
-            (si_ib(si)->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) {
-               si_chk_snd(si_ic(si)->cons);
+            (si_ib(si)->i == 0 && (si_opposite(si)->flags & SI_FL_WAIT_DATA)))) {
+               si_chk_snd(si_opposite(si));
                /* check if the consumer has freed some space */
                if (channel_may_recv(si_ic(si)) && !si_ic(si)->pipe)
                        si->flags &= ~SI_FL_WAIT_ROOM;
@@ -203,14 +203,14 @@ static void stream_int_update_embedded(struct stream_interface *si)
            si->state != SI_ST_EST ||
            (si->flags & SI_FL_ERR) ||
            ((si_ic(si)->flags & CF_READ_PARTIAL) &&
-            (!si_ic(si)->to_forward || si_ic(si)->cons->state != SI_ST_EST)) ||
+            (!si_ic(si)->to_forward || si_opposite(si)->state != SI_ST_EST)) ||
 
            /* changes on the consumption side */
            (si_oc(si)->flags & (CF_WRITE_NULL|CF_WRITE_ERROR)) ||
            ((si_oc(si)->flags & CF_WRITE_ACTIVITY) &&
             ((si_oc(si)->flags & CF_SHUTW) ||
              ((si_oc(si)->flags & CF_WAKE_WRITE) &&
-              (si_oc(si)->prod->state != SI_ST_EST ||
+              (si_opposite(si)->state != SI_ST_EST ||
                (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) {
                if (!(si->flags & SI_FL_DONT_WAKE))
                        task_wakeup(si_task(si), TASK_WOKEN_IO);
@@ -424,7 +424,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag)
                 */
                if (conn->data == &si_conn_cb) {
                        struct stream_interface *si = conn->owner;
-                       struct connection *remote = objt_conn(si_oc(si)->prod->end);
+                       struct connection *remote = objt_conn(si_opposite(si)->end);
                        ret = make_proxy_line(trash.str, trash.size, objt_server(conn->target), remote);
                }
                else {
@@ -586,8 +586,8 @@ static int si_conn_wake_cb(struct connection *conn)
 
                if (likely((si_oc(si)->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL &&
                           channel_may_recv(si_oc(si)) &&
-                          (si_oc(si)->prod->flags & SI_FL_WAIT_ROOM)))
-                       si_chk_rcv(si_oc(si)->prod);
+                          (si_opposite(si)->flags & SI_FL_WAIT_ROOM)))
+                       si_chk_rcv(si_opposite(si));
        }
 
        /* process producer side.
@@ -599,10 +599,10 @@ static int si_conn_wake_cb(struct connection *conn)
         */
        if (((si_ic(si)->flags & CF_READ_PARTIAL) && !channel_is_empty(si_ic(si))) &&
            (si_ic(si)->pipe /* always try to send spliced data */ ||
-            (si_ib(si)->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) {
+            (si_ib(si)->i == 0 && (si_opposite(si)->flags & SI_FL_WAIT_DATA)))) {
                int last_len = si_ic(si)->pipe ? si_ic(si)->pipe->data : 0;
 
-               si_chk_snd(si_ic(si)->cons);
+               si_chk_snd(si_opposite(si));
 
                /* check if the consumer has freed some space either in the
                 * buffer or in the pipe.
@@ -630,14 +630,14 @@ static int si_conn_wake_cb(struct connection *conn)
            si->state != SI_ST_EST ||
            (si->flags & SI_FL_ERR) ||
            ((si_ic(si)->flags & CF_READ_PARTIAL) &&
-            (!si_ic(si)->to_forward || si_ic(si)->cons->state != SI_ST_EST)) ||
+            (!si_ic(si)->to_forward || si_opposite(si)->state != SI_ST_EST)) ||
 
            /* changes on the consumption side */
            (si_oc(si)->flags & (CF_WRITE_NULL|CF_WRITE_ERROR)) ||
            ((si_oc(si)->flags & CF_WRITE_ACTIVITY) &&
             ((si_oc(si)->flags & CF_SHUTW) ||
              ((si_oc(si)->flags & CF_WAKE_WRITE) &&
-              (si_oc(si)->prod->state != SI_ST_EST ||
+              (si_opposite(si)->state != SI_ST_EST ||
                (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) {
                task_wakeup(si_task(si), TASK_WOKEN_IO);
        }