]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: conn_stream: merge cs_new_from_{mux,applet} into cs_new_from_endp()
authorWilly Tarreau <w@1wt.eu>
Wed, 11 May 2022 14:11:24 +0000 (16:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 13 May 2022 12:28:48 +0000 (14:28 +0200)
The two functions became exact copies since there's no more special case
for the appctx owner. Let's merge them into a single one, that simplifies
the code.

12 files changed:
include/haproxy/conn_stream.h
include/haproxy/mux_quic.h
src/conn_stream.c
src/dns.c
src/flt_spoe.c
src/hlua.c
src/http_client.c
src/mux_h1.c
src/mux_h2.c
src/mux_pt.c
src/peers.c
src/sink.c

index ae2d9f0b942200422707ac05fa9374a25dad650d..4a567a5dc8cec1cedb3ee87babfa3d03b7c2e91e 100644 (file)
@@ -38,8 +38,7 @@ struct check;
 struct cs_endpoint *cs_endpoint_new();
 void cs_endpoint_free(struct cs_endpoint *endp);
 
-struct conn_stream *cs_new_from_mux(struct cs_endpoint *endp, struct session *sess, struct buffer *input);
-struct conn_stream *cs_new_from_applet(struct cs_endpoint *endp, struct session *sess, struct buffer *input);
+struct conn_stream *cs_new_from_endp(struct cs_endpoint *endp, struct session *sess, struct buffer *input);
 struct conn_stream *cs_new_from_strm(struct stream *strm, unsigned int flags);
 struct conn_stream *cs_new_from_check(struct check *check, unsigned int flags);
 void cs_free(struct conn_stream *cs);
index 0086909fb135503c259a0fc241da3a074133b010..08ff9a35874125e3deaa09fda9a1ae80176d0b48 100644 (file)
@@ -91,7 +91,7 @@ static inline int qcc_install_app_ops(struct qcc *qcc,
 
 static inline struct conn_stream *qc_attach_cs(struct qcs *qcs, struct buffer *buf)
 {
-       if (!cs_new_from_mux(qcs->endp, qcs->qcc->conn->owner, buf))
+       if (!cs_new_from_endp(qcs->endp, qcs->qcc->conn->owner, buf))
                return NULL;
 
        ++qcs->qcc->nb_cs;
index c13a2a1d1a83305d4562a46b2077a2049075e313..a37b4637ee10bd8f2c1adb872fa62e81186bf08d 100644 (file)
@@ -156,27 +156,7 @@ static struct conn_stream *cs_new(struct cs_endpoint *endp)
  * defined. It returns NULL on error. On success, the new conn-stream is
  * returned. In this case, CS_EP_ORPHAN flag is removed.
  */
-struct conn_stream *cs_new_from_mux(struct cs_endpoint *endp, struct session *sess, struct buffer *input)
-{
-       struct conn_stream *cs;
-
-       cs = cs_new(endp);
-       if (unlikely(!cs))
-               return NULL;
-       if (unlikely(!stream_new(sess, cs, input))) {
-               pool_free(pool_head_connstream, cs);
-               cs = NULL;
-       }
-       endp->flags &= ~CS_EP_ORPHAN;
-       return cs;
-}
-
-/* Creates a new conn-stream and its associated stream from an applet. <endp>
- * must be defined. It returns NULL on error. On success, the new conn-stream is
- * returned. In this case, CS_EP_ORPHAN flag is removed. The created CS is used
- * to set the appctx owner.
- */
-struct conn_stream *cs_new_from_applet(struct cs_endpoint *endp, struct session *sess, struct buffer *input)
+struct conn_stream *cs_new_from_endp(struct cs_endpoint *endp, struct session *sess, struct buffer *input)
 {
        struct conn_stream *cs;
 
index 35ff61a6ad8141f30480efea7e3a265d7fd75955..bfd22c1b9e2b9f789c363d7e806d5dc99a0ab34f 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -938,7 +938,7 @@ static struct appctx *dns_session_create(struct dns_session *ds)
        if (!sockaddr_alloc(&addr, &ds->dss->srv->addr, sizeof(ds->dss->srv->addr)))
                goto out_free_sess;
 
-       cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
+       cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
                ha_alert("Failed to initialize stream in dns_session_create().\n");
                goto out_free_addr;
index 59db4280e0672703a5a6454a353fbad89859fd08..030ba9c8af061e5c8997a4bfebff7d42264d0b56 100644 (file)
@@ -2026,7 +2026,7 @@ spoe_create_appctx(struct spoe_config *conf)
        if (!sess)
                goto out_free_spoe;
 
-       cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
+       cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs)
                goto out_free_sess;
 
index 91a9f7cad244f9182c6047ac196950fc35497d1b..ef967a51548f8fdc798d02e6a8d6e4b64f3b3b23 100644 (file)
@@ -3004,7 +3004,7 @@ __LJMP static int hlua_socket_new(lua_State *L)
                goto out_fail_appctx;
        }
 
-       cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
+       cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
                hlua_pusherror(L, "socket: out of memory");
                goto out_fail_sess;
index 1efb48496d183418891b707a18baf240185aae4e..4daacea1da1e8e18383cd606753c7124434b6a7d 100644 (file)
@@ -607,7 +607,7 @@ struct appctx *httpclient_start(struct httpclient *hc)
        if (!sockaddr_alloc(&addr, ss_dst, sizeof(*ss_dst)))
                goto out_free_sess;
 
-       cs = cs_new_from_applet(appctx->endp, sess, &hc->req.buf);
+       cs = cs_new_from_endp(appctx->endp, sess, &hc->req.buf);
        if (!cs) {
                ha_alert("httpclient: Failed to initialize stream %s:%d.\n", __FUNCTION__, __LINE__);
                goto out_free_addr;
index e41e6ef4ce6234987ad166d568a996fa3a9b5cc7..c5f0b03201705a40874e08dfa4d83e72a82ac186 100644 (file)
@@ -726,7 +726,7 @@ static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input)
        if (h1s->req.flags & H1_MF_UPG_WEBSOCKET)
                h1s->endp->flags |= CS_EP_WEBSOCKET;
 
-       if (!cs_new_from_mux(h1s->endp, h1c->conn->owner, input)) {
+       if (!cs_new_from_endp(h1s->endp, h1c->conn->owner, input)) {
                TRACE_ERROR("CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1c->conn, h1s);
                goto err;
        }
index 6cb2334ba7e4a9d260c4b7f46a8d0d13223072ba..9ed272768cf96ffabee0ed13dc2538f8e1a10f68 100644 (file)
@@ -1629,7 +1629,7 @@ static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *in
         */
        sess->t_idle = tv_ms_elapsed(&sess->tv_accept, &now) - sess->t_handshake;
 
-       if (!cs_new_from_mux(h2s->endp, sess, input))
+       if (!cs_new_from_endp(h2s->endp, sess, input))
                goto out_close;
 
        h2c->nb_cs++;
index fa92ed6aac26bb2c2f71ed05b611d04605bfbbf5..821f558ba651400fdd88805cdf4b234d16c1e6c2 100644 (file)
@@ -302,7 +302,7 @@ static int mux_pt_init(struct connection *conn, struct proxy *prx, struct sessio
                ctx->endp->ctx = conn;
                ctx->endp->flags |= (CS_EP_T_MUX|CS_EP_ORPHAN);
 
-               cs = cs_new_from_mux(ctx->endp, sess, input);
+               cs = cs_new_from_endp(ctx->endp, sess, input);
                if (!cs) {
                        TRACE_ERROR("CS allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn);
                        goto fail_free_endp;
index f521b55ea7ce4cc185a64c7d82c6f30d4c107ae8..58f771b97df208b510872d4900ef1b2107c88ced 100644 (file)
@@ -3194,7 +3194,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
        if (!sockaddr_alloc(&addr, &peer->addr, sizeof(peer->addr)))
                goto out_free_sess;
 
-       cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
+       cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
                ha_alert("Failed to initialize stream in peer_session_create().\n");
                goto out_free_addr;
index 3dc4a4df2ec1cb4b9bec93625975271715ab841b..c52afc68dcae10ef4c2c8da3cf7f44d72deec214 100644 (file)
@@ -654,7 +654,7 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink
        if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr)))
                goto out_free_sess;
 
-       cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
+       cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
                ha_alert("Failed to initialize stream in sink_forward_session_create().\n");
                goto out_free_addr;