/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_buffer();
-/* Initializes all fields in the buffer. The ->rlim field is initialized last
+/* 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.
* The BF_EMPTY flags is set.
buf->cons = NULL;
buf->flags = BF_EMPTY;
buf->r = buf->lr = buf->w = buf->data;
- buf->rlim = buf->data + BUFSIZE;
+ buf->max_len = BUFSIZE;
}
/* returns 1 if the buffer is empty, 0 otherwise */
buf->r = buf->lr = buf->w = buf->data;
buf->l = 0;
buf->flags |= BF_EMPTY | BF_FULL;
- if (buf->rlim)
+ if (buf->max_len)
buf->flags &= ~BF_FULL;
}
*/
static inline void buffer_set_rlim(struct buffer *buf, int size)
{
- buf->rlim = buf->data + size;
+ buf->max_len = size;
if (buf->l < size)
buf->flags &= ~BF_FULL;
else
#define BF_READ_ERROR 0x000008 /* unrecoverable error on producer side */
#define BF_READ_ACTIVITY (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR)
-#define BF_FULL 0x000010 /* buffer cannot accept any more data (l >= rlim-data) */
+#define BF_FULL 0x000010 /* buffer cannot accept any more data (l >= max_len) */
#define BF_SHUTR 0x000020 /* producer has already shut down */
#define BF_SHUTR_NOW 0x000040 /* the producer must shut down for reads immediately */
#define BF_READ_NOEXP 0x000080 /* producer should not expire */
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 max_len; /* read limit, used to keep room for header rewriting */
unsigned int send_max; /* number of bytes the sender can consume om this buffer, <= l */
unsigned int to_forward; /* number of bytes to forward after send_max without a wake-up */
unsigned int analysers; /* bit field indicating what to do on the buffer */
http_find_header2("Transfer-Encoding", 17, msg->sol, &txn->hdr_idx, &ctx);
if (ctx.idx && ctx.vlen >= 7 && strncasecmp(ctx.line+ctx.val, "chunked", 7) == 0) {
unsigned int chunk = 0;
- while ( params < req->rlim && !HTTP_IS_CRLF(*params)) {
+ while ( params < (req->data+req->max_len) && !HTTP_IS_CRLF(*params)) {
char c = *params;
if (ishex(c)) {
unsigned int hex = toupper(c) - '0';
buf->flags &= ~(BF_EMPTY|BF_FULL);
if (buf->l == 0)
buf->flags |= BF_EMPTY;
- if (buf->l >= buf->rlim - buf->data)
+ if (buf->l >= buf->max_len)
buf->flags |= BF_FULL;
return -1;
buf->flags &= ~(BF_EMPTY|BF_FULL);
if (buf->l == 0)
buf->flags |= BF_EMPTY;
- if (buf->l >= buf->rlim - buf->data)
+ if (buf->l >= buf->max_len)
buf->flags |= BF_FULL;
chunk->len = 0;
b->flags &= ~(BF_EMPTY|BF_FULL);
if (b->l == 0)
b->flags |= BF_EMPTY;
- if (b->l >= b->rlim - b->data)
+ if (b->l >= b->max_len)
b->flags |= BF_FULL;
return delta;
b->flags &= ~(BF_EMPTY|BF_FULL);
if (b->l == 0)
b->flags |= BF_EMPTY;
- if (b->l >= b->rlim - b->data)
+ if (b->l >= b->max_len)
b->flags |= BF_FULL;
return delta;
b->flags &= ~(BF_EMPTY|BF_FULL);
if (b->l == 0)
b->flags |= BF_EMPTY;
- if (b->l >= b->rlim - b->data)
+ if (b->l >= b->max_len)
b->flags |= BF_FULL;
return delta;
s->req->flags |= BF_READ_ATTACHED; /* the producer is already connected */
if (p->mode == PR_MODE_HTTP) /* reserve some space for header rewriting */
- s->req->rlim -= MAXREWRITE;
+ s->req->max_len -= MAXREWRITE;
/* activate default analysers enabled for this listener */
s->req->analysers = l->analysers;
* all the part of the request which fits in a buffer is already
* there.
*/
- if (msg_len > l4->req->rlim - l4->req->w)
- msg_len = l4->req->rlim - l4->req->w;
+ if (msg_len > l4->req->max_len + l4->req->data - l4->req->w)
+ msg_len = l4->req->max_len + l4->req->data - l4->req->w;
if (bleft < msg_len)
goto too_short;
/*
* 1. compute the maximum block size we can read at once.
*/
- if (b->l == 0) { /* let's realign the buffer to optimize I/O */
- b->r = b->w = b->lr = b->data;
- max = b->rlim - b->data;
+ if (b->l == 0) {
+ /* let's realign the buffer to optimize I/O */
+ b->r = b->w = b->lr = b->data;
+ max = b->max_len;
}
else if (b->r > b->w) {
- max = b->rlim - b->r;
+ max = b->data + b->max_len - b->r;
}
else {
max = b->w - b->r;
- /* FIXME: theorically, if w>0, we shouldn't have rlim < data+size anymore
- * since it means that the rewrite protection has been removed. This
- * implies that the if statement can be removed.
- */
- if (max > b->rlim - b->data)
- max = b->rlim - b->data;
+ if (max > b->max_len)
+ max = b->max_len;
}
if (unlikely(max == 0)) {
b->total += ret;
- if (b->l >= b->rlim - b->data) {
+ if (b->l >= b->max_len) {
/* The buffer is now full, there's no point in going through
* the loop again.
*/
b->flags |= BF_WRITE_PARTIAL;
- if (b->l < b->rlim - b->data)
+ if (b->l < b->max_len)
b->flags &= ~BF_FULL;
if (b->w == b->data + BUFSIZE) {