]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: channel: do not report full when buf_empty is present on a channel
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Nov 2014 19:54:13 +0000 (20:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Dec 2014 22:47:32 +0000 (23:47 +0100)
Till now we'd consider a buffer full even if it had size==0 due to pointing
to buf.size. Now we change this : if buf_wanted is present, it means that we
have already tried to allocate a buffer but failed. Thus the buffer must be
considered full so that we stop trying to poll for reads on it. Otherwise if
it's empty, it's buf_empty and we report !full since we may allocate it on
the fly.

include/common/buffer.h
include/proto/channel.h

index 4e55285e7d09ae33ce3ec5f55f3989586d6fbd89..221839020f7861458ce3a77c4a57829d55eb483d 100644 (file)
@@ -176,6 +176,9 @@ static inline int buffer_empty(const struct buffer *buf)
  */
 static inline int buffer_full(const struct buffer *b, unsigned int reserve)
 {
+       if (b == &buf_empty)
+               return 0;
+
        return (b->i + reserve >= b->size);
 }
 
@@ -282,7 +285,10 @@ static inline int buffer_work_area(const struct buffer *buf, const char *end)
 /* Return 1 if the buffer has less than 1/4 of its capacity free, otherwise 0 */
 static inline int buffer_almost_full(const struct buffer *buf)
 {
-       if (buffer_total_space(buf) < buf->size / 4)
+       if (buf == &buf_empty)
+               return 0;
+
+       if (!buf->size || buffer_total_space(buf) < buf->size / 4)
                return 1;
        return 0;
 }
index 1c175e9045be991fa2a0b0b8ab1ed057ffd44346..1cee05a1d58a6782348cf5b141bcb9b2e05794c1 100644 (file)
@@ -129,6 +129,9 @@ static inline int channel_full(const struct channel *chn)
 {
        int rem = chn->buf->size;
 
+       if (chn->buf == &buf_empty)
+               return 0;
+
        rem -= chn->buf->o;
        rem -= chn->buf->i;
        if (!rem)