]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream-interface: introduce si_attach_conn to replace si_prepare_conn
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Oct 2013 13:50:53 +0000 (15:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2013 14:40:23 +0000 (15:40 +0100)
si_prepare_conn() is not appropriate in our case as it both initializes and
attaches the connection to the stream interface. Due to the asymmetry between
accept() and connect(), it causes some fields such as the control and transport
layers to be reinitialized.

Now that we can separately initialize these fields using conn_prepare(), let's
break this function to only attach the connection to the stream interface.

Also, by analogy, si_prepare_none() was renamed si_detach(), and
si_prepare_applet() was renamed si_attach_applet().

include/proto/stream_interface.h
src/backend.c
src/peers.c
src/session.c
src/stream_interface.c

index 6bedaffcca43d7b1c6797957f7600416af006e5b..511099cd1750f5ba85968cfcd1b2bd904eb4fa22 100644 (file)
@@ -70,29 +70,25 @@ static inline void si_set_state(struct stream_interface *si, int state)
        si->state = si->prev_state = state;
 }
 
-static inline void si_prepare_none(struct stream_interface *si)
+static inline void si_detach(struct stream_interface *si)
 {
        si->ops = &si_embedded_ops;
        si->end = NULL;
        si->appctx.applet = NULL;
 }
 
-/* Assign the stream interface's pre-allocated connection to the end point,
- * and leave the connection's context untouched. This is used for incoming
- * and outgoing connections. The caller is responsible for ensuring that
- * si->conn already points to the connection.
+/* Attach connection <conn> to the stream interface <si>. The stream interface
+ * is configured to work with a connection and the connection it configured
+ * with a stream interface data layer.
  */
-static inline void si_prepare_conn(struct stream_interface *si, const struct protocol *ctrl, const struct xprt_ops *xprt)
+static inline void si_attach_conn(struct stream_interface *si, struct connection *conn)
 {
-       struct connection *conn = si->conn;
-
        si->ops = &si_conn_ops;
        si->end = &conn->obj_type;
-       conn_prepare(conn, ctrl, xprt);
        conn_attach(conn, si, &si_conn_cb);
 }
 
-static inline void si_prepare_applet(struct stream_interface *si, struct si_applet *applet)
+static inline void si_attach_applet(struct stream_interface *si, struct si_applet *applet)
 {
        si->ops = &si_embedded_ops;
        si->appctx.applet = applet;
index 65cbcb6500fb68d588d437599ee14f6b265f912e..a06a332a2aca29235988444756d71be0c9706625 100644 (file)
@@ -997,17 +997,19 @@ int connect_server(struct session *s)
 
        /* set the correct protocol on the output stream interface */
        if (objt_server(s->target)) {
-               si_prepare_conn(s->req->cons, objt_server(s->target)->proto, objt_server(s->target)->xprt);
+               conn_prepare(srv_conn, objt_server(s->target)->proto, objt_server(s->target)->xprt);
        }
        else if (obj_type(s->target) == OBJ_TYPE_PROXY) {
                /* proxies exclusively run on raw_sock right now */
-               si_prepare_conn(s->req->cons, protocol_by_family(srv_conn->addr.to.ss_family), &raw_sock);
+               conn_prepare(srv_conn, protocol_by_family(srv_conn->addr.to.ss_family), &raw_sock);
                if (!objt_conn(s->req->cons->end) || !objt_conn(s->req->cons->end)->ctrl)
                        return SN_ERR_INTERNAL;
        }
        else
                return SN_ERR_INTERNAL;  /* how did we get there ? */
 
+       si_attach_conn(s->req->cons, srv_conn);
+
        /* process the case where the server requires the PROXY protocol to be sent */
        s->req->cons->send_proxy_ofs = 0;
        if (objt_server(s->target) && (objt_server(s->target)->state & SRV_SEND_PROXY)) {
index 86237041b55b5f4ca810bb7dc33cf3aa81b579f4..33f8eaa6a246039fb44b214b6fde6db192d755f9 100644 (file)
@@ -1187,7 +1187,8 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
         * pre-initialized connection in si->conn.
         */
        conn_init(s->si[1].conn);
-       si_prepare_conn(&s->si[1], peer->proto, peer->xprt);
+       conn_prepare(s->si[1].conn, peer->proto, peer->xprt);
+       si_attach_conn(&s->si[1], s->si[1].conn);
 
        session_init_srv_conn(s);
        s->si[1].conn->target = s->target = &s->be->obj_type;
index f8b29d54247d5efcd16a473468fb42b8c8ee6b03..7218dae4a6395523ec325f349768c72202d02948 100644 (file)
@@ -433,7 +433,8 @@ int session_complete(struct session *s)
                s->si[0].flags |= SI_FL_INDEP_STR;
 
        s->si[0].conn = conn;
-       si_prepare_conn(&s->si[0], l->proto, l->xprt);
+       conn_prepare(conn, l->proto, l->xprt);
+       si_attach_conn(&s->si[0], conn);
 
        s->flags |= SN_INITIALIZED;
        s->unique_id = NULL;
@@ -475,7 +476,7 @@ int session_complete(struct session *s)
        si_reset(&s->si[1], t);
        conn_init(s->si[1].conn);
        s->si[1].conn->target = NULL;
-       si_prepare_none(&s->si[1]);
+       si_detach(&s->si[1]);
 
        if (likely(s->fe->options2 & PR_O2_INDEPSTR))
                s->si[1].flags |= SI_FL_INDEP_STR;
index 95f5d44a8bffee78b4a0bad96a5dddea4b3ef4ca..00b28e607766cc64ab56ad9946f1d7f77fca838f 100644 (file)
@@ -354,7 +354,7 @@ struct task *stream_int_register_handler(struct stream_interface *si, struct si_
 {
        DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner);
 
-       si_prepare_applet(si, app);
+       si_attach_applet(si, app);
        si->flags |= SI_FL_WAIT_DATA;
        return si->owner;
 }