[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/src/buffers.c b/src/buffers.c
index c8681cf..55b7963 100644
--- a/src/buffers.c
+++ b/src/buffers.c
@@ -24,7 +24,7 @@
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_buffer()
{
- pool2_buffer = create_pool("buffer", sizeof(struct buffer), MEM_F_SHARED);
+ pool2_buffer = create_pool("buffer", sizeof(struct buffer) + BUFSIZE, MEM_F_SHARED);
return pool2_buffer != NULL;
}
@@ -48,7 +48,7 @@
buf->send_max += len;
buf->r += len;
buf->total += len;
- if (buf->r == buf->data + BUFSIZE)
+ if (buf->r == buf->data + buf->size)
buf->r = buf->data;
buf->flags &= ~(BF_EMPTY|BF_FULL);
@@ -82,7 +82,7 @@
buf->send_max += chunk->len;
buf->r += chunk->len;
buf->total += chunk->len;
- if (buf->r == buf->data + BUFSIZE)
+ if (buf->r == buf->data + buf->size)
buf->r = buf->data;
buf->flags &= ~(BF_EMPTY|BF_FULL);
@@ -111,7 +111,7 @@
len = strlen(str);
delta = len - (end - pos);
- if (delta + b->r >= b->data + BUFSIZE)
+ if (delta + b->r >= b->data + b->size)
return 0; /* no space left */
/* first, protect the end of the buffer */
@@ -145,7 +145,7 @@
delta = len - (end - pos);
- if (delta + b->r >= b->data + BUFSIZE)
+ if (delta + b->r >= b->data + b->size)
return 0; /* no space left */
if (b->data + b->l < end) {
@@ -192,7 +192,7 @@
delta = len + 2;
- if (delta + b->r >= b->data + BUFSIZE)
+ if (delta + b->r >= b->data + b->size)
return 0; /* no space left */
/* first, protect the end of the buffer */
diff --git a/src/client.c b/src/client.c
index ec8f120..92baefc 100644
--- a/src/client.c
+++ b/src/client.c
@@ -384,6 +384,7 @@
if ((s->req = pool_alloc2(pool2_buffer)) == NULL)
goto out_fail_req; /* no memory */
+ s->req->size = BUFSIZE;
buffer_init(s->req);
s->req->prod = &s->si[0];
s->req->cons = &s->si[1];
@@ -410,6 +411,7 @@
if ((s->rep = pool_alloc2(pool2_buffer)) == NULL)
goto out_fail_rep; /* no memory */
+ s->rep->size = BUFSIZE;
buffer_init(s->rep);
s->rep->prod = &s->si[1];
s->rep->cons = &s->si[0];
diff --git a/src/proto_http.c b/src/proto_http.c
index e495d32..d2c5919 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -2576,7 +2576,7 @@
* could. Let's switch to the DATA state. *
************************************************************/
- buffer_set_rlim(req, BUFSIZE); /* no more rewrite needed */
+ buffer_set_rlim(req, req->size); /* no more rewrite needed */
s->logs.tv_request = now;
/* When a connection is tarpitted, we use the tarpit timeout,
@@ -3190,7 +3190,7 @@
* could. Let's switch to the DATA state. *
************************************************************/
- buffer_set_rlim(rep, BUFSIZE); /* no more rewrite needed */
+ buffer_set_rlim(rep, rep->size); /* no more rewrite needed */
t->logs.t_data = tv_ms_elapsed(&t->logs.tv_accept, &now);
/* if the user wants to log as soon as possible, without counting
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index 880ec99..0cd6a35 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -482,6 +482,7 @@
if ((s->req = pool_alloc2(pool2_buffer)) == NULL)
goto out_free_task;
+ s->req->size = BUFSIZE;
buffer_init(s->req);
s->req->prod = &s->si[0];
s->req->cons = &s->si[1];
@@ -498,6 +499,7 @@
if ((s->rep = pool_alloc2(pool2_buffer)) == NULL)
goto out_free_req;
+ s->rep->size = BUFSIZE;
buffer_init(s->rep);
s->rep->prod = &s->si[1];
diff --git a/src/session.c b/src/session.c
index 33109d6..23c4409 100644
--- a/src/session.c
+++ b/src/session.c
@@ -320,7 +320,7 @@
struct buffer *rep = si->ib;
if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
- buffer_set_rlim(rep, BUFSIZE); /* no rewrite needed */
+ buffer_set_rlim(rep, rep->size); /* no rewrite needed */
/* if the user wants to log as soon as possible, without counting
* bytes from the server, then this is the right moment. */
@@ -330,7 +330,7 @@
}
}
else {
- buffer_set_rlim(rep, BUFSIZE - MAXREWRITE); /* rewrite needed */
+ buffer_set_rlim(rep, req->size - MAXREWRITE); /* rewrite needed */
s->txn.rsp.msg_state = HTTP_MSG_RPBEFORE;
/* reset hdr_idx which was already initialized by the request.
* right now, the http parser does it.
diff --git a/src/stream_sock.c b/src/stream_sock.c
index f20bb3f..3a69d1f 100644
--- a/src/stream_sock.c
+++ b/src/stream_sock.c
@@ -345,7 +345,7 @@
b->flags |= BF_READ_PARTIAL;
b->flags &= ~BF_EMPTY;
- if (b->r == b->data + BUFSIZE) {
+ if (b->r == b->data + b->size) {
b->r = b->data; /* wrap around the buffer */
}
@@ -367,7 +367,7 @@
}
}
else if ((b->flags & (BF_STREAMER | BF_STREAMER_FAST)) &&
- (cur_read <= BUFSIZE / 2)) {
+ (cur_read <= b->size / 2)) {
b->xfer_large = 0;
b->xfer_small++;
if (b->xfer_small >= 2) {
@@ -397,7 +397,7 @@
*/
if (ret < max) {
if ((b->flags & (BF_STREAMER | BF_STREAMER_FAST)) &&
- (cur_read <= BUFSIZE / 2)) {
+ (cur_read <= b->size / 2)) {
b->xfer_large = 0;
b->xfer_small++;
if (b->xfer_small >= 3) {
@@ -580,7 +580,7 @@
if (b->r > b->w)
max = b->r - b->w;
else
- max = b->data + BUFSIZE - b->w;
+ max = b->data + b->size - b->w;
/* limit the amount of outgoing data if required */
if (max > b->send_max)
@@ -628,7 +628,7 @@
b->flags |= BF_WRITE_PARTIAL;
b->w += ret;
- if (b->w == b->data + BUFSIZE)
+ if (b->w == b->data + b->size)
b->w = b->data; /* wrap around the buffer */
b->l -= ret;