]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] add the splice_len member to the buffer struct in preparation of splice support
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Jan 2009 18:33:39 +0000 (19:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Jan 2009 09:15:02 +0000 (10:15 +0100)
In preparation of splice support, let's add the splice_len member
to the buffer struct. An earlier implementation made it conditional,
which made the whole logics very complex due to a large number of
ifdefs.

Now BF_EMPTY is only set once both buf->l and buf->splice_len are
null. Splice_len is initialized to zero during buffer creation and
is currently not changed, so the whole logics remains unaffected.

When splice gets merged, splice_len will reflect the number of bytes
in flight out of the buffer but not yet sent, typically in a pipe for
the Linux case.

include/proto/buffers.h
include/types/buffers.h
src/stream_sock.c

index ab0de118a9a4a95ce089ad07333303add39ffe34..edb3973a6c2432d0704e557202aa78b81f09beb5 100644 (file)
@@ -48,6 +48,7 @@ static inline void buffer_init(struct buffer *buf)
        buf->send_max = 0;
        buf->to_forward = 0;
        buf->l = buf->total = 0;
+       buf->splice_len = 0;
        buf->analysers = 0;
        buf->cons = NULL;
        buf->flags = BF_EMPTY;
index f15d33daaacd9a176518dd9b7443531cf19bfa7d..b310aeda8b0394872bb85c80835c9eb5269256b3 100644 (file)
@@ -127,6 +127,7 @@ struct buffer {
        int wto;                        /* write timeout, in ticks */
        int cto;                        /* connect timeout, in ticks */
        unsigned int l;                 /* data length */
+       unsigned int splice_len;        /* number of bytes remaining in splice, out of buffer */
        char *r, *w, *lr;               /* read ptr, write ptr, last read */
        char *rlim;                     /* read limit, used for header rewriting */
        unsigned int send_max;          /* number of bytes the sender can consume */
index 82e105555499bcc8474c4084e50443d3b786bcc0..d10faa8f1f57f2c215d4581a63ee3360b8071f7f 100644 (file)
@@ -116,8 +116,8 @@ int stream_sock_read(int fd) {
                        cur_read += ret;
 
                        /* if noone is interested in analysing data, let's forward everything */
-                       if (b->to_forward > b->send_max)
-                               b->send_max = MIN(b->to_forward, b->l);
+                       if (b->to_forward - b->splice_len > b->send_max)
+                               b->send_max = MIN(b->to_forward - b->splice_len, b->l);
 
                        if (fdtab[fd].state == FD_STCONN)
                                fdtab[fd].state = FD_STREADY;
@@ -406,7 +406,7 @@ int stream_sock_write(int fd) {
                                b->w = b->data; /* wrap around the buffer */
                        }
 
-                       if (!b->l) {
+                       if (!b->l && !b->splice_len) {
                                b->flags |= BF_EMPTY;
 
                                /* Maybe we just wrote the last chunk and need to close ? */
@@ -608,7 +608,7 @@ void stream_sock_data_finish(struct stream_interface *si)
        /* Check if we need to close the write side */
        if (!(ob->flags & BF_SHUTW)) {
                /* Write not closed, update FD status and timeout for writes */
-               if ((ob->send_max == 0) ||
+               if ((ob->send_max == 0 && ob->splice_len == 0) ||
                    (ob->flags & BF_EMPTY) ||
                    (ob->flags & (BF_HIJACK|BF_WRITE_ENA)) == 0) {
                        /* stop writing */
@@ -693,7 +693,7 @@ void stream_sock_chk_snd(struct stream_interface *si)
        if (unlikely(si->state != SI_ST_EST || (ob->flags & BF_SHUTW)))
                return;
 
-       if ((ob->send_max == 0) ||
+       if ((ob->send_max == 0 && ob->splice_len == 0) ||
            (ob->flags & BF_EMPTY) ||
            (ob->flags & (BF_HIJACK|BF_WRITE_ENA)) == 0) {
                /* stop writing */