]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream: don't rely on the session's listener anymore in stream_new()
authorWilly Tarreau <w@1wt.eu>
Sun, 5 Apr 2015 22:25:48 +0000 (00:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Apr 2015 09:37:35 +0000 (11:37 +0200)
When the stream is instanciated from an applet, it doesn't necessarily
have a listener. The listener was sparsely used there, just to retrieve
the task function, update the listeners' stats, and set the analysers
and default target, both of which are often zero from applets. Thus
these elements are now initialized with default values that the caller
is free to change if desired.

src/peers.c
src/session.c
src/stream.c

index 4899ee7a0a5dfaf4e38792f92e612e02ff3cbf0b..d1a06d801def2bf5960f90844ec779f714f7e157 100644 (file)
@@ -1166,17 +1166,8 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
        conn->target = s->target = &s->be->obj_type;
        memcpy(&conn->addr.to, &peer->addr, sizeof(conn->addr.to));
        s->do_log = NULL;
-
-       /* default error reporting function, may be changed by analysers */
-       s->srv_error = default_srv_error;
        s->uniq_id = 0;
 
-       /* note: this should not happen anymore since there's always at least the switching rules */
-       if (!s->req.analysers) {
-               channel_auto_connect(&s->req);/* don't wait to establish connection */
-               channel_auto_close(&s->req);  /* let the producer forward close requests */
-       }
-
        s->req.rto = s->sess->fe->timeout.client;
        s->req.wto = s->be->timeout.server;
        s->res.rto = s->be->timeout.server;
index 247e4927dcb41cb044ca7805d8c364685e14de6c..6ae2592fe1b049127da978f12abbeb3436a3ea73 100644 (file)
@@ -88,6 +88,7 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
        struct connection *cli_conn;
        struct proxy *p = l->frontend;
        struct session *sess;
+       struct stream *strm;
        struct task *t;
        int ret;
 
@@ -224,9 +225,15 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
 
        /* OK let's complete stream initialization since there is no handshake */
        cli_conn->flags |= CO_FL_CONNECTED;
-       if (stream_new(sess, t))
-               return 1;
+       strm = stream_new(sess, t);
+       if (!strm)
+               goto out_free_task;
+
+       strm->target        = sess->listener->default_target;
+       strm->req.analysers = sess->listener->analysers;
+       return 1;
 
+ out_free_task:
        task_free(t);
  out_free_sess:
        p->feconn--;
@@ -369,12 +376,22 @@ static int conn_complete_session(struct connection *conn)
 {
        struct task *task = conn->owner;
        struct session *sess = task->context;
+       struct stream *strm;
 
-       if (!(conn->flags & CO_FL_ERROR) && (stream_new(sess, task) != NULL)) {
-               conn->flags &= ~CO_FL_INIT_DATA;
-               return 0;
-       }
+       if (conn->flags & CO_FL_ERROR)
+               goto fail;
+
+       task->process = sess->listener->handler;
+       strm = stream_new(sess, task);
+       if (!strm)
+               goto fail;
+
+       strm->target        = sess->listener->default_target;
+       strm->req.analysers = sess->listener->analysers;
+       conn->flags &= ~CO_FL_INIT_DATA;
+       return 0;
 
+ fail:
        session_kill_embryonic(sess);
        return -1;
 }
index dca1c88842b722c5933afc62d06f03c8efe26f8e..863075b0ba4c9a722cf4b3742aed05bd1d69c1de 100644 (file)
@@ -61,11 +61,12 @@ struct list buffer_wq = LIST_HEAD_INIT(buffer_wq);
  * be called with an embryonic session. It returns the pointer to the newly
  * created stream, or NULL in case of fatal error. For now the client-side
  * end point is taken from the session's origin, which must be valid.
+ * The task's context is set to the new stream, and its function is set to
+ * process_stream(). Target and analysers are null.
  */
 struct stream *stream_new(struct session *sess, struct task *t)
 {
        struct stream *s;
-       struct listener *l = sess->listener;
        struct connection *conn = objt_conn(sess->origin);
        struct appctx *appctx   = objt_appctx(sess->origin);
        int i;
@@ -121,7 +122,7 @@ struct stream *stream_new(struct session *sess, struct task *t)
        s->unique_id = NULL;
 
        s->task = t;
-       t->process = l->handler;
+       t->process = process_stream;
        t->context = s;
        t->expire = TICK_ETERNITY;
 
@@ -136,7 +137,8 @@ struct stream *stream_new(struct session *sess, struct task *t)
        s->res_cap = NULL;
 
        /* Let's count a stream now */
-       proxy_inc_fe_sess_ctr(l, sess->fe);
+       if (conn)
+               proxy_inc_fe_sess_ctr(sess->listener, sess->fe);
 
        for (i = 0; i < MAX_SESS_STKCTR; i++) {
                void *ptr;
@@ -178,7 +180,7 @@ struct stream *stream_new(struct session *sess, struct task *t)
                s->si[1].flags |= SI_FL_INDEP_STR;
 
        stream_init_srv_conn(s);
-       s->target = l->default_target; /* used by peers and CLI */
+       s->target = NULL;
        s->pend_pos = NULL;
 
        /* init store persistence */
@@ -186,14 +188,9 @@ struct stream *stream_new(struct session *sess, struct task *t)
 
        channel_init(&s->req);
        s->req.flags |= CF_READ_ATTACHED; /* the producer is already connected */
-
-       /* activate default analysers enabled for this listener */
-       s->req.analysers = l->analysers;
-
-       if (!s->req.analysers) {
-               channel_auto_connect(&s->req);  /* don't wait to establish connection */
-               channel_auto_close(&s->req);    /* let the producer forward close requests */
-       }
+       s->req.analysers = 0;
+       channel_auto_connect(&s->req);  /* don't wait to establish connection */
+       channel_auto_close(&s->req);    /* let the producer forward close requests */
 
        s->req.rto = sess->fe->timeout.client;
        s->req.wto = TICK_ETERNITY;