]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: Slightly rework stream_new to separate CS/SI initialization
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 23 Dec 2021 11:06:45 +0000 (12:06 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Feb 2022 10:00:02 +0000 (11:00 +0100)
It is just a minor reforctoring of stream_new() function to ease next
changes. Especially to move the SI from the stream to the conn-stream.

src/stream.c

index 8ceb9bc1d2cc91211380f4a385b61f156f1da61d..774c74cea28e00563c9d4f25c36c6024b3c39fa3 100644 (file)
@@ -393,8 +393,6 @@ struct stream *stream_new(struct session *sess, struct conn_stream *cs, struct b
        memcpy(s->stkctr, sess->stkctr, sizeof(s->stkctr));
 
        s->sess = sess;
-       s->si[0].flags = SI_FL_NONE;
-       s->si[1].flags = SI_FL_ISBACK;
 
        s->stream_epoch = _HA_ATOMIC_LOAD(&stream_epoch);
        s->uniq_id = _HA_ATOMIC_FETCH_ADD(&global.req_count, 1);
@@ -436,19 +434,35 @@ struct stream *stream_new(struct session *sess, struct conn_stream *cs, struct b
        vars_init_head(&s->vars_txn,    SCOPE_TXN);
        vars_init_head(&s->vars_reqres, SCOPE_REQ);
 
+        /* Set SF_HTX flag for HTTP frontends. */
+       if (sess->fe->mode == PR_MODE_HTTP)
+               s->flags |= SF_HTX;
+
+       cs->app = &s->obj_type;
        s->csf = cs;
+       s->csb = cs_new(NULL, NULL, &s->obj_type, &s->si[1], NULL);
+       if (!s->csb)
+               goto out_fail_alloc_cs;
 
-       /* this part should be common with other protocols */
+       s->si[0].flags = SI_FL_NONE;
        if (si_reset(&s->si[0]) < 0)
-               goto out_fail_alloc;
+               goto out_fail_reset_si0;
+       si_attach_cs(&s->si[0], s->csf);
        si_set_state(&s->si[0], SI_ST_EST);
        s->si[0].hcto = sess->fe->timeout.clientfin;
 
-        /* Set SF_HTX flag for HTTP frontends. */
-       if (sess->fe->mode == PR_MODE_HTTP)
-               s->flags |= SF_HTX;
+       if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
+               s->si[0].flags |= SI_FL_INDEP_STR;
+
+       s->si[1].flags = SI_FL_ISBACK;
+       if (si_reset(&s->si[1]) < 0)
+               goto out_fail_reset_si1;
+       si_attach_cs(&s->si[1], s->csb);
+       s->si[1].hcto = TICK_ETERNITY;
+
+       if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
+               s->si[1].flags |= SI_FL_INDEP_STR;
 
-       si_attach_cs(&s->si[0], cs);
        if (cs->flags & CS_FL_WEBSOCKET)
                s->flags |= SF_WEBSOCKET;
        if (cs_conn(cs)) {
@@ -462,25 +476,6 @@ struct stream *stream_new(struct session *sess, struct conn_stream *cs, struct b
                }
        }
 
-
-       if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
-               s->si[0].flags |= SI_FL_INDEP_STR;
-
-       /* pre-initialize the other side's stream interface to an INIT state. The
-        * callbacks will be initialized before attempting to connect.
-        */
-       if (si_reset(&s->si[1]) < 0)
-               goto out_fail_alloc_si1;
-       s->si[1].hcto = TICK_ETERNITY;
-
-       if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
-               s->si[1].flags |= SI_FL_INDEP_STR;
-
-       s->csb = cs_new(NULL, NULL, &s->obj_type, &s->si[1], NULL);
-       if (!s->csb)
-               goto out_fail_alloc_cs;
-       s->si[1].cs = s->csb;
-
        stream_init_srv_conn(s);
        s->target = sess->listener ? sess->listener->default_target : NULL;
 
@@ -576,13 +571,14 @@ struct stream *stream_new(struct session *sess, struct conn_stream *cs, struct b
        /* Error unrolling */
  out_fail_accept:
        flt_stream_release(s, 0);
-       task_destroy(t);
        tasklet_free(s->si[1].wait_event.tasklet);
        LIST_DELETE(&s->list);
- out_fail_alloc_cs:
-       si_release_endpoint(&s->si[1]);
- out_fail_alloc_si1:
+ out_fail_reset_si1:
        tasklet_free(s->si[0].wait_event.tasklet);
+ out_fail_reset_si0:
+       si_release_endpoint(&s->si[1]);
+ out_fail_alloc_cs:
+       task_destroy(t);
  out_fail_alloc:
        pool_free(pool_head_stream, s);
        DBG_TRACE_DEVEL("leaving on error", STRM_EV_STRM_NEW|STRM_EV_STRM_ERR);