[MEDIUM] replace BUFSIZE with buf->size in computations
The first step towards dynamic buffer size consists in removing
all static definitions of the buffer size. Instead, we store a
buffer's size in itself. Right now they're all preinitialized
to BUFSIZE, but we will change that.
diff --git a/include/proto/buffers.h b/include/proto/buffers.h
index dc9961a..53fd41f 100644
--- a/include/proto/buffers.h
+++ b/include/proto/buffers.h
@@ -41,6 +41,7 @@
/* Initializes all fields in the buffer. The ->max_len field is initialized last
* so that the compiler can optimize it away if changed immediately after the
* call to this function. By default, it is set to the full size of the buffer.
+ * This implies that buffer_init() must only be called once ->size is set !
* The BF_EMPTY flags is set.
*/
static inline void buffer_init(struct buffer *buf)
@@ -53,7 +54,7 @@
buf->cons = NULL;
buf->flags = BF_EMPTY;
buf->r = buf->lr = buf->w = buf->data;
- buf->max_len = BUFSIZE;
+ buf->max_len = buf->size;
}
/* returns 1 if the buffer is empty, 0 otherwise */
@@ -64,7 +65,7 @@
/* returns 1 if the buffer is full, 0 otherwise */
static inline int buffer_isfull(const struct buffer *buf) {
- return buf->l == BUFSIZE;
+ return buf->l == buf->size;
}
/* Check buffer timeouts, and set the corresponding flags. The
@@ -238,10 +239,10 @@
/* returns the maximum number of bytes writable at once in this buffer */
static inline int buffer_max(const struct buffer *buf)
{
- if (buf->l == BUFSIZE)
+ if (buf->l == buf->size)
return 0;
else if (buf->r >= buf->w)
- return buf->data + BUFSIZE - buf->r;
+ return buf->data + buf->size - buf->r;
else
return buf->w - buf->r;
}