]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: channel: Add the function channel_add_input
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 2 Jan 2019 13:24:35 +0000 (14:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 2 Jan 2019 19:12:44 +0000 (20:12 +0100)
This function must be called when new incoming data are pushed in the channel's
buffer. It updates the channel state and take care of the fast forwarding by
consuming right amount of data and decrementing "->to_forward" accordingly when
necessary. In fact, this patch just moves a part of ci_putblk in a dedicated
function.

This patch must be backported to 1.9.

include/proto/channel.h
src/channel.c

index 5d9c7a8aa339e1b30d5500c6c169ea96643a7fb6..0ea458f77838cb13e824b805133c565f71a918ae 100644 (file)
@@ -361,6 +361,25 @@ static inline void channel_forward_forever(struct channel *chn)
        chn->to_forward = CHN_INFINITE_FORWARD;
 }
 
+/* <len> bytes of input data was added into the channel <chn>. This functions
+ * must be called to update the channel state. It also handles the fast
+ * forwarding. */
+static inline void channel_add_input(struct channel *chn, unsigned int len)
+{
+       if (chn->to_forward) {
+               unsigned long fwd = len;
+               if (chn->to_forward != CHN_INFINITE_FORWARD) {
+                       if (fwd > chn->to_forward)
+                               fwd = chn->to_forward;
+                       chn->to_forward -= fwd;
+               }
+               c_adv(chn, fwd);
+       }
+       /* notify that some data was read */
+       chn->total += len;
+       chn->flags |= CF_READ_PARTIAL;
+}
+
 static inline unsigned long long channel_htx_forward(struct channel *chn, struct htx *htx, unsigned long long bytes)
 {
        unsigned long long ret;
@@ -378,7 +397,6 @@ static inline void channel_htx_forward_forever(struct channel *chn, struct htx *
        channel_forward_forever(chn);
        b_set_data(&chn->buf, b_size(&chn->buf));
 }
-
 /*********************************************************************/
 /* These functions are used to compute various channel content sizes */
 /*********************************************************************/
index 3bf5c50428561dbdd69c22c2b74025f08cf8e72c..d4a46ffeddd2d1675429a3df153774c9f6754c6b 100644 (file)
@@ -172,19 +172,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
                memcpy(c_orig(chn), blk + max, len - max);
 
        b_add(&chn->buf, len);
-       chn->total += len;
-       if (chn->to_forward) {
-               unsigned long fwd = len;
-               if (chn->to_forward != CHN_INFINITE_FORWARD) {
-                       if (fwd > chn->to_forward)
-                               fwd = chn->to_forward;
-                       chn->to_forward -= fwd;
-               }
-               c_adv(chn, fwd);
-       }
-
-       /* notify that some data was read from the SI into the buffer */
-       chn->flags |= CF_READ_PARTIAL;
+       channel_add_input(chn, len);
        return len;
 }