]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: conn_stream: add an tx buffer to the conn_stream
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 23 May 2018 12:58:55 +0000 (14:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Aug 2018 07:53:01 +0000 (09:53 +0200)
To be symmetrical with the recv() part, we no handle retryable and partial
transmission using a intermediary buffer in the conn_stream. For now it's only
set to BUF_NULL and never allocated nor used.

It cannot yet be used as-is without risking to lose data on close since
conn_streams need to be orphaned for this.

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

index dba7fca991825f907a115f8190b7cb56305950a4..2111f67d2ff56de449c2a9d15e6dea5e083375b7 100644 (file)
@@ -616,6 +616,7 @@ static inline void cs_init(struct conn_stream *cs, struct connection *conn)
        LIST_INIT(&cs->send_wait_list);
        cs->conn = conn;
        cs->rxbuf = BUF_NULL;
+       cs->txbuf = BUF_NULL;
 }
 
 /* Initializes all required fields for a new connection. Note that it does the
@@ -687,6 +688,17 @@ static inline void cs_drop_rxbuf(struct conn_stream *cs)
        }
 }
 
+/* Releases the conn_stream's tx buf if it exists. The buffer is automatically
+ * replaced with a pointer to the empty buffer.
+ */
+static inline void cs_drop_txbuf(struct conn_stream *cs)
+{
+       if (b_size(&cs->txbuf)) {
+               b_free(&cs->txbuf);
+               offer_buffers(NULL, tasks_run_queue);
+       }
+}
+
 /* Releases a conn_stream previously allocated by cs_new(), as well as any
  * buffer it would still hold.
  */
@@ -696,6 +708,7 @@ static inline void cs_free(struct conn_stream *cs)
                tasklet_free(cs->wait_list.task);
 
        cs_drop_rxbuf(cs);
+       cs_drop_txbuf(cs);
        pool_free(pool_head_connstream, cs);
 }
 
index 83c6bd182f27da284e955058305f2ccea6b35592..cf5dbb6b7faa36353f55102d2368c753cc9c4622 100644 (file)
@@ -373,6 +373,7 @@ struct conn_stream {
        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) */
+       struct buffer txbuf;                 /* transmission 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 */