]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: reintroduce conn_prepare to set the protocol and transport
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Oct 2013 13:08:37 +0000 (15:08 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2013 14:40:23 +0000 (15:40 +0100)
Now that we can assign conn->xprt regardless of the initialization state,
we can reintroduce conn_prepare() to set only the protocol, the transport
layer and initialize the transport layer's state.

include/proto/connection.h
src/checks.c
src/session.c

index e3b6e891be313aba8f651e88b30579d5dc4f8676..5c72a95ae8bd90f4e9965b9797e4425acdc5cbe3 100644 (file)
@@ -468,6 +468,17 @@ static inline int conn_sock_shutw_pending(struct connection *c)
        return (c->flags & (CO_FL_DATA_WR_SH | CO_FL_SOCK_WR_SH)) == CO_FL_DATA_WR_SH;
 }
 
+/* prepares a connection to work with protocol <proto> and transport <xprt>.
+ * The transport's context is initialized as well.
+ */
+static inline void conn_prepare(struct connection *conn, const struct protocol *proto, const struct xprt_ops *xprt)
+{
+       conn->ctrl = proto;
+       conn->xprt = xprt;
+       conn->xprt_st = 0;
+       conn->xprt_ctx = NULL;
+}
+
 /* Initializes all required fields for a new connection. Note that it does the
  * minimum acceptable initialization for a connection that already exists and
  * is about to be reused. It also leaves the addresses untouched, which makes
@@ -477,8 +488,6 @@ static inline void conn_init(struct connection *conn)
 {
        conn->obj_type = OBJ_TYPE_CONN;
        conn->flags = CO_FL_NONE;
-       conn->xprt_st = 0;
-       conn->xprt_ctx = NULL;
        conn->data = NULL;
        conn->owner = NULL;
        conn->t.sock.fd = -1; /* just to help with debugging */
index 2213782220229f896e2405599d6eccfe152abcbe..b96f13dc8fba027e430db7f8e948a02322a1b7e0 100644 (file)
@@ -1541,6 +1541,7 @@ static struct task *process_chk(struct task *t)
 
                /* prepare a new connection */
                conn_init(conn);
+               conn_prepare(conn, s->check_common.proto, s->check_common.xprt);
                conn_assign(conn, &check_conn_cb, s->check_common.proto, s->check_common.xprt, check);
                conn->target = &s->obj_type;
 
index df1b43cbbaf1c82325c54159550a3cab22a3ea8a..9acfa7a0852c07fb09d3a87eaf45fedbf1c9c5fc 100644 (file)
@@ -110,8 +110,8 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
         */
        conn_init(cli_conn);
        cli_conn->t.sock.fd = cfd;
-       cli_conn->ctrl = l->proto;
        cli_conn->flags |= CO_FL_ADDR_FROM_SET;
+       conn_prepare(cli_conn, l->proto, l->xprt);
        cli_conn->addr.from = *addr;
        cli_conn->target = &l->obj_type;