]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: backend: factor out objt_server() in connect_server()
authorWilly Tarreau <w@1wt.eu>
Tue, 4 Aug 2015 17:34:21 +0000 (19:34 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 Aug 2015 08:12:47 +0000 (10:12 +0200)
objt_server() is called multiple times at various places while some
places already make use of srv for this. Let's move the call at the
top of the function and use it all over the place.

src/backend.c

index 35ff17545cd0ed9df3ff320b2cb4623af3bd6907..d55434da72ee671cf193c39897472e32f5b49587 100644 (file)
@@ -1029,6 +1029,7 @@ int connect_server(struct stream *s)
        int reuse = 0;
        int err;
 
+       srv = objt_server(s->target);
        srv_conn = objt_conn(s->si[1].end);
        if (srv_conn)
                reuse = s->target == srv_conn->target;
@@ -1039,7 +1040,6 @@ int connect_server(struct stream *s)
                 * we don't need to disable connection reuse on no-idempotent
                 * requests nor when PROXY protocol is used.
                 */
-               srv = objt_server(s->target);
                if (srv && srv->conn_src.opts & CO_SRC_BIND) {
                        if ((srv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_DYN)
                                reuse = 0;
@@ -1065,8 +1065,8 @@ int connect_server(struct stream *s)
                srv_conn->target = s->target;
 
                /* set the correct protocol on the output stream interface */
-               if (objt_server(s->target)) {
-                       conn_prepare(srv_conn, protocol_by_family(srv_conn->addr.to.ss_family), objt_server(s->target)->xprt);
+               if (srv) {
+                       conn_prepare(srv_conn, protocol_by_family(srv_conn->addr.to.ss_family), srv->xprt);
                }
                else if (obj_type(s->target) == OBJ_TYPE_PROXY) {
                        /* proxies exclusively run on raw_sock right now */
@@ -1079,7 +1079,7 @@ int connect_server(struct stream *s)
 
                /* process the case where the server requires the PROXY protocol to be sent */
                srv_conn->send_proxy_ofs = 0;
-               if (objt_server(s->target) && objt_server(s->target)->pp_opts) {
+               if (srv && srv->pp_opts) {
                        srv_conn->send_proxy_ofs = 1; /* must compute size */
                        cli_conn = objt_conn(strm_orig(s));
                        if (cli_conn)
@@ -1112,7 +1112,6 @@ int connect_server(struct stream *s)
        /* set connect timeout */
        s->si[1].exp = tick_add_ifset(now_ms, s->be->timeout.connect);
 
-       srv = objt_server(s->target);
        if (srv) {
                s->flags |= SF_CURR_SESS;
                srv->cur_sess++;