From 0979916d3bffc2e87b903559cc793e822ef94c26 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 25 Oct 2018 10:16:07 +0200 Subject: [PATCH] MINOR: stream-int: add si_alloc_ibuf() to ease input buffer allocation 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 2b50c06ea6..f3cf5e0e90 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -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 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 -- 2.39.5