From 806c8c830d69ab09383a6d42a879b2344e3e6989 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 28 Jan 2026 10:53:22 +0100 Subject: [PATCH] REORG: stconn: Move functions related to channel buffers to sc_strm.h sc_have_buff(), sc_need_buff(), sc_have_room() and sc_need_room() are related to the buffer's channel. So we can move them in sc_strm.h header file. In addition, this will be mandatory for the next commit. --- include/haproxy/sc_strm.h | 64 +++++++++++++++++++++++++++++++++++++++ include/haproxy/stconn.h | 61 ------------------------------------- 2 files changed, 64 insertions(+), 61 deletions(-) diff --git a/include/haproxy/sc_strm.h b/include/haproxy/sc_strm.h index 61b72a9fd..5d473f3b8 100644 --- a/include/haproxy/sc_strm.h +++ b/include/haproxy/sc_strm.h @@ -74,6 +74,70 @@ static inline struct buffer *sc_ob(const struct stconn *sc) { return &sc_oc(sc)->buf; } + + +/* The application layer tells the stream connector that it just got the input + * buffer it was waiting for. A read activity is reported. The SC_FL_HAVE_BUFF + * flag is set and held until sc_used_buff() is called to indicate it was + * used. + */ +static inline void sc_have_buff(struct stconn *sc) +{ + if (sc->flags & SC_FL_NEED_BUFF) { + sc->flags &= ~SC_FL_NEED_BUFF; + sc->flags |= SC_FL_HAVE_BUFF; + sc_ep_report_read_activity(sc); + } +} + +/* The stream connector failed to get an input buffer and is waiting for it. + * It indicates a willingness to deliver data to the buffer that will have to + * be retried. As such, callers will often automatically clear SE_FL_HAVE_NO_DATA + * to be called again as soon as SC_FL_NEED_BUFF is cleared. + */ +static inline void sc_need_buff(struct stconn *sc) +{ + sc->flags |= SC_FL_NEED_BUFF; +} + +/* The stream connector indicates that it has successfully allocated the buffer + * it was previously waiting for so it drops the SC_FL_HAVE_BUFF bit. + */ +static inline void sc_used_buff(struct stconn *sc) +{ + sc->flags &= ~SC_FL_HAVE_BUFF; +} + +/* Tell a stream connector some room was made in the input buffer and any + * failed attempt to inject data into it may be tried again. This is usually + * called after a successful transfer of buffer contents to the other side. + * A read activity is reported. + */ +static inline void sc_have_room(struct stconn *sc) +{ + if (sc->flags & SC_FL_NEED_ROOM) { + sc->flags &= ~SC_FL_NEED_ROOM; + sc->room_needed = 0; + sc_ep_report_read_activity(sc); + } +} + +/* The stream connector announces it failed to put data into the input buffer + * by lack of room. Since it indicates a willingness to deliver data to the + * buffer that will have to be retried. Usually the caller will also clear + * SE_FL_HAVE_NO_DATA to be called again as soon as SC_FL_NEED_ROOM is cleared. + * + * The caller is responsible to specified the amount of free space required to + * progress. It must take care to not exceed the buffer size. + */ +static inline void sc_need_room(struct stconn *sc, ssize_t room_needed) +{ + sc->flags |= SC_FL_NEED_ROOM; + BUG_ON_HOT(room_needed > (ssize_t)global.tune.bufsize); + sc->room_needed = room_needed; +} + + /* returns the stream's task associated to this stream connector */ static inline struct task *sc_strm_task(const struct stconn *sc) { diff --git a/include/haproxy/stconn.h b/include/haproxy/stconn.h index 61ce17c39..3a2c5238c 100644 --- a/include/haproxy/stconn.h +++ b/include/haproxy/stconn.h @@ -397,67 +397,6 @@ static inline void se_need_remote_conn(struct sedesc *se) se_fl_set(se, SE_FL_APPLET_NEED_CONN); } -/* The application layer tells the stream connector that it just got the input - * buffer it was waiting for. A read activity is reported. The SC_FL_HAVE_BUFF - * flag is set and held until sc_used_buff() is called to indicate it was - * used. - */ -static inline void sc_have_buff(struct stconn *sc) -{ - if (sc->flags & SC_FL_NEED_BUFF) { - sc->flags &= ~SC_FL_NEED_BUFF; - sc->flags |= SC_FL_HAVE_BUFF; - sc_ep_report_read_activity(sc); - } -} - -/* The stream connector failed to get an input buffer and is waiting for it. - * It indicates a willingness to deliver data to the buffer that will have to - * be retried. As such, callers will often automatically clear SE_FL_HAVE_NO_DATA - * to be called again as soon as SC_FL_NEED_BUFF is cleared. - */ -static inline void sc_need_buff(struct stconn *sc) -{ - sc->flags |= SC_FL_NEED_BUFF; -} - -/* The stream connector indicates that it has successfully allocated the buffer - * it was previously waiting for so it drops the SC_FL_HAVE_BUFF bit. - */ -static inline void sc_used_buff(struct stconn *sc) -{ - sc->flags &= ~SC_FL_HAVE_BUFF; -} - -/* Tell a stream connector some room was made in the input buffer and any - * failed attempt to inject data into it may be tried again. This is usually - * called after a successful transfer of buffer contents to the other side. - * A read activity is reported. - */ -static inline void sc_have_room(struct stconn *sc) -{ - if (sc->flags & SC_FL_NEED_ROOM) { - sc->flags &= ~SC_FL_NEED_ROOM; - sc->room_needed = 0; - sc_ep_report_read_activity(sc); - } -} - -/* The stream connector announces it failed to put data into the input buffer - * by lack of room. Since it indicates a willingness to deliver data to the - * buffer that will have to be retried. Usually the caller will also clear - * SE_FL_HAVE_NO_DATA to be called again as soon as SC_FL_NEED_ROOM is cleared. - * - * The caller is responsible to specified the amount of free space required to - * progress. It must take care to not exceed the buffer size. - */ -static inline void sc_need_room(struct stconn *sc, ssize_t room_needed) -{ - sc->flags |= SC_FL_NEED_ROOM; - BUG_ON_HOT(room_needed > (ssize_t)global.tune.bufsize); - sc->room_needed = room_needed; -} - /* The stream endpoint indicates that it's ready to consume data from the * stream's output buffer. Report a send activity if the SE is unblocked. */