]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: session: simplify receive buffer allocator to only use the channel
authorWilly Tarreau <w@1wt.eu>
Sun, 28 Dec 2014 12:09:02 +0000 (13:09 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2015 19:41:47 +0000 (20:41 +0100)
Now that we can get the session from the channel, let's simplify the
prototype of session_alloc_recv_buffer() to only require the channel.
Both the caller and the function are now simplified.

include/proto/session.h
src/hlua.c
src/session.c
src/stream_interface.c

index fd62dfdbf00ebb50301fe188ff118d0bd34ad862..2dc3d830e4cbfc6a3ad393c528e70ff8323b9d34 100644 (file)
@@ -60,7 +60,7 @@ void __session_offer_buffers(int rqlimit);
 static inline void session_offer_buffers();
 int session_alloc_work_buffer(struct session *s);
 void session_release_buffers(struct session *s);
-int session_alloc_recv_buffer(struct session *s, struct buffer **buf);
+int session_alloc_recv_buffer(struct channel *chn);
 
 /* sets the stick counter's entry pointer */
 static inline void stkctr_set_entry(struct stkctr *stkctr, struct stksess *entry)
index 78f67731f58aa2756dedec6c35b8d240b0897ca0..02e3e31e99eccc963070ef937ab40ec9e934b467 100644 (file)
@@ -1440,7 +1440,7 @@ static int hlua_socket_write_yield(struct lua_State *L,int status, lua_KContext
         * the request buffer if its not required.
         */
        if (socket->s->req.buf->size == 0) {
-               if (!session_alloc_recv_buffer(socket->s, &socket->s->req.buf)) {
+               if (!session_alloc_recv_buffer(&socket->s->req)) {
                        socket->s->si[0].flags |= SI_FL_WAIT_ROOM;
                        goto hlua_socket_write_yield_return;
                }
@@ -2324,7 +2324,7 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
         * the request buffer if its not required.
         */
        if (chn->chn->buf->size == 0) {
-               if (!session_alloc_recv_buffer(chn->s, &chn->chn->buf)) {
+               if (!session_alloc_recv_buffer(chn->chn)) {
                        chn_prod(chn->chn)->flags |= SI_FL_WAIT_ROOM;
                        WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_send_yield, TICK_ETERNITY, 0));
                }
index 26758477f47fc9ade55a49223d3af0a5faa53ddf..94fc875b08758e373af6dad4f3c8da13e511c166 100644 (file)
@@ -670,24 +670,26 @@ static void session_free(struct session *s)
        }
 }
 
-/* Allocates a single buffer for session <s>, but only if it's guaranteed that
- * it's not the last available buffer. To be called at the beginning of recv()
- * callbacks to ensure that the required buffers are properly allocated. If the
- * buffer is the session's request buffer, an extra control is made so that we
- * always keep <tune.buffers.reserved> buffers available after this allocation.
- * In all circumstances we leave at least 2 buffers so that any later call from
- * process_session() has a chance to succeed. The response buffer is not bound
- * to this control. Returns 0 in case of failure, non-zero otherwise.
+/* Allocates a receive buffer for channel <chn>, but only if it's guaranteed
+ * that it's not the last available buffer or it's the response buffer. Unless
+ * the buffer is the response buffer, an extra control is made so that we always
+ * keep <tune.buffers.reserved> buffers available after this allocation. To be
+ * called at the beginning of recv() callbacks to ensure that the required
+ * buffers are properly allocated. Returns 0 in case of failure, non-zero
+ * otherwise.
  */
-int session_alloc_recv_buffer(struct session *s, struct buffer **buf)
+int session_alloc_recv_buffer(struct channel *chn)
 {
+       struct session *s;
        struct buffer *b;
        int margin = 0;
 
-       if (buf == &s->req.buf)
+       if (!(chn->flags & CF_ISRESP))
                margin = global.tune.reserved_bufs;
 
-       b = b_alloc_margin(buf, margin);
+       s = chn_sess(chn);
+
+       b = b_alloc_margin(&chn->buf, margin);
        if (b)
                return 1;
 
index 9912df074ca18e186ba21c100d1f5c5528f5e3b4..1ba509e75056899800852ff8f4c84789d3e50782 100644 (file)
@@ -1185,7 +1185,7 @@ static void si_conn_recv_cb(struct connection *conn)
        }
 
        /* now we'll need a buffer */
-       if (!session_alloc_recv_buffer(si_sess(si), &ic->buf)) {
+       if (!session_alloc_recv_buffer(ic)) {
                si->flags |= SI_FL_WAIT_ROOM;
                goto end_recv;
        }