]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MAJOR: stream-int: handle the connection reuse in si_connect()
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Dec 2013 15:20:50 +0000 (16:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Dec 2013 01:23:53 +0000 (02:23 +0100)
This is the best place to reuse a connection. We centralize all
connection requests and we're at the best place to know exactly
what the current state of the underlying connection is. If the
connection is reused, we just enable polling for send() in order
to be able to emit the request.

include/proto/stream_interface.h

index 588b83e16cc833bcbeb7430cea08896c6639ebb2..938ccc1431146e1f24dcaef70dd421032f4530fe 100644 (file)
@@ -298,14 +298,22 @@ static inline void si_chk_snd(struct stream_interface *si)
 static inline int si_connect(struct stream_interface *si)
 {
        struct connection *conn = objt_conn(si->end);
-       int ret;
+       int ret = SN_ERR_NONE;
 
        if (unlikely(!conn || !conn->ctrl || !conn->ctrl->connect))
                return SN_ERR_INTERNAL;
 
-       ret = conn->ctrl->connect(conn, !channel_is_empty(si->ob), 0);
-       if (ret != SN_ERR_NONE)
-               return ret;
+       if (!conn_ctrl_ready(conn) || !conn_xprt_ready(conn)) {
+               ret = conn->ctrl->connect(conn, !channel_is_empty(si->ob), 0);
+               if (ret != SN_ERR_NONE)
+                       return ret;
+       }
+       else if (!channel_is_empty(si->ob)) {
+               /* reuse the existing connection, we'll have to send a
+                * request there.
+                */
+               conn_data_want_send(conn);
+       }
 
        /* needs src ip/port for logging */
        if (si->flags & SI_FL_SRC_ADDR)