From 5056cbdb866e22c5953c0520aeff8e68e76dbc89 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 1 Feb 2024 16:31:03 +0100 Subject: [PATCH] MINOR: sc_strm: Add generic version to perform sync receives and sends sc_sync_recv() and sc_sync_send() were added to use connection or applet versions, depending on the endpoint type. For now these functions are not used. But this will be used by process_stream() to replace the connection version. --- include/haproxy/sc_strm.h | 27 +++++++++++++++++++++++++++ src/stconn.c | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/include/haproxy/sc_strm.h b/include/haproxy/sc_strm.h index d8fb5aa71..445bbde4f 100644 --- a/include/haproxy/sc_strm.h +++ b/include/haproxy/sc_strm.h @@ -43,6 +43,9 @@ void sc_conn_sync_send(struct stconn *sc); int sc_applet_sync_recv(struct stconn *sc); void sc_applet_sync_send(struct stconn *sc); +int sc_applet_sync_recv(struct stconn *sc); +void sc_applet_sync_send(struct stconn *sc); + /* returns the channel which receives data from this stream connector (input channel) */ static inline struct channel *sc_ic(const struct stconn *sc) @@ -322,6 +325,30 @@ static inline void sc_chk_snd(struct stconn *sc) sc->app_ops->chk_snd(sc); } + +/* Perform a synchronous receive using the right version, depending the endpoing + * is a connection or an applet. + */ +static inline int sc_sync_recv(struct stconn *sc) +{ + if (sc_ep_test(sc, SE_FL_T_MUX)) + return sc_conn_sync_recv(sc); + else if (sc_ep_test(sc, SE_FL_T_APPLET)) + return sc_applet_sync_recv(sc); + return 0; +} + +/* Perform a synchronous send using the right version, depending the endpoing is + * a connection or an applet. + */ +static inline void sc_sync_send(struct stconn *sc) +{ + if (sc_ep_test(sc, SE_FL_T_MUX)) + sc_conn_sync_send(sc); + else if (sc_ep_test(sc, SE_FL_T_APPLET)) + sc_applet_sync_send(sc); +} + /* Combines both sc_update_rx() and sc_update_tx() at once */ static inline void sc_update(struct stconn *sc) { diff --git a/src/stconn.c b/src/stconn.c index 145ecf0d5..c6515b14e 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -2107,6 +2107,9 @@ int sc_applet_recv(struct stconn *sc) */ int sc_applet_sync_recv(struct stconn *sc) { + if (!(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS)) + return 0; + if (!sc_state_in(sc->state, SC_SB_RDY|SC_SB_EST)) return 0; @@ -2198,6 +2201,9 @@ void sc_applet_sync_send(struct stconn *sc) oc->flags &= ~CF_WRITE_EVENT; + if (!(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS)) + return; + if (sc->flags & SC_FL_SHUT_DONE) return;