]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: muxes: Use one callback function to shut a mux stream
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 18 Apr 2024 07:56:11 +0000 (09:56 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 19 Apr 2024 14:33:40 +0000 (16:33 +0200)
mux-ops .shutr and .shutw callback functions are merged into a unique
functions, called .shut. The shutdown mode is still passed as argument,
muxes are responsible to test it. Concretly, .shut() function of each mux is
now the content of the old .shutw() followed by the content of the old
.shutr().

include/haproxy/connection-t.h
src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/mux_pt.c
src/mux_quic.c
src/stconn.c

index bfaece231b27373c72cadca027a0b51824b685f9..342abba5d4bcae188c9f08025426b7de34b96514 100644 (file)
@@ -411,8 +411,7 @@ struct mux_ops {
        size_t (*done_fastfwd)(struct stconn *sc); /* Callback to terminate fast data forwarding */
        int (*fastfwd)(struct stconn *sc, unsigned int count, unsigned int flags); /* Callback to init fast data forwarding */
        int (*resume_fastfwd)(struct stconn *sc, unsigned int flags); /* Callback to resume fast data forwarding */
-       void (*shutr)(struct stconn *sc, enum se_shut_mode);     /* shutr function */
-       void (*shutw)(struct stconn *sc, enum se_shut_mode);     /* shutw function */
+       void (*shut)(struct stconn *sc, enum se_shut_mode);     /* shutdown function */
 
        int (*attach)(struct connection *conn, struct sedesc *, struct session *sess); /* attach a stconn to an outgoing connection */
        struct stconn *(*get_first_sc)(const struct connection *); /* retrieves any valid stconn from this connection */
index 3562663c443317370bf75b86b3abd5a6204c55a6..b914eadfeee91a44b44b4dab1b6f83026a51a4de 100644 (file)
@@ -3791,23 +3791,16 @@ struct task *fcgi_deferred_shut(struct task *t, void *ctx, unsigned int state)
        return NULL;
 }
 
-/* shutr() called by the stream connector (mux_ops.shutr) */
-static void fcgi_shutr(struct stconn *sc, enum se_shut_mode mode)
+static void fcgi_shut(struct stconn *sc, enum se_shut_mode mode)
 {
        struct fcgi_strm *fstrm = __sc_mux_strm(sc);
 
-       TRACE_POINT(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm);
+       TRACE_ENTER(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm);
+       if (mode & (SE_SHW_SILENT|SE_SHW_NORMAL))
+               fcgi_do_shutw(fstrm);
        if (mode & SE_SHR_RESET)
                fcgi_do_shutr(fstrm);
-}
-
-/* shutw() called by the stream connector (mux_ops.shutw) */
-static void fcgi_shutw(struct stconn *sc, enum se_shut_mode mode)
-{
-       struct fcgi_strm *fstrm = __sc_mux_strm(sc);
-
-       TRACE_POINT(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm);
-       fcgi_do_shutw(fstrm);
+       TRACE_LEAVE(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm);
 }
 
 /* Called from the upper layer, to subscribe <es> to events <event_type>. The
@@ -4261,8 +4254,7 @@ static const struct mux_ops mux_fcgi_ops = {
        .snd_buf       = fcgi_snd_buf,
        .subscribe     = fcgi_subscribe,
        .unsubscribe   = fcgi_unsubscribe,
-       .shutr         = fcgi_shutr,
-       .shutw         = fcgi_shutw,
+       .shut          = fcgi_shut,
        .ctl           = fcgi_ctl,
        .sctl           = fcgi_sctl,
        .show_fd       = fcgi_show_fd,
index 881fff77bb62a6be22fd31517d3c2f237133cd83..9e3feb9f7d6ca82d1631cb7185efa6a8fd0e0a19 100644 (file)
@@ -4291,25 +4291,12 @@ static void h1_detach(struct sedesc *sd)
        TRACE_LEAVE(H1_EV_STRM_END);
 }
 
-
-static void h1_shutr(struct stconn *sc, enum se_shut_mode mode)
-{
-       struct h1s *h1s = __sc_mux_strm(sc);
-       struct h1c *h1c;
-
-       if (!h1s)
-               return;
-       h1c = h1s->h1c;
-
-       TRACE_POINT(H1_EV_STRM_SHUT, h1c->conn, h1s, 0, (size_t[]){mode});
-}
-
-static void h1_shutw(struct stconn *sc, enum se_shut_mode mode)
+static void h1_shut(struct stconn *sc, enum se_shut_mode mode)
 {
        struct h1s *h1s = __sc_mux_strm(sc);
        struct h1c *h1c;
 
-       if (!h1s)
+       if (!h1s || !(mode & (SE_SHW_SILENT|SE_SHW_NORMAL)))
                return;
        h1c = h1s->h1c;
 
@@ -5517,8 +5504,7 @@ static const struct mux_ops mux_http_ops = {
        .resume_fastfwd = h1_resume_fastfwd,
        .subscribe   = h1_subscribe,
        .unsubscribe = h1_unsubscribe,
-       .shutr       = h1_shutr,
-       .shutw       = h1_shutw,
+       .shut        = h1_shut,
        .show_fd     = h1_show_fd,
        .show_sd     = h1_show_sd,
        .ctl         = h1_ctl,
@@ -5545,8 +5531,7 @@ static const struct mux_ops mux_h1_ops = {
        .resume_fastfwd = h1_resume_fastfwd,
        .subscribe   = h1_subscribe,
        .unsubscribe = h1_unsubscribe,
-       .shutr       = h1_shutr,
-       .shutw       = h1_shutw,
+       .shut        = h1_shut,
        .show_fd     = h1_show_fd,
        .show_sd     = h1_show_sd,
        .ctl         = h1_ctl,
index f76685593f6bb490733fe9913bd241f5897cf0f2..47b1f14cf37519a61f9ac433f813ad445f11d229 100644 (file)
@@ -5079,27 +5079,18 @@ struct task *h2_deferred_shut(struct task *t, void *ctx, unsigned int state)
        return t;
 }
 
-/* shutr() called by the stream connector (mux_ops.shutr) */
-static void h2_shutr(struct stconn *sc, enum se_shut_mode mode)
+static void h2_shut(struct stconn *sc, enum se_shut_mode mode)
 {
        struct h2s *h2s = __sc_mux_strm(sc);
 
        TRACE_ENTER(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s);
+       if (mode & (SE_SHW_SILENT|SE_SHW_NORMAL))
+               h2_do_shutw(h2s);
        if (mode & SE_SHR_RESET)
                h2_do_shutr(h2s);
        TRACE_LEAVE(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s);
 }
 
-/* shutw() called by the stream connector (mux_ops.shutw) */
-static void h2_shutw(struct stconn *sc, enum se_shut_mode mode)
-{
-       struct h2s *h2s = __sc_mux_strm(sc);
-
-       TRACE_ENTER(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s);
-       h2_do_shutw(h2s);
-       TRACE_LEAVE(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s);
-}
-
 /* Decode the payload of a HEADERS frame and produce the HTX request or response
  * depending on the connection's side. Returns a positive value on success, a
  * negative value on failure, or 0 if it couldn't proceed. May report connection
@@ -7746,8 +7737,7 @@ static const struct mux_ops h2_ops = {
        .destroy = h2_destroy,
        .avail_streams = h2_avail_streams,
        .used_streams = h2_used_streams,
-       .shutr = h2_shutr,
-       .shutw = h2_shutw,
+       .shut = h2_shut,
        .ctl = h2_ctl,
        .sctl = h2_sctl,
        .show_fd = h2_show_fd,
index 2e961abeb5320f4255f64a8f07eda515dfd6abb6..7aa97d79328aca5a5e4fc7f380dd2552b8794adc 100644 (file)
@@ -462,38 +462,30 @@ static int mux_pt_avail_streams(struct connection *conn)
        return 1 - mux_pt_used_streams(conn);
 }
 
-static void mux_pt_shutr(struct stconn *sc, enum se_shut_mode mode)
+static void mux_pt_shut(struct stconn *sc, enum se_shut_mode mode)
 {
        struct connection *conn = __sc_conn(sc);
        struct mux_pt_ctx *ctx = conn->ctx;
 
        TRACE_ENTER(PT_EV_STRM_SHUT, conn, sc);
+       if (mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) {
+               if (conn_xprt_ready(conn) && conn->xprt->shutw)
+                       conn->xprt->shutw(conn, conn->xprt_ctx, (mode & SE_SHW_NORMAL));
+               if (conn->flags & CO_FL_SOCK_RD_SH)
+                       conn_full_close(conn);
+               else
+                       conn_sock_shutw(conn, (mode & SE_SHW_NORMAL));
+       }
 
-       se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
-       if (conn_xprt_ready(conn) && conn->xprt->shutr)
-               conn->xprt->shutr(conn, conn->xprt_ctx,
-                   (mode & SE_SHR_DRAIN));
-       else if (mode & SE_SHR_DRAIN)
-               conn_ctrl_drain(conn);
-       if (conn->flags & CO_FL_SOCK_WR_SH)
-               conn_full_close(conn);
-
-       TRACE_LEAVE(PT_EV_STRM_SHUT, conn, sc);
-}
-
-static void mux_pt_shutw(struct stconn *sc, enum se_shut_mode mode)
-{
-       struct connection *conn = __sc_conn(sc);
-
-       TRACE_ENTER(PT_EV_STRM_SHUT, conn, sc);
-
-       if (conn_xprt_ready(conn) && conn->xprt->shutw)
-               conn->xprt->shutw(conn, conn->xprt_ctx,
-                   (mode & SE_SHW_NORMAL));
-       if (!(conn->flags & CO_FL_SOCK_RD_SH))
-               conn_sock_shutw(conn, (mode & SE_SHW_NORMAL));
-       else
-               conn_full_close(conn);
+       if (mode & (SE_SHR_RESET|SE_SHR_DRAIN)) {
+               se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
+               if (conn_xprt_ready(conn) && conn->xprt->shutr)
+                       conn->xprt->shutr(conn, conn->xprt_ctx, (mode & SE_SHR_DRAIN));
+               else if (mode & SE_SHR_DRAIN)
+                       conn_ctrl_drain(conn);
+               if (conn->flags & CO_FL_SOCK_WR_SH)
+                       conn_full_close(conn);
+       }
 
        TRACE_LEAVE(PT_EV_STRM_SHUT, conn, sc);
 }
@@ -865,8 +857,7 @@ const struct mux_ops mux_tcp_ops = {
        .destroy = mux_pt_destroy_meth,
        .ctl = mux_pt_ctl,
        .sctl = mux_pt_sctl,
-       .shutr = mux_pt_shutr,
-       .shutw = mux_pt_shutw,
+       .shut = mux_pt_shut,
        .flags = MX_FL_NONE,
        .name = "PASS",
 };
@@ -891,8 +882,7 @@ const struct mux_ops mux_pt_ops = {
        .destroy = mux_pt_destroy_meth,
        .ctl = mux_pt_ctl,
        .sctl = mux_pt_sctl,
-       .shutr = mux_pt_shutr,
-       .shutw = mux_pt_shutw,
+       .shut = mux_pt_shut,
        .flags = MX_FL_NONE|MX_FL_NO_UPG,
        .name = "PASS",
 };
index 4e803838078cec98dc3c5d0515a15c1b89695fff..883ef01bb2661edeec5b49ebbf8e7434bcd24065 100644 (file)
@@ -3095,11 +3095,14 @@ static int qmux_wake(struct connection *conn)
        return 1;
 }
 
-static void qmux_strm_shutw(struct stconn *sc, enum se_shut_mode mode)
+static void qmux_strm_shut(struct stconn *sc, enum se_shut_mode mode)
 {
        struct qcs *qcs = __sc_mux_strm(sc);
        struct qcc *qcc = qcs->qcc;
 
+       if (!(mode & (SE_SHW_SILENT|SE_SHW_NORMAL)))
+               return;
+
        TRACE_ENTER(QMUX_EV_STRM_SHUT, qcc->conn, qcs);
 
        /* Early closure reported if QC_SF_FIN_STREAM not yet set. */
@@ -3182,7 +3185,7 @@ static const struct mux_ops qmux_ops = {
        .subscribe   = qmux_strm_subscribe,
        .unsubscribe = qmux_strm_unsubscribe,
        .wake        = qmux_wake,
-       .shutw       = qmux_strm_shutw,
+       .shut       = qmux_strm_shut,
        .sctl        = qmux_sctl,
        .show_sd     = qmux_strm_show_sd,
        .flags = MX_FL_HTX|MX_FL_NO_UPG|MX_FL_FRAMED,
index ca878436ae2bd4cdd8f11ed79521c2fb22f87856..930b92b1bd3f95d15400eeb43f875e325110b942 100644 (file)
@@ -140,17 +140,19 @@ void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode)
 {
        if (se_fl_test(sedesc, SE_FL_T_MUX)) {
                const struct mux_ops *mux = (sedesc->conn ? sedesc->conn->mux : NULL);
+               unsigned int flags = 0;
 
-               if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(sedesc, SE_FL_SHW)) {
-                       if (mux && mux->shutw)
-                               mux->shutw(sedesc->sc, mode);
-                       se_fl_set(sedesc, (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
-               }
+               if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(sedesc, SE_FL_SHW))
+                       flags |= (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS;
+
+
+               if ((mode & (SE_SHR_RESET|SE_SHR_DRAIN)) && !se_fl_test(sedesc, SE_FL_SHR))
+                       flags |= (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR;
 
-               if ((mode & (SE_SHR_RESET|SE_SHR_DRAIN)) && !se_fl_test(sedesc, SE_FL_SHR)) {
-                       if (mux && mux->shutr)
-                               mux->shutr(sedesc->sc, mode);
-                       se_fl_set(sedesc, (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
+               if (flags) {
+                       if (mux && mux->shut)
+                               mux->shut(sedesc->sc, mode);
+                       se_fl_set(sedesc, flags);
                }
        }
        else if (se_fl_test(sedesc, SE_FL_T_APPLET)) {