]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stconn: use a single function to know if SC may send to SE
authorWilly Tarreau <w@1wt.eu>
Tue, 24 May 2022 06:49:24 +0000 (08:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 27 May 2022 17:33:34 +0000 (19:33 +0200)
sc_is_send_allowed() is now used everywhere instead of the combination
of cs_tx_endp_ready() && !cs_tx_blocked(). There's no place where we
need them individually thus it's simpler. The test was placed in cs_util
as we'll complete it later.

include/haproxy/cs_utils.h
src/applet.c
src/conn_stream.c
src/stream.c

index 9f5463d427cfafcde279a16577fa8e10a5113860..22b21b27b7e02de08235f6be0f9273654d3bead9 100644 (file)
@@ -341,4 +341,14 @@ static inline const char *cs_state_str(int state)
        }
 }
 
+/* indicates if the connector may send data to the endpoint, that is, the
+ * endpoint is both willing to receive data and ready to do so. This is only
+ * used with applets so there's always a stream attached to this connector.
+ */
+__attribute__((warn_unused_result))
+static inline int sc_is_send_allowed(const struct stconn *sc)
+{
+       return cs_tx_endp_ready(sc) && !cs_tx_blocked(sc);
+}
+
 #endif /* _HAPROXY_CS_UTILS_H */
index fe1fc625d15474b7a737f8481aefc4770777ce65..1af0dbddf00cfc363bce4acaa3590156f2096aa6 100644 (file)
@@ -246,7 +246,7 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state)
        if (rate >= 100000 && app->call_rate.prev_ctr && // looped more than 100k times over last second
            ((b_size(sc_ib(cs)) && se_fl_test(app->sedesc, SE_FL_RXBLK_BUFF)) || // asks for a buffer which is present
             (b_size(sc_ib(cs)) && !b_data(sc_ib(cs)) && se_fl_test(app->sedesc, SE_FL_RXBLK_ROOM)) || // asks for room in an empty buffer
-            (b_data(sc_ob(cs)) && cs_tx_endp_ready(cs) && !cs_tx_blocked(cs)) || // asks for data already present
+            (b_data(sc_ob(cs)) && sc_is_send_allowed(cs)) || // asks for data already present
             (!b_data(sc_ib(cs)) && b_data(sc_ob(cs)) && // didn't return anything ...
              (sc_oc(cs)->flags & (CF_WRITE_PARTIAL|CF_SHUTW_NOW)) == CF_SHUTW_NOW))) { // ... and left data pending after a shut
                stream_dump_and_crash(&app->obj_type, read_freq_ctr(&app->call_rate));
index 9ad52586926a5035856efe368f420153ab3d37b1..e3c20668029b7461946516a2aa24bf61693875fe 100644 (file)
@@ -1951,8 +1951,7 @@ static int cs_applet_process(struct stconn *cs)
         * appctx but in the case the task is not in runqueue we may have to
         * wakeup the appctx immediately.
         */
-       if ((cs_rx_endp_ready(cs) && !cs_rx_blocked(cs)) ||
-           (cs_tx_endp_ready(cs) && !cs_tx_blocked(cs)))
+       if ((cs_rx_endp_ready(cs) && !cs_rx_blocked(cs)) || sc_is_send_allowed(cs))
                appctx_wakeup(__sc_appctx(cs));
        return 0;
 }
index c0e49b6526a1b040ae099a98cf3d248339247416..e6b197897c2821940ed15acaf16b955460c2f36f 100644 (file)
@@ -1543,13 +1543,11 @@ static void stream_update_both_cs(struct stream *s)
         * handled at the latest moment.
         */
        if (sc_appctx(scf)) {
-               if ((cs_rx_endp_ready(scf) && !cs_rx_blocked(scf)) ||
-                   (cs_tx_endp_ready(scf) && !cs_tx_blocked(scf)))
+               if ((cs_rx_endp_ready(scf) && !cs_rx_blocked(scf)) || sc_is_send_allowed(scf))
                        appctx_wakeup(__sc_appctx(scf));
        }
        if (sc_appctx(scb)) {
-               if ((cs_rx_endp_ready(scb) && !cs_rx_blocked(scb)) ||
-                   (cs_tx_endp_ready(scb) && !cs_tx_blocked(scb)))
+               if ((cs_rx_endp_ready(scb) && !cs_rx_blocked(scb)) || sc_is_send_allowed(scb))
                        appctx_wakeup(__sc_appctx(scb));
        }
 }