]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MAJOR: session: check for a connection to an applet in sess_prepare_conn_req()
authorWilly Tarreau <w@1wt.eu>
Sat, 30 Nov 2013 08:06:53 +0000 (09:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2013 14:40:22 +0000 (15:40 +0100)
Instead of having applets bypass the whole connection process, we now
follow the common path through sess_prepare_conn_req(). It is this
function which detects an applet an sets the output state so SI_ST_EST
instead of initiating a connection to a server. It is made possible
because we now have s->target pointing to the applet.

src/session.c

index 8dd6d05b9a91fc36aea63ff606c470f13a5d0c57..5274971f1e1ea5f50f97c6a3b4b9ec7b25da969b 100644 (file)
@@ -1151,9 +1151,10 @@ static void sess_set_term_flags(struct session *s)
 }
 
 /* This function initiates a server connection request on a stream interface
- * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS,
- * indicating that a server has been assigned. It may also return SI_ST_QUE,
- * or SI_ST_CLO upon error.
+ * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS for
+ * a real connection to a server, indicating that a server has been assigned,
+ * or SI_ST_EST for a successful connection to an applet. It may also return
+ * SI_ST_QUE, or SI_ST_CLO upon error.
  */
 static void sess_prepare_conn_req(struct session *s, struct stream_interface *si)
 {
@@ -1168,6 +1169,18 @@ static void sess_prepare_conn_req(struct session *s, struct stream_interface *si
        if (si->state != SI_ST_REQ)
                return;
 
+       if (unlikely(obj_type(s->target) == OBJ_TYPE_APPLET)) {
+               /* the applet directly goes to the EST state */
+               s->logs.t_queue   = tv_ms_elapsed(&s->logs.tv_accept, &now);
+               s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now);
+               si->state         = SI_ST_EST;
+               si->err_type      = SI_ET_NONE;
+               si->exp           = TICK_ETERNITY;
+               s->req->wex       = TICK_ETERNITY;
+               s->rep->flags    |= CF_READ_ATTACHED; /* producer is now attached */
+               return;
+       }
+
        /* Try to assign a server */
        if (srv_redispatch_connect(s) != 0) {
                /* We did not get a server. Either we queued the
@@ -2175,11 +2188,6 @@ struct task *process_session(struct task *t)
                                 */
                                s->req->cons->state = SI_ST_REQ; /* new connection requested */
                                s->req->cons->conn_retries = s->be->conn_retries;
-                               if (unlikely(obj_type(s->target) == OBJ_TYPE_APPLET)) {
-                                       s->req->cons->state = SI_ST_EST; /* connection established */
-                                       s->rep->flags |= CF_READ_ATTACHED; /* producer is now attached */
-                                       s->req->wex = TICK_ETERNITY;
-                               }
                        }
                }
                else {
@@ -2207,7 +2215,7 @@ struct task *process_session(struct task *t)
                                /* check for HTTP mode and proxy server_name_hdr_name != NULL */
                                if ((s->flags & SN_BE_ASSIGNED) &&
                                    (s->be->mode == PR_MODE_HTTP) &&
-                                   (s->be->server_id_hdr_name != NULL && s->target)) {
+                                   (s->be->server_id_hdr_name != NULL && objt_server(s->target))) {
                                        http_send_name_header(&s->txn, s->be, objt_server(s->target)->id);
                                }
                        }