]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream-int: add si_alloc_ibuf() to ease input buffer allocation
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Oct 2018 08:16:07 +0000 (10:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 28 Oct 2018 12:47:00 +0000 (13:47 +0100)
This will supersed channel_alloc_buffer() while relying on it. It will
automatically adjust SI_FL_WAIT_ROOM on the stream-int depending on
success or failure to allocate this buffer.

It's worth noting that it could make sense to also set SI_FL_WANT_PUT
each time we do this to further simplify the code at user places such
as applets, but it would possibly not be easy to clean this flag
everywhere an rx operation stops.

include/proto/stream_interface.h

index 2b50c06ea6f37e2b40d4edebb24dc813f5df6a0f..f3cf5e0e90f0eaab8967f32094528ec6ae5eb6be 100644 (file)
@@ -306,6 +306,26 @@ static inline struct conn_stream *si_alloc_cs(struct stream_interface *si, struc
        return cs;
 }
 
+/* Try to allocate a buffer for the stream-int's input channel. It relies on
+ * channel_alloc_buffer() for this so it abides by its rules. It returns 0 in
+ * case of failure, non-zero otherwise. The stream-int's flag SI_FL_WAIT_ROOM
+ * is cleared before trying. If no buffer are available, the requester,
+ * represented by <wait> pointer, will be added in the list of objects waiting
+ * for an available buffer, and SI_FL_WAIT_ROOM will be set on the stream-int.
+ * The requester will be responsible for calling this function to try again
+ * once woken up.
+ */
+static inline int si_alloc_ibuf(struct stream_interface *si, struct buffer_wait *wait)
+{
+       int ret;
+
+       si->flags &= ~SI_FL_WAIT_ROOM;
+       ret = channel_alloc_buffer(si_ic(si), wait);
+       if (!ret)
+               si->flags |= SI_FL_WAIT_ROOM;
+       return ret;
+}
+
 /* Release the interface's existing endpoint (connection or appctx) and
  * allocate then initialize a new appctx which is assigned to the interface
  * and returned. NULL may be returned upon memory shortage. Applet <applet>