MINOR: channel: add channel_in_transit()

This function returns the amount of bytes in transit in a channel's buffer,
which is the amount of outgoing data plus the amount of incoming data bound
to the forward limit.

(cherry picked from commit 1a4484dec8488cdd14c52e6cb93198e3c8f83942)
[wt: this is not a bug but the next bugfix needs it]
diff --git a/include/proto/channel.h b/include/proto/channel.h
index d79bb9f..9473709 100644
--- a/include/proto/channel.h
+++ b/include/proto/channel.h
@@ -118,6 +118,27 @@
 	return rem >= 0;
 }
 
+/* Returns the amount of bytes from the channel that are already scheduled for
+ * leaving (buf->o) or that are still part of the input and expected to be sent
+ * soon as covered by to_forward. This is useful to know by how much we can
+ * shrink the rewrite reserve during forwards.
+ */
+static inline int channel_in_transit(const struct channel *chn)
+{
+	int ret;
+
+	/* below, this is min(i, to_forward) optimized for the fast case */
+	if (chn->to_forward >= chn->buf->i ||
+	    (CHN_INFINITE_FORWARD < MAX_RANGE(typeof(chn->buf->i)) &&
+	     chn->to_forward == CHN_INFINITE_FORWARD))
+		ret = chn->buf->i;
+	else
+		ret = chn->to_forward;
+
+	ret += chn->buf->o;
+	return ret;
+}
+
 /* Returns non-zero if the buffer input is considered full. This is used to
  * decide when to stop reading into a buffer when we want to ensure that we
  * leave the reserve untouched after all pending outgoing data are forwarded.