]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stconn: Use only one SC function to shut connection endpoints
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 16 Apr 2024 15:42:38 +0000 (17:42 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 19 Apr 2024 14:25:06 +0000 (16:25 +0200)
The SC API to perform shutdowns on connection endpoints was unified to have
only one function, sc_conn_shut(), with read/write shut modes passed
explicitly. It means sc_conn_shutr() and sc_conn_shutw() were removed. The
next step is to do the same at the mux level.

include/haproxy/stconn.h
src/check.c
src/stconn.c

index 039055c9a6e1535d9ff4b959bbf09971e895a8e3..e2409011c6792ba60c34bb638eb48d8d68467e9c 100644 (file)
@@ -318,52 +318,25 @@ static inline const char *sc_get_data_name(const struct stconn *sc)
        return sc->app_ops->name;
 }
 
-/* shut read */
-static inline void sc_conn_shutr(struct stconn *sc, enum se_shut_mode mode)
+static inline void sc_conn_shut(struct stconn *sc, enum se_shut_mode mode)
 {
        const struct mux_ops *mux;
 
        BUG_ON(!sc_conn(sc));
 
-       if (sc_ep_test(sc, SE_FL_SHR))
-               return;
-
-       /* clean data-layer shutdown */
        mux = sc_mux_ops(sc);
-       if (mux && mux->shutr)
-               mux->shutr(sc, mode);
-       sc_ep_set(sc, (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
-}
-
-/* shut write */
-static inline void sc_conn_shutw(struct stconn *sc, enum se_shut_mode mode)
-{
-       const struct mux_ops *mux;
 
-       BUG_ON(!sc_conn(sc));
-
-       if (sc_ep_test(sc, SE_FL_SHW))
-               return;
-
-       /* clean data-layer shutdown */
-       mux = sc_mux_ops(sc);
-       if (mux && mux->shutw)
-               mux->shutw(sc, mode);
-       sc_ep_set(sc, (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
-}
-
-/* completely close a stream connector (but do not detach it) */
-static inline void sc_conn_shut(struct stconn *sc)
-{
-       sc_conn_shutw(sc, SE_SHW_SILENT);
-       sc_conn_shutr(sc, SE_SHR_RESET);
-}
+       if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !sc_ep_test(sc, SE_FL_SHW)) {
+               if (mux && mux->shutw)
+                       mux->shutw(sc, mode);
+               sc_ep_set(sc, (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
+       }
 
-/* completely close a stream connector after draining possibly pending data (but do not detach it) */
-static inline void sc_conn_drain_and_shut(struct stconn *sc)
-{
-       sc_conn_shutw(sc, SE_SHW_SILENT);
-       sc_conn_shutr(sc, SE_SHR_DRAIN);
+       if ((mode & (SE_SHR_RESET|SE_SHR_DRAIN)) && !sc_ep_test(sc, SE_FL_SHR)) {
+               if (mux && mux->shutr)
+                       mux->shutr(sc, mode);
+               sc_ep_set(sc, (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
+       }
 }
 
 /* Returns non-zero if the stream connector's Rx path is blocked because of
@@ -572,7 +545,7 @@ static inline size_t se_done_ff(struct sedesc *se)
                                sc_ep_report_blocked_send(se->sc, 0);
                        if (se->iobuf.flags & IOBUF_FL_FF_BLOCKED) {
                                sc_ep_report_blocked_send(se->sc, 0);
-                               
+
                                if (!(se->sc->wait_event.events & SUB_RETRY_SEND)) {
                                        /* The SC must be subs for send to be notify when some
                                         * space is made
index 2753c9324ba587dd67becc80636156f95468b30b..6a37ad887147f2771616d6d79b21229ad6360d21 100644 (file)
@@ -1382,7 +1382,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
                 * as a failed response coupled with "observe layer7" caused the
                 * server state to be suddenly changed.
                 */
-               sc_conn_drain_and_shut(sc);
+               sc_conn_shut(sc, SE_SHR_DRAIN|SE_SHW_SILENT);
        }
 
        if (sc) {
index 5e4a0025dd0a5f01fd131449771d8454a729f305..7eea66fb5825a3c965975e396a9b33ff7cfda403 100644 (file)
@@ -700,7 +700,7 @@ static void sc_app_abort_conn(struct stconn *sc)
                return;
 
        if (sc->flags & SC_FL_SHUT_DONE) {
-               sc_conn_shut(sc);
+               sc_conn_shut(sc, SE_SHR_RESET|SE_SHW_SILENT);
                sc->state = SC_ST_DIS;
                if (sc->flags & SC_FL_ISBACK)
                        __sc_strm(sc)->conn_exp = TICK_ETERNITY;
@@ -742,12 +742,11 @@ static void sc_app_shut_conn(struct stconn *sc)
                 * no risk so we close both sides immediately.
                 */
                if (!(sc->flags & (SC_FL_NOLINGER|SC_FL_EOS|SC_FL_ABRT_DONE)) && !(ic->flags & CF_DONT_READ)) {
-                       sc_conn_shutw(sc, SE_SHW_NORMAL);
+                       sc_conn_shut(sc, SE_SHW_NORMAL);
                        return;
                }
 
-               sc_conn_shutw(sc, (sc->flags & SC_FL_NOLINGER) ? SE_SHW_SILENT : SE_SHW_NORMAL);
-               sc_conn_shut(sc);
+               sc_conn_shut(sc, SE_SHR_RESET|((sc->flags & SC_FL_NOLINGER) ? SE_SHW_SILENT : SE_SHW_NORMAL));
                sc->state = SC_ST_DIS;
                break;
 
@@ -755,7 +754,7 @@ static void sc_app_shut_conn(struct stconn *sc)
                /* we may have to close a pending connection, and mark the
                 * response buffer as abort
                 */
-               sc_conn_shut(sc);
+               sc_conn_shut(sc, SE_SHR_RESET|SE_SHW_SILENT);
                sc->state = SC_ST_DIS;
                break;
        case SC_ST_CER:
@@ -1203,7 +1202,7 @@ static void sc_conn_eos(struct stconn *sc)
 
  do_close:
        /* OK we completely close the socket here just as if we went through sc_shut[rw]() */
-       sc_conn_shut(sc);
+       sc_conn_shut(sc, SE_SHR_RESET|SE_SHW_SILENT);
 
        sc->flags &= ~SC_FL_SHUT_WANTED;
        sc->flags |= SC_FL_SHUT_DONE;