]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: conn_stream: add an rx buffer to the conn_stream
authorWilly Tarreau <w@1wt.eu>
Fri, 2 Mar 2018 09:43:58 +0000 (10:43 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Jul 2018 17:21:43 +0000 (19:21 +0200)
In order to reorganize the connection layers, recv() operations will
need to be retryable and to support partial transfers. This requires
an intermediary buffer to hold the data coming from the mux. After a
few attempts, it turns out that this buffer is best placed inside the
conn_stream itself. For now it's only set to buf_empty and it will be
up to the caller to allocate it if required.

include/proto/connection.h
include/types/connection.h

index 8344c951dee5deec8ef8b7f27c8549cb0801e981..ce7ef38119a866c6dda5465afaf511cf97577c0c 100644 (file)
@@ -601,6 +601,7 @@ static inline void cs_init(struct conn_stream *cs, struct connection *conn)
        LIST_INIT(&cs->wait_list.list);
        LIST_INIT(&cs->send_wait_list);
        cs->conn = conn;
+       cs->rxbuf = BUF_NULL;
 }
 
 /* Initializes all required fields for a new connection. Note that it does the
@@ -661,11 +662,26 @@ static inline struct connection *conn_new()
        return conn;
 }
 
-/* Releases a conn_stream previously allocated by cs_new() */
+/* Releases the conn_stream's rx buf if it exists. The buffer is automatically
+ * replaced with a pointer to the empty buffer.
+ */
+static inline void cs_drop_rxbuf(struct conn_stream *cs)
+{
+       if (b_size(&cs->rxbuf)) {
+               b_free(&cs->rxbuf);
+               offer_buffers(NULL, tasks_run_queue);
+       }
+}
+
+/* Releases a conn_stream previously allocated by cs_new(), as well as any
+ * buffer it would still hold.
+ */
 static inline void cs_free(struct conn_stream *cs)
 {
        if (cs->wait_list.task)
                tasklet_free(cs->wait_list.task);
+
+       cs_drop_rxbuf(cs);
        pool_free(pool_head_connstream, cs);
 }
 
index 16a82bb57fb05a2a67fad2bd15bb1cc14c191621..3a66ed5da59071c4877b15ce8ff4d912468e4896 100644 (file)
@@ -367,10 +367,12 @@ struct conn_src {
  */
 struct conn_stream {
        enum obj_type obj_type;              /* differentiates connection from applet context */
+       /* 3 bytes hole here */
        unsigned int flags;                  /* CS_FL_* */
        struct connection *conn;             /* xprt-level connection */
        struct wait_list wait_list;          /* We're in a wait list for send */
        struct list send_wait_list;          /* list of tasks to wake when we're ready to send */
+       struct buffer rxbuf;                 /* receive buffer, always valid (buf_empty or real buffer) */
        void *data;                          /* pointer to upper layer's entity (eg: stream interface) */
        const struct data_cb *data_cb;       /* data layer callbacks. Must be set before xprt->init() */
        void *ctx;                           /* mux-specific context */