MEDIUM: conn-stream: Be prepared to use an appctx as conn-stream endpoint
To be able to use an appctx as conn-stream endpoint, the connection is no
longer stored as is in the conn-stream. The obj-type is used instead.
diff --git a/src/conn_stream.c b/src/conn_stream.c
index 43e6fd0..7b53ecc 100644
--- a/src/conn_stream.c
+++ b/src/conn_stream.c
@@ -19,30 +19,17 @@
DECLARE_POOL(pool_head_connstream, "conn_stream", sizeof(struct conn_stream));
-/* Tries to allocate a new conn_stream and initialize its main fields. If
- * <conn> is NULL, then a new connection is allocated on the fly, initialized,
- * and assigned to cs->conn ; this connection will then have to be released
- * using pool_free() or conn_free(). The conn_stream is initialized and added
- * to the mux's stream list on success, then returned. On failure, nothing is
- * allocated and NULL is returned.
+/* Tries to allocate a new conn_stream and initialize its main fields. On
+ * failure, nothing is allocated and NULL is returned.
*/
-struct conn_stream *cs_new(struct connection *conn, void *target)
+struct conn_stream *cs_new(enum obj_type *endp)
{
struct conn_stream *cs;
cs = pool_alloc(pool_head_connstream);
if (unlikely(!cs))
return NULL;
-
- if (!conn) {
- conn = conn_new(target);
- if (unlikely(!conn)) {
- cs_free(cs);
- return NULL;
- }
- }
-
- cs_init(cs, conn);
+ cs_init(cs, endp);
return cs;
}
diff --git a/src/h3.c b/src/h3.c
index 31b9c00..bda2a46 100644
--- a/src/h3.c
+++ b/src/h3.c
@@ -176,7 +176,7 @@
if (fin)
htx->flags |= HTX_FL_EOM;
- cs = cs_new(qcs->qcc->conn, qcs->qcc->conn->target);
+ cs = cs_new(qcs->qcc->conn->obj_type);
if (!cs)
return 1;
diff --git a/src/hq_interop.c b/src/hq_interop.c
index 0e2c6cd..376779d 100644
--- a/src/hq_interop.c
+++ b/src/hq_interop.c
@@ -72,7 +72,7 @@
htx_add_endof(htx, HTX_BLK_EOH);
htx_to_buf(htx, &htx_buf);
- cs = cs_new(qcs->qcc->conn, qcs->qcc->conn->target);
+ cs = cs_new(&qcs->qcc->conn->obj_type);
if (!cs)
return -1;
diff --git a/src/mux_h1.c b/src/mux_h1.c
index 81b5cce..cc53364 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -678,12 +678,13 @@
* success or NULL on error. */
static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input)
{
+ struct h1c *h1c = h1s->h1c;
struct conn_stream *cs;
- TRACE_ENTER(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
- cs = cs_new(h1s->h1c->conn, h1s->h1c->conn->target);
+ TRACE_ENTER(H1_EV_STRM_NEW, h1c->conn, h1s);
+ cs = cs_new(&h1c->conn->obj_type);
if (!cs) {
- TRACE_ERROR("CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
+ TRACE_ERROR("CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1c->conn, h1s);
goto err;
}
h1s->cs = cs;
@@ -696,21 +697,21 @@
cs->flags |= CS_FL_WEBSOCKET;
if (stream_create_from_cs(cs, input) < 0) {
- TRACE_DEVEL("leaving on stream creation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
+ TRACE_DEVEL("leaving on stream creation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1c->conn, h1s);
goto err;
}
- HA_ATOMIC_INC(&h1s->h1c->px_counters->open_streams);
- HA_ATOMIC_INC(&h1s->h1c->px_counters->total_streams);
+ HA_ATOMIC_INC(&h1c->px_counters->open_streams);
+ HA_ATOMIC_INC(&h1c->px_counters->total_streams);
- h1s->h1c->flags = (h1s->h1c->flags & ~H1C_F_ST_EMBRYONIC) | H1C_F_ST_ATTACHED | H1C_F_ST_READY;
- TRACE_LEAVE(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
+ h1c->flags = (h1c->flags & ~H1C_F_ST_EMBRYONIC) | H1C_F_ST_ATTACHED | H1C_F_ST_READY;
+ TRACE_LEAVE(H1_EV_STRM_NEW, h1c->conn, h1s);
return cs;
err:
cs_free(cs);
h1s->cs = NULL;
- TRACE_DEVEL("leaving on error", H1_EV_STRM_NEW|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
+ TRACE_DEVEL("leaving on error", H1_EV_STRM_NEW|H1_EV_STRM_ERR, h1c->conn, h1s);
return NULL;
}
diff --git a/src/mux_h2.c b/src/mux_h2.c
index c466332..d142793 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -1529,7 +1529,7 @@
if (!h2s)
goto out;
- cs = cs_new(h2c->conn, h2c->conn->target);
+ cs = cs_new(&h2c->conn->obj_type);
if (!cs)
goto out_close;
diff --git a/src/mux_pt.c b/src/mux_pt.c
index 1f8b4dc..e048a49 100644
--- a/src/mux_pt.c
+++ b/src/mux_pt.c
@@ -291,7 +291,7 @@
ctx->conn = conn;
if (!cs) {
- cs = cs_new(conn, conn->target);
+ cs = cs_new(&conn->obj_type);
if (!cs) {
TRACE_ERROR("CS allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn);
goto fail_free_ctx;
diff --git a/src/tcpcheck.c b/src/tcpcheck.c
index bf7e5c9..5fec53e 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -1091,8 +1091,10 @@
check_release_buf(check, &check->bo);
/* No connection, prepare a new one */
- cs = cs_new(NULL, (s ? &s->obj_type : &proxy->obj_type));
- if (!cs) {
+ conn = conn_new((s ? &s->obj_type : &proxy->obj_type));
+ if (conn)
+ cs = cs_new(&conn->obj_type);
+ if (!conn || !cs) {
chunk_printf(&trash, "TCPCHK error allocating connection at step %d",
tcpcheck_get_step_id(check, rule));
if (rule->comment)
@@ -1100,13 +1102,14 @@
set_server_check_status(check, HCHK_STATUS_SOCKERR, trash.area);
ret = TCPCHK_EVAL_STOP;
TRACE_ERROR("conn-stream allocation error", CHK_EV_TCPCHK_CONN|CHK_EV_TCPCHK_ERR, check);
+ if (conn)
+ conn_free(conn);
goto out;
}
tasklet_set_tid(check->wait_list.tasklet, tid);
check->cs = cs;
- conn = cs->conn;
conn_set_owner(conn, check->sess, NULL);
/* Maybe there were an older connection we were waiting on */