From: Willy Tarreau Date: Tue, 4 Aug 2015 17:34:21 +0000 (+0200) Subject: CLEANUP: backend: factor out objt_server() in connect_server() X-Git-Tag: v1.6-dev4~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b00492ce3d7be9b5f8ecf4863a700f271f11936;p=thirdparty%2Fhaproxy.git CLEANUP: backend: factor out objt_server() in connect_server() 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. --- diff --git a/src/backend.c b/src/backend.c index 35ff17545c..d55434da72 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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++;