mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 05:41:26 +02:00
REORG/MAJOR: extract "struct buffer" from "struct channel"
At the moment, the struct is still embedded into the struct channel, but all the functions have been updated to use struct buffer only when possible, otherwise struct channel. Some functions would likely need to be splitted between a buffer-layer primitive and a channel-layer function. Later the buffer should become a pointer in the struct buffer, but doing so requires a few changes to the buffer allocation calls.
This commit is contained in:
parent
7421efb85f
commit
572bf9095d
@ -47,23 +47,23 @@ int bo_getline(struct channel *buf, char *str, int len);
|
||||
int bo_getblk(struct channel *buf, char *blk, int len, int offset);
|
||||
int buffer_replace2(struct channel *b, char *pos, char *end, const char *str, int len);
|
||||
int buffer_insert_line2(struct channel *b, char *pos, const char *str, int len);
|
||||
void buffer_dump(FILE *o, struct channel *b, int from, int to);
|
||||
void buffer_slow_realign(struct channel *buf);
|
||||
void buffer_bounce_realign(struct channel *buf);
|
||||
void buffer_dump(FILE *o, struct buffer *b, int from, int to);
|
||||
void buffer_slow_realign(struct buffer *buf);
|
||||
void buffer_bounce_realign(struct buffer *buf);
|
||||
unsigned long long buffer_forward(struct channel *buf, unsigned long long bytes);
|
||||
|
||||
/* Initialize all fields in the buffer. The BF_OUT_EMPTY flags is set. */
|
||||
static inline void buffer_init(struct channel *buf)
|
||||
{
|
||||
buf->o = 0;
|
||||
buf->i = 0;
|
||||
buf->buf.o = 0;
|
||||
buf->buf.i = 0;
|
||||
buf->buf.p = buf->buf.data;
|
||||
buf->to_forward = 0;
|
||||
buf->total = 0;
|
||||
buf->pipe = NULL;
|
||||
buf->analysers = 0;
|
||||
buf->cons = NULL;
|
||||
buf->flags = BF_OUT_EMPTY;
|
||||
buf->p = buf->data;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
@ -86,7 +86,7 @@ static inline void buffer_init(struct channel *buf)
|
||||
})
|
||||
|
||||
/* Returns the start of the input data in a buffer */
|
||||
static inline char *bi_ptr(const struct channel *b)
|
||||
static inline char *bi_ptr(const struct buffer *b)
|
||||
{
|
||||
return b->p;
|
||||
}
|
||||
@ -94,7 +94,7 @@ static inline char *bi_ptr(const struct channel *b)
|
||||
/* Returns the end of the input data in a buffer (pointer to next
|
||||
* insertion point).
|
||||
*/
|
||||
static inline char *bi_end(const struct channel *b)
|
||||
static inline char *bi_end(const struct buffer *b)
|
||||
{
|
||||
char *ret = b->p + b->i;
|
||||
|
||||
@ -104,7 +104,7 @@ static inline char *bi_end(const struct channel *b)
|
||||
}
|
||||
|
||||
/* Returns the amount of input data that can contiguously be read at once */
|
||||
static inline int bi_contig_data(const struct channel *b)
|
||||
static inline int bi_contig_data(const struct buffer *b)
|
||||
{
|
||||
int data = b->data + b->size - b->p;
|
||||
|
||||
@ -114,7 +114,7 @@ static inline int bi_contig_data(const struct channel *b)
|
||||
}
|
||||
|
||||
/* Returns the start of the output data in a buffer */
|
||||
static inline char *bo_ptr(const struct channel *b)
|
||||
static inline char *bo_ptr(const struct buffer *b)
|
||||
{
|
||||
char *ret = b->p - b->o;
|
||||
|
||||
@ -124,13 +124,13 @@ static inline char *bo_ptr(const struct channel *b)
|
||||
}
|
||||
|
||||
/* Returns the end of the output data in a buffer */
|
||||
static inline char *bo_end(const struct channel *b)
|
||||
static inline char *bo_end(const struct buffer *b)
|
||||
{
|
||||
return b->p;
|
||||
}
|
||||
|
||||
/* Returns the amount of output data that can contiguously be read at once */
|
||||
static inline int bo_contig_data(const struct channel *b)
|
||||
static inline int bo_contig_data(const struct buffer *b)
|
||||
{
|
||||
char *beg = b->p - b->o;
|
||||
|
||||
@ -140,25 +140,25 @@ static inline int bo_contig_data(const struct channel *b)
|
||||
}
|
||||
|
||||
/* Return the buffer's length in bytes by summing the input and the output */
|
||||
static inline int buffer_len(const struct channel *buf)
|
||||
static inline int buffer_len(const struct buffer *buf)
|
||||
{
|
||||
return buf->i + buf->o;
|
||||
}
|
||||
|
||||
/* Return non-zero only if the buffer is not empty */
|
||||
static inline int buffer_not_empty(const struct channel *buf)
|
||||
static inline int buffer_not_empty(const struct buffer *buf)
|
||||
{
|
||||
return buf->i | buf->o;
|
||||
}
|
||||
|
||||
/* Return non-zero only if the buffer is empty */
|
||||
static inline int buffer_empty(const struct channel *buf)
|
||||
static inline int buffer_empty(const struct buffer *buf)
|
||||
{
|
||||
return !buffer_not_empty(buf);
|
||||
}
|
||||
|
||||
/* Normalizes a pointer after a subtract */
|
||||
static inline char *buffer_wrap_sub(const struct channel *buf, char *ptr)
|
||||
static inline char *buffer_wrap_sub(const struct buffer *buf, char *ptr)
|
||||
{
|
||||
if (ptr < buf->data)
|
||||
ptr += buf->size;
|
||||
@ -166,7 +166,7 @@ static inline char *buffer_wrap_sub(const struct channel *buf, char *ptr)
|
||||
}
|
||||
|
||||
/* Normalizes a pointer after an addition */
|
||||
static inline char *buffer_wrap_add(const struct channel *buf, char *ptr)
|
||||
static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
|
||||
{
|
||||
if (ptr - buf->size >= buf->data)
|
||||
ptr -= buf->size;
|
||||
@ -180,7 +180,7 @@ static inline char *buffer_wrap_add(const struct channel *buf, char *ptr)
|
||||
*/
|
||||
static inline int buffer_reserved(const struct channel *buf)
|
||||
{
|
||||
int ret = global.tune.maxrewrite - buf->to_forward - buf->o;
|
||||
int ret = global.tune.maxrewrite - buf->to_forward - buf->buf.o;
|
||||
|
||||
if (buf->to_forward == BUF_INFINITE_FORWARD)
|
||||
return 0;
|
||||
@ -195,7 +195,7 @@ static inline int buffer_reserved(const struct channel *buf)
|
||||
*/
|
||||
static inline int buffer_max_len(const struct channel *buf)
|
||||
{
|
||||
return buf->size - buffer_reserved(buf);
|
||||
return buf->buf.size - buffer_reserved(buf);
|
||||
}
|
||||
|
||||
/* Returns non-zero if the buffer input is considered full. The reserved space
|
||||
@ -205,20 +205,20 @@ static inline int buffer_max_len(const struct channel *buf)
|
||||
*/
|
||||
static inline int bi_full(const struct channel *b)
|
||||
{
|
||||
int rem = b->size;
|
||||
int rem = b->buf.size;
|
||||
|
||||
rem -= b->o;
|
||||
rem -= b->i;
|
||||
rem -= b->buf.o;
|
||||
rem -= b->buf.i;
|
||||
if (!rem)
|
||||
return 1; /* buffer already full */
|
||||
|
||||
if (b->to_forward >= b->size ||
|
||||
(BUF_INFINITE_FORWARD < MAX_RANGE(typeof(b->size)) && // just there to ensure gcc
|
||||
if (b->to_forward >= b->buf.size ||
|
||||
(BUF_INFINITE_FORWARD < MAX_RANGE(typeof(b->buf.size)) && // just there to ensure gcc
|
||||
b->to_forward == BUF_INFINITE_FORWARD)) // avoids the useless second
|
||||
return 0; // test whenever possible
|
||||
|
||||
rem -= global.tune.maxrewrite;
|
||||
rem += b->o;
|
||||
rem += b->buf.o;
|
||||
rem += b->to_forward;
|
||||
return rem <= 0;
|
||||
}
|
||||
@ -230,21 +230,21 @@ static inline int bi_full(const struct channel *b)
|
||||
*/
|
||||
static inline int bi_avail(const struct channel *b)
|
||||
{
|
||||
int rem = b->size;
|
||||
int rem = b->buf.size;
|
||||
int rem2;
|
||||
|
||||
rem -= b->o;
|
||||
rem -= b->i;
|
||||
rem -= b->buf.o;
|
||||
rem -= b->buf.i;
|
||||
if (!rem)
|
||||
return rem; /* buffer already full */
|
||||
|
||||
if (b->to_forward >= b->size ||
|
||||
(BUF_INFINITE_FORWARD < MAX_RANGE(typeof(b->size)) && // just there to ensure gcc
|
||||
if (b->to_forward >= b->buf.size ||
|
||||
(BUF_INFINITE_FORWARD < MAX_RANGE(typeof(b->buf.size)) && // just there to ensure gcc
|
||||
b->to_forward == BUF_INFINITE_FORWARD)) // avoids the useless second
|
||||
return rem; // test whenever possible
|
||||
|
||||
rem2 = rem - global.tune.maxrewrite;
|
||||
rem2 += b->o;
|
||||
rem2 += b->buf.o;
|
||||
rem2 += b->to_forward;
|
||||
|
||||
if (rem > rem2)
|
||||
@ -257,7 +257,7 @@ static inline int bi_avail(const struct channel *b)
|
||||
/* Return the maximum amount of bytes that can be written into the buffer,
|
||||
* including reserved space which may be overwritten.
|
||||
*/
|
||||
static inline int buffer_total_space(const struct channel *buf)
|
||||
static inline int buffer_total_space(const struct buffer *buf)
|
||||
{
|
||||
return buf->size - buffer_len(buf);
|
||||
}
|
||||
@ -266,7 +266,7 @@ static inline int buffer_total_space(const struct channel *buf)
|
||||
* and enforces a limit on buf->data + buf->size. <start> must be within the
|
||||
* buffer.
|
||||
*/
|
||||
static inline int buffer_contig_area(const struct channel *buf, const char *start, int count)
|
||||
static inline int buffer_contig_area(const struct buffer *buf, const char *start, int count)
|
||||
{
|
||||
if (count > buf->data - start + buf->size)
|
||||
count = buf->data - start + buf->size;
|
||||
@ -276,7 +276,7 @@ static inline int buffer_contig_area(const struct channel *buf, const char *star
|
||||
/* Return the amount of bytes that can be written into the buffer at once,
|
||||
* including reserved space which may be overwritten.
|
||||
*/
|
||||
static inline int buffer_contig_space(const struct channel *buf)
|
||||
static inline int buffer_contig_space(const struct buffer *buf)
|
||||
{
|
||||
const char *left, *right;
|
||||
|
||||
@ -296,11 +296,11 @@ static inline int buffer_contig_space(const struct channel *buf)
|
||||
*/
|
||||
static inline void b_adv(struct channel *b, unsigned int adv)
|
||||
{
|
||||
b->i -= adv;
|
||||
b->o += adv;
|
||||
if (b->o)
|
||||
b->buf.i -= adv;
|
||||
b->buf.o += adv;
|
||||
if (b->buf.o)
|
||||
b->flags &= ~BF_OUT_EMPTY;
|
||||
b->p = b_ptr(b, adv);
|
||||
b->buf.p = b_ptr(&b->buf, adv);
|
||||
}
|
||||
|
||||
/* Rewinds the buffer by <adv> bytes, which means that the buffer pointer goes
|
||||
@ -309,18 +309,18 @@ static inline void b_adv(struct channel *b, unsigned int adv)
|
||||
*/
|
||||
static inline void b_rew(struct channel *b, unsigned int adv)
|
||||
{
|
||||
b->i += adv;
|
||||
b->o -= adv;
|
||||
if (!b->o && !b->pipe)
|
||||
b->buf.i += adv;
|
||||
b->buf.o -= adv;
|
||||
if (!b->buf.o && !b->pipe)
|
||||
b->flags |= BF_OUT_EMPTY;
|
||||
b->p = b_ptr(b, (int)-adv);
|
||||
b->buf.p = b_ptr(&b->buf, (int)-adv);
|
||||
}
|
||||
|
||||
/* Return the amount of bytes that can be written into the buffer at once,
|
||||
* excluding the amount of reserved space passed in <res>, which is
|
||||
* preserved.
|
||||
*/
|
||||
static inline int buffer_contig_space_with_res(const struct channel *buf, int res)
|
||||
static inline int buffer_contig_space_with_res(const struct buffer *buf, int res)
|
||||
{
|
||||
/* Proceed differently if the buffer is full, partially used or empty.
|
||||
* The hard situation is when it's partially used and either data or
|
||||
@ -342,9 +342,9 @@ static inline int buffer_contig_space_with_res(const struct channel *buf, int re
|
||||
/* Return the amount of bytes that can be written into the buffer at once,
|
||||
* excluding reserved space, which is preserved.
|
||||
*/
|
||||
static inline int buffer_contig_space_res(const struct channel *buf)
|
||||
static inline int buffer_contig_space_res(const struct channel *chn)
|
||||
{
|
||||
return buffer_contig_space_with_res(buf, buffer_reserved(buf));
|
||||
return buffer_contig_space_with_res(&chn->buf, buffer_reserved(chn));
|
||||
}
|
||||
|
||||
/* Normalizes a pointer which is supposed to be relative to the beginning of a
|
||||
@ -353,7 +353,7 @@ static inline int buffer_contig_space_res(const struct channel *buf)
|
||||
* once, so the original pointer must be between ->data-size and ->data+2*size-1,
|
||||
* otherwise an invalid pointer might be returned.
|
||||
*/
|
||||
static inline const char *buffer_pointer(const struct channel *buf, const char *ptr)
|
||||
static inline const char *buffer_pointer(const struct buffer *buf, const char *ptr)
|
||||
{
|
||||
if (ptr < buf->data)
|
||||
ptr += buf->size;
|
||||
@ -365,7 +365,7 @@ static inline const char *buffer_pointer(const struct channel *buf, const char *
|
||||
/* Returns the distance between two pointers, taking into account the ability
|
||||
* to wrap around the buffer's end.
|
||||
*/
|
||||
static inline int buffer_count(const struct channel *buf, const char *from, const char *to)
|
||||
static inline int buffer_count(const struct buffer *buf, const char *from, const char *to)
|
||||
{
|
||||
int count = to - from;
|
||||
if (count < 0)
|
||||
@ -376,7 +376,7 @@ static inline int buffer_count(const struct channel *buf, const char *from, cons
|
||||
/* returns the amount of pending bytes in the buffer. It is the amount of bytes
|
||||
* that is not scheduled to be sent.
|
||||
*/
|
||||
static inline int buffer_pending(const struct channel *buf)
|
||||
static inline int buffer_pending(const struct buffer *buf)
|
||||
{
|
||||
return buf->i;
|
||||
}
|
||||
@ -387,7 +387,7 @@ static inline int buffer_pending(const struct channel *buf)
|
||||
* <end>. It always starts at buf->p. The work area includes the
|
||||
* reserved area.
|
||||
*/
|
||||
static inline int buffer_work_area(const struct channel *buf, const char *end)
|
||||
static inline int buffer_work_area(const struct buffer *buf, const char *end)
|
||||
{
|
||||
end = buffer_pointer(buf, end);
|
||||
if (end == buffer_wrap_add(buf, buf->p + buf->i))
|
||||
@ -397,7 +397,7 @@ static inline int buffer_work_area(const struct channel *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 channel *buf)
|
||||
static inline int buffer_almost_full(const struct buffer *buf)
|
||||
{
|
||||
if (buffer_total_space(buf) < buf->size / 4)
|
||||
return 1;
|
||||
@ -443,10 +443,10 @@ static inline void buffer_check_timeouts(struct channel *b)
|
||||
*/
|
||||
static inline void buffer_flush(struct channel *buf)
|
||||
{
|
||||
buf->p = buffer_wrap_add(buf, buf->p + buf->i);
|
||||
buf->o += buf->i;
|
||||
buf->i = 0;
|
||||
if (buf->o)
|
||||
buf->buf.p = buffer_wrap_add(&buf->buf, buf->buf.p + buf->buf.i);
|
||||
buf->buf.o += buf->buf.i;
|
||||
buf->buf.i = 0;
|
||||
if (buf->buf.o)
|
||||
buf->flags &= ~BF_OUT_EMPTY;
|
||||
}
|
||||
|
||||
@ -456,10 +456,10 @@ static inline void buffer_flush(struct channel *buf)
|
||||
*/
|
||||
static inline void buffer_erase(struct channel *buf)
|
||||
{
|
||||
buf->o = 0;
|
||||
buf->i = 0;
|
||||
buf->buf.o = 0;
|
||||
buf->buf.i = 0;
|
||||
buf->to_forward = 0;
|
||||
buf->p = buf->data;
|
||||
buf->buf.p = buf->buf.data;
|
||||
buf->flags &= ~(BF_FULL | BF_OUT_EMPTY);
|
||||
if (!buf->pipe)
|
||||
buf->flags |= BF_OUT_EMPTY;
|
||||
@ -472,14 +472,14 @@ static inline void buffer_erase(struct channel *buf)
|
||||
*/
|
||||
static inline void bi_erase(struct channel *buf)
|
||||
{
|
||||
if (!buf->o)
|
||||
if (!buf->buf.o)
|
||||
return buffer_erase(buf);
|
||||
|
||||
buf->to_forward = 0;
|
||||
if (!buf->i)
|
||||
if (!buf->buf.i)
|
||||
return;
|
||||
|
||||
buf->i = 0;
|
||||
buf->buf.i = 0;
|
||||
buf->flags &= ~BF_FULL;
|
||||
if (bi_full(buf))
|
||||
buf->flags |= BF_FULL;
|
||||
@ -491,7 +491,7 @@ static inline void bi_erase(struct channel *buf)
|
||||
* This is mainly used to remove empty lines at the beginning of a request
|
||||
* or a response.
|
||||
*/
|
||||
static inline void bi_fast_delete(struct channel *buf, int n)
|
||||
static inline void bi_fast_delete(struct buffer *buf, int n)
|
||||
{
|
||||
buf->i -= n;
|
||||
buf->p += n;
|
||||
@ -578,7 +578,7 @@ static inline void buffer_dont_read(struct channel *buf)
|
||||
* Tries to realign the given buffer, and returns how many bytes can be written
|
||||
* there at once without overwriting anything.
|
||||
*/
|
||||
static inline int buffer_realign(struct channel *buf)
|
||||
static inline int buffer_realign(struct buffer *buf)
|
||||
{
|
||||
if (!(buf->i | buf->o)) {
|
||||
/* let's realign the buffer to optimize I/O */
|
||||
@ -595,12 +595,12 @@ static inline int buffer_realign(struct channel *buf)
|
||||
*/
|
||||
static inline void bo_skip(struct channel *buf, int len)
|
||||
{
|
||||
buf->o -= len;
|
||||
if (!buf->o && !buf->pipe)
|
||||
buf->buf.o -= len;
|
||||
if (!buf->buf.o && !buf->pipe)
|
||||
buf->flags |= BF_OUT_EMPTY;
|
||||
|
||||
if (buffer_len(buf) == 0)
|
||||
buf->p = buf->data;
|
||||
if (buffer_len(&buf->buf) == 0)
|
||||
buf->buf.p = buf->buf.data;
|
||||
|
||||
if (!bi_full(buf))
|
||||
buf->flags &= ~BF_FULL;
|
||||
@ -654,7 +654,7 @@ static inline int bo_getchr(struct channel *buf)
|
||||
return -2;
|
||||
return -1;
|
||||
}
|
||||
return *buffer_wrap_sub(buf, buf->p - buf->o);
|
||||
return *buffer_wrap_sub(&buf->buf, buf->buf.p - buf->buf.o);
|
||||
}
|
||||
|
||||
/* This function writes the string <str> at position <pos> which must be in
|
||||
|
@ -174,16 +174,20 @@ struct chunk {
|
||||
/* needed for a declaration below */
|
||||
struct session;
|
||||
|
||||
struct buffer {
|
||||
char *p; /* buffer's start pointer, separates in and out data */
|
||||
unsigned int size; /* buffer size in bytes */
|
||||
unsigned int i; /* number of input bytes pending for analysis in the buffer */
|
||||
unsigned int o; /* number of out bytes the sender can consume from this buffer */
|
||||
char data[0]; /* <size> bytes */
|
||||
};
|
||||
|
||||
struct channel {
|
||||
unsigned int flags; /* BF_* */
|
||||
int rex; /* expiration date for a read, in ticks */
|
||||
int wex; /* expiration date for a write or connect, in ticks */
|
||||
int rto; /* read timeout, in ticks */
|
||||
int wto; /* write timeout, in ticks */
|
||||
char *p; /* buffer's start pointer, separates in and out data */
|
||||
unsigned int size; /* buffer size in bytes */
|
||||
unsigned int i; /* number of input bytes pending for analysis in the buffer */
|
||||
unsigned int o; /* number of out bytes the sender can consume from this buffer */
|
||||
unsigned int to_forward; /* number of bytes to forward after out without a wake-up */
|
||||
unsigned int analysers; /* bit field indicating what to do on the buffer */
|
||||
int analyse_exp; /* expiration date for current analysers (if set) */
|
||||
@ -194,7 +198,7 @@ struct channel {
|
||||
struct stream_interface *prod; /* producer attached to this buffer */
|
||||
struct stream_interface *cons; /* consumer attached to this buffer */
|
||||
struct pipe *pipe; /* non-NULL only when data present */
|
||||
char data[0]; /* <size> bytes */
|
||||
struct buffer buf; /* embedded buffer for now, will move */
|
||||
};
|
||||
|
||||
|
||||
|
18
src/acl.c
18
src/acl.c
@ -108,7 +108,7 @@ acl_fetch_req_len(struct proxy *px, struct session *l4, void *l7, unsigned int o
|
||||
return 0;
|
||||
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = l4->req->i;
|
||||
smp->data.uint = l4->req->buf.i;
|
||||
smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
|
||||
return 1;
|
||||
}
|
||||
@ -128,8 +128,8 @@ acl_fetch_ssl_hello_type(struct proxy *px, struct session *l4, void *l7, unsigne
|
||||
|
||||
b = ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? l4->rep : l4->req;
|
||||
|
||||
bleft = b->i;
|
||||
data = (const unsigned char *)b->p;
|
||||
bleft = b->buf.i;
|
||||
data = (const unsigned char *)b->buf.p;
|
||||
|
||||
if (!bleft)
|
||||
goto too_short;
|
||||
@ -194,11 +194,11 @@ acl_fetch_req_ssl_ver(struct proxy *px, struct session *l4, void *l7, unsigned i
|
||||
return 0;
|
||||
|
||||
msg_len = 0;
|
||||
bleft = l4->req->i;
|
||||
bleft = l4->req->buf.i;
|
||||
if (!bleft)
|
||||
goto too_short;
|
||||
|
||||
data = (const unsigned char *)l4->req->p;
|
||||
data = (const unsigned char *)l4->req->buf.p;
|
||||
if ((*data >= 0x14 && *data <= 0x17) || (*data == 0xFF)) {
|
||||
/* SSLv3 header format */
|
||||
if (bleft < 5)
|
||||
@ -266,8 +266,8 @@ acl_fetch_req_ssl_ver(struct proxy *px, struct session *l4, void *l7, unsigned i
|
||||
* all the part of the request which fits in a buffer is already
|
||||
* there.
|
||||
*/
|
||||
if (msg_len > buffer_max_len(l4->req) + l4->req->data - l4->req->p)
|
||||
msg_len = buffer_max_len(l4->req) + l4->req->data - l4->req->p;
|
||||
if (msg_len > buffer_max_len(l4->req) + l4->req->buf.data - l4->req->buf.p)
|
||||
msg_len = buffer_max_len(l4->req) + l4->req->buf.data - l4->req->buf.p;
|
||||
|
||||
if (bleft < msg_len)
|
||||
goto too_short;
|
||||
@ -332,8 +332,8 @@ acl_fetch_ssl_hello_sni(struct proxy *px, struct session *l4, void *l7, unsigned
|
||||
|
||||
b = ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? l4->rep : l4->req;
|
||||
|
||||
bleft = b->i;
|
||||
data = (unsigned char *)b->p;
|
||||
bleft = b->buf.i;
|
||||
data = (unsigned char *)b->buf.p;
|
||||
|
||||
/* Check for SSL/TLS Handshake */
|
||||
if (!bleft)
|
||||
|
@ -257,11 +257,11 @@ struct server *get_server_ph_post(struct session *s)
|
||||
struct proxy *px = s->be;
|
||||
unsigned int plen = px->url_param_len;
|
||||
unsigned long len = msg->body_len;
|
||||
const char *params = b_ptr(req, (int)(msg->sov - req->o));
|
||||
const char *params = b_ptr(&req->buf, (int)(msg->sov - req->buf.o));
|
||||
const char *p = params;
|
||||
|
||||
if (len > buffer_len(req) - msg->sov)
|
||||
len = buffer_len(req) - msg->sov;
|
||||
if (len > buffer_len(&req->buf) - msg->sov)
|
||||
len = buffer_len(&req->buf) - msg->sov;
|
||||
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
@ -342,7 +342,7 @@ struct server *get_server_hh(struct session *s)
|
||||
ctx.idx = 0;
|
||||
|
||||
/* if the message is chunked, we skip the chunk size, but use the value as len */
|
||||
http_find_header2(px->hh_name, plen, b_ptr(s->req, -s->req->o), &txn->hdr_idx, &ctx);
|
||||
http_find_header2(px->hh_name, plen, b_ptr(&s->req->buf, s->req->buf.o), &txn->hdr_idx, &ctx);
|
||||
|
||||
/* if the header is not found or empty, let's fallback to round robin */
|
||||
if (!ctx.idx || !ctx.vlen)
|
||||
@ -418,7 +418,7 @@ struct server *get_server_rch(struct session *s)
|
||||
args[0].data.str.len = px->hh_len;
|
||||
args[1].type = ARGT_STOP;
|
||||
|
||||
b_rew(s->req, rewind = s->req->o);
|
||||
b_rew(s->req, rewind = s->req->buf.o);
|
||||
|
||||
ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp);
|
||||
len = smp.data.str.len;
|
||||
@ -568,7 +568,7 @@ int assign_server(struct session *s)
|
||||
if (s->txn.req.msg_state < HTTP_MSG_BODY)
|
||||
break;
|
||||
srv = get_server_uh(s->be,
|
||||
b_ptr(s->req, (int)(s->txn.req.sl.rq.u - s->req->o)),
|
||||
b_ptr(&s->req->buf, (int)(s->txn.req.sl.rq.u - s->req->buf.o)),
|
||||
s->txn.req.sl.rq.u_l);
|
||||
break;
|
||||
|
||||
@ -578,7 +578,7 @@ int assign_server(struct session *s)
|
||||
break;
|
||||
|
||||
srv = get_server_ph(s->be,
|
||||
b_ptr(s->req, (int)(s->txn.req.sl.rq.u - s->req->o)),
|
||||
b_ptr(&s->req->buf, (int)(s->txn.req.sl.rq.u - s->req->buf.o)),
|
||||
s->txn.req.sl.rq.u_l);
|
||||
|
||||
if (!srv && s->txn.meth == HTTP_METH_POST)
|
||||
@ -904,7 +904,7 @@ static void assign_tproxy_address(struct session *s)
|
||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0;
|
||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0;
|
||||
|
||||
b_rew(s->req, rewind = s->req->o);
|
||||
b_rew(s->req, rewind = s->req->buf.o);
|
||||
if (http_get_hdr(&s->txn.req, srv->bind_hdr_name, srv->bind_hdr_len,
|
||||
&s->txn.hdr_idx, srv->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
|
||||
@ -938,7 +938,7 @@ static void assign_tproxy_address(struct session *s)
|
||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0;
|
||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0;
|
||||
|
||||
b_rew(s->req, rewind = s->req->o);
|
||||
b_rew(s->req, rewind = s->req->buf.o);
|
||||
if (http_get_hdr(&s->txn.req, s->be->bind_hdr_name, s->be->bind_hdr_len,
|
||||
&s->txn.hdr_idx, s->be->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
|
||||
|
@ -51,7 +51,7 @@ unsigned long long buffer_forward(struct channel *buf, unsigned long long bytes)
|
||||
* once anyway.
|
||||
*/
|
||||
if (bytes <= ~0U) {
|
||||
if (bytes32 <= buf->i) {
|
||||
if (bytes32 <= buf->buf.i) {
|
||||
/* OK this amount of bytes might be forwarded at once */
|
||||
if (!bytes32)
|
||||
return 0;
|
||||
@ -60,8 +60,8 @@ unsigned long long buffer_forward(struct channel *buf, unsigned long long bytes)
|
||||
}
|
||||
}
|
||||
|
||||
forwarded = buf->i;
|
||||
b_adv(buf, buf->i);
|
||||
forwarded = buf->buf.i;
|
||||
b_adv(buf, buf->buf.i);
|
||||
|
||||
/* Note: the case below is the only case where we may return
|
||||
* a byte count that does not fit into a 32-bit number.
|
||||
@ -103,7 +103,7 @@ int bo_inject(struct channel *buf, const char *msg, int len)
|
||||
if (len == 0)
|
||||
return -1;
|
||||
|
||||
if (len > buf->size) {
|
||||
if (len > buf->buf.size) {
|
||||
/* we can't write this chunk and will never be able to, because
|
||||
* it is larger than the buffer. This must be reported as an
|
||||
* error. Then we return -2 so that writers that don't care can
|
||||
@ -112,14 +112,14 @@ int bo_inject(struct channel *buf, const char *msg, int len)
|
||||
return -2;
|
||||
}
|
||||
|
||||
max = buffer_realign(buf);
|
||||
max = buffer_realign(&buf->buf);
|
||||
|
||||
if (len > max)
|
||||
return max;
|
||||
|
||||
memcpy(buf->p, msg, len);
|
||||
buf->o += len;
|
||||
buf->p = b_ptr(buf, len);
|
||||
memcpy(buf->buf.p, msg, len);
|
||||
buf->buf.o += len;
|
||||
buf->buf.p = b_ptr(&buf->buf, len);
|
||||
buf->total += len;
|
||||
|
||||
buf->flags &= ~(BF_OUT_EMPTY|BF_FULL);
|
||||
@ -144,9 +144,9 @@ int bi_putchr(struct channel *buf, char c)
|
||||
if (buf->flags & BF_FULL)
|
||||
return -1;
|
||||
|
||||
*bi_end(buf) = c;
|
||||
*bi_end(&buf->buf) = c;
|
||||
|
||||
buf->i++;
|
||||
buf->buf.i++;
|
||||
if (bi_full(buf))
|
||||
buf->flags |= BF_FULL;
|
||||
buf->flags |= BF_READ_PARTIAL;
|
||||
@ -177,7 +177,7 @@ int bi_putblk(struct channel *buf, const char *blk, int len)
|
||||
return -2;
|
||||
|
||||
max = buffer_max_len(buf);
|
||||
if (unlikely(len > max - buffer_len(buf))) {
|
||||
if (unlikely(len > max - buffer_len(&buf->buf))) {
|
||||
/* we can't write this chunk right now because the buffer is
|
||||
* almost full or because the block is too large. Return the
|
||||
* available space or -2 if impossible.
|
||||
@ -192,12 +192,12 @@ int bi_putblk(struct channel *buf, const char *blk, int len)
|
||||
return 0;
|
||||
|
||||
/* OK so the data fits in the buffer in one or two blocks */
|
||||
max = buffer_contig_space_with_res(buf, buf->size - max);
|
||||
memcpy(bi_end(buf), blk, MIN(len, max));
|
||||
max = buffer_contig_space_with_res(&buf->buf, buf->buf.size - max);
|
||||
memcpy(bi_end(&buf->buf), blk, MIN(len, max));
|
||||
if (len > max)
|
||||
memcpy(buf->data, blk + max, len - max);
|
||||
memcpy(buf->buf.data, blk + max, len - max);
|
||||
|
||||
buf->i += len;
|
||||
buf->buf.i += len;
|
||||
buf->total += len;
|
||||
if (buf->to_forward) {
|
||||
unsigned long fwd = len;
|
||||
@ -243,10 +243,10 @@ int bo_getline(struct channel *buf, char *str, int len)
|
||||
goto out;
|
||||
}
|
||||
|
||||
p = bo_ptr(buf);
|
||||
p = bo_ptr(&buf->buf);
|
||||
|
||||
if (max > buf->o) {
|
||||
max = buf->o;
|
||||
if (max > buf->buf.o) {
|
||||
max = buf->buf.o;
|
||||
str[max-1] = 0;
|
||||
}
|
||||
while (max) {
|
||||
@ -256,9 +256,9 @@ int bo_getline(struct channel *buf, char *str, int len)
|
||||
|
||||
if (*p == '\n')
|
||||
break;
|
||||
p = buffer_wrap_add(buf, p + 1);
|
||||
p = buffer_wrap_add(&buf->buf, p + 1);
|
||||
}
|
||||
if (ret > 0 && ret < len && ret < buf->o &&
|
||||
if (ret > 0 && ret < len && ret < buf->buf.o &&
|
||||
*(str-1) != '\n' &&
|
||||
!(buf->flags & (BF_SHUTW|BF_SHUTW_NOW)))
|
||||
ret = 0;
|
||||
@ -283,25 +283,25 @@ int bo_getblk(struct channel *buf, char *blk, int len, int offset)
|
||||
if (buf->flags & BF_SHUTW)
|
||||
return -1;
|
||||
|
||||
if (len + offset > buf->o) {
|
||||
if (len + offset > buf->buf.o) {
|
||||
if (buf->flags & (BF_SHUTW|BF_SHUTW_NOW))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
firstblock = buf->data + buf->size - bo_ptr(buf);
|
||||
firstblock = buf->buf.data + buf->buf.size - bo_ptr(&buf->buf);
|
||||
if (firstblock > offset) {
|
||||
if (firstblock >= len + offset) {
|
||||
memcpy(blk, bo_ptr(buf) + offset, len);
|
||||
memcpy(blk, bo_ptr(&buf->buf) + offset, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
memcpy(blk, bo_ptr(buf) + offset, firstblock - offset);
|
||||
memcpy(blk + firstblock - offset, buf->data, len - firstblock + offset);
|
||||
memcpy(blk, bo_ptr(&buf->buf) + offset, firstblock - offset);
|
||||
memcpy(blk + firstblock - offset, buf->buf.data, len - firstblock + offset);
|
||||
return len;
|
||||
}
|
||||
|
||||
memcpy(blk, buf->data + offset - firstblock, len);
|
||||
memcpy(blk, buf->buf.data + offset - firstblock, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -321,26 +321,26 @@ int buffer_replace2(struct channel *b, char *pos, char *end, const char *str, in
|
||||
|
||||
delta = len - (end - pos);
|
||||
|
||||
if (bi_end(b) + delta >= b->data + b->size)
|
||||
if (bi_end(&b->buf) + delta >= b->buf.data + b->buf.size)
|
||||
return 0; /* no space left */
|
||||
|
||||
if (buffer_not_empty(b) &&
|
||||
bi_end(b) + delta > bo_ptr(b) &&
|
||||
bo_ptr(b) >= bi_end(b))
|
||||
if (buffer_not_empty(&b->buf) &&
|
||||
bi_end(&b->buf) + delta > bo_ptr(&b->buf) &&
|
||||
bo_ptr(&b->buf) >= bi_end(&b->buf))
|
||||
return 0; /* no space left before wrapping data */
|
||||
|
||||
/* first, protect the end of the buffer */
|
||||
memmove(end + delta, end, bi_end(b) - end);
|
||||
memmove(end + delta, end, bi_end(&b->buf) - end);
|
||||
|
||||
/* now, copy str over pos */
|
||||
if (len)
|
||||
memcpy(pos, str, len);
|
||||
|
||||
b->i += delta;
|
||||
b->buf.i += delta;
|
||||
|
||||
b->flags &= ~BF_FULL;
|
||||
if (buffer_len(b) == 0)
|
||||
b->p = b->data;
|
||||
if (buffer_len(&b->buf) == 0)
|
||||
b->buf.p = b->buf.data;
|
||||
if (bi_full(b))
|
||||
b->flags |= BF_FULL;
|
||||
|
||||
@ -363,11 +363,11 @@ int buffer_insert_line2(struct channel *b, char *pos, const char *str, int len)
|
||||
|
||||
delta = len + 2;
|
||||
|
||||
if (bi_end(b) + delta >= b->data + b->size)
|
||||
if (bi_end(&b->buf) + delta >= b->buf.data + b->buf.size)
|
||||
return 0; /* no space left */
|
||||
|
||||
/* first, protect the end of the buffer */
|
||||
memmove(pos + delta, pos, bi_end(b) - pos);
|
||||
memmove(pos + delta, pos, bi_end(&b->buf) - pos);
|
||||
|
||||
/* now, copy str over pos */
|
||||
if (len && str) {
|
||||
@ -376,7 +376,7 @@ int buffer_insert_line2(struct channel *b, char *pos, const char *str, int len)
|
||||
pos[len + 1] = '\n';
|
||||
}
|
||||
|
||||
b->i += delta;
|
||||
b->buf.i += delta;
|
||||
|
||||
b->flags &= ~BF_FULL;
|
||||
if (bi_full(b))
|
||||
@ -390,7 +390,7 @@ int buffer_insert_line2(struct channel *b, char *pos, const char *str, int len)
|
||||
* becomes contiguous and starts at the beginning of the buffer area. The
|
||||
* function may only be used when the buffer's output is empty.
|
||||
*/
|
||||
void buffer_slow_realign(struct channel *buf)
|
||||
void buffer_slow_realign(struct buffer *buf)
|
||||
{
|
||||
/* two possible cases :
|
||||
* - the buffer is in one contiguous block, we move it in-place
|
||||
@ -420,7 +420,7 @@ void buffer_slow_realign(struct channel *buf)
|
||||
* so it's desirable to use it only on non-contiguous buffers. No pointers are
|
||||
* changed, the caller is responsible for that.
|
||||
*/
|
||||
void buffer_bounce_realign(struct channel *buf)
|
||||
void buffer_bounce_realign(struct buffer *buf)
|
||||
{
|
||||
int advance, to_move;
|
||||
char *from, *to;
|
||||
@ -584,7 +584,7 @@ int chunk_asciiencode(struct chunk *dst, struct chunk *src, char qc) {
|
||||
/*
|
||||
* Dumps part or all of a buffer.
|
||||
*/
|
||||
void buffer_dump(FILE *o, struct channel *b, int from, int to)
|
||||
void buffer_dump(FILE *o, struct buffer *b, int from, int to)
|
||||
{
|
||||
fprintf(o, "Dumping buffer %p\n", b);
|
||||
fprintf(o, " data=%p o=%d i=%d p=%p\n",
|
||||
|
@ -1481,7 +1481,7 @@ static void cli_io_handler(struct stream_interface *si)
|
||||
/* ensure we have some output room left in the event we
|
||||
* would want to return some info right after parsing.
|
||||
*/
|
||||
if (buffer_almost_full(si->ib))
|
||||
if (buffer_almost_full(&si->ib->buf))
|
||||
break;
|
||||
|
||||
reql = bo_getline(si->ob, trash, trashlen);
|
||||
@ -1595,7 +1595,7 @@ static void cli_io_handler(struct stream_interface *si)
|
||||
* buffer is empty. This still allows pipelined requests
|
||||
* to be sent in non-interactive mode.
|
||||
*/
|
||||
if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->applet.st1 && !req->o)) {
|
||||
if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->applet.st1 && !req->buf.o)) {
|
||||
si->applet.st0 = STAT_CLI_END;
|
||||
continue;
|
||||
}
|
||||
@ -2197,7 +2197,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
|
||||
case STAT_ST_LIST:
|
||||
/* dump proxies */
|
||||
while (si->applet.ctx.stats.px) {
|
||||
if (buffer_almost_full(rep))
|
||||
if (buffer_almost_full(&rep->buf))
|
||||
return 0;
|
||||
px = si->applet.ctx.stats.px;
|
||||
/* skip the disabled proxies and non-networked ones */
|
||||
@ -2513,7 +2513,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
|
||||
case STAT_PX_ST_LI:
|
||||
/* stats.l has been initialized above */
|
||||
for (; si->applet.ctx.stats.l != NULL; si->applet.ctx.stats.l = l->next) {
|
||||
if (buffer_almost_full(rep))
|
||||
if (buffer_almost_full(&rep->buf))
|
||||
return 0;
|
||||
|
||||
l = si->applet.ctx.stats.l;
|
||||
@ -2651,7 +2651,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc
|
||||
for (; si->applet.ctx.stats.sv != NULL; si->applet.ctx.stats.sv = sv->next) {
|
||||
int sv_state; /* 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, 6=unchecked */
|
||||
|
||||
if (buffer_almost_full(rep))
|
||||
if (buffer_almost_full(&rep->buf))
|
||||
return 0;
|
||||
|
||||
sv = si->applet.ctx.stats.sv;
|
||||
@ -3472,7 +3472,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
|
||||
" an_exp=%s",
|
||||
sess->req,
|
||||
sess->req->flags, sess->req->analysers,
|
||||
sess->req->i, sess->req->o,
|
||||
sess->req->buf.i, sess->req->buf.o,
|
||||
sess->req->pipe ? sess->req->pipe->data : 0,
|
||||
sess->req->to_forward,
|
||||
sess->req->analyse_exp ?
|
||||
@ -3491,8 +3491,8 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
|
||||
sess->req->wex ?
|
||||
human_time(TICKS_TO_MS(sess->req->wex - now_ms),
|
||||
TICKS_TO_MS(1000)) : "<NEVER>",
|
||||
sess->req->data,
|
||||
(int)(sess->req->p - sess->req->data),
|
||||
sess->req->buf.data,
|
||||
(int)(sess->req->buf.p - sess->req->buf.data),
|
||||
sess->txn.req.next,
|
||||
sess->req->total);
|
||||
|
||||
@ -3501,7 +3501,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
|
||||
" an_exp=%s",
|
||||
sess->rep,
|
||||
sess->rep->flags, sess->rep->analysers,
|
||||
sess->rep->i, sess->rep->o,
|
||||
sess->rep->buf.i, sess->rep->buf.o,
|
||||
sess->rep->pipe ? sess->rep->pipe->data : 0,
|
||||
sess->rep->to_forward,
|
||||
sess->rep->analyse_exp ?
|
||||
@ -3520,8 +3520,8 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
|
||||
sess->rep->wex ?
|
||||
human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
|
||||
TICKS_TO_MS(1000)) : "<NEVER>",
|
||||
sess->rep->data,
|
||||
(int)(sess->rep->p - sess->rep->data),
|
||||
sess->rep->buf.data,
|
||||
(int)(sess->rep->buf.p - sess->rep->buf.data),
|
||||
sess->txn.rsp.next,
|
||||
sess->rep->total);
|
||||
|
||||
@ -3642,7 +3642,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si)
|
||||
chunk_printf(&msg,
|
||||
" rq[f=%06xh,i=%d,an=%02xh,rx=%s",
|
||||
curr_sess->req->flags,
|
||||
curr_sess->req->i,
|
||||
curr_sess->req->buf.i,
|
||||
curr_sess->req->analysers,
|
||||
curr_sess->req->rex ?
|
||||
human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
|
||||
@ -3663,7 +3663,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si)
|
||||
chunk_printf(&msg,
|
||||
" rp[f=%06xh,i=%d,an=%02xh,rx=%s",
|
||||
curr_sess->rep->flags,
|
||||
curr_sess->rep->i,
|
||||
curr_sess->rep->buf.i,
|
||||
curr_sess->rep->analysers,
|
||||
curr_sess->rep->rex ?
|
||||
human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
|
||||
|
@ -253,8 +253,8 @@ int frontend_accept(struct session *s)
|
||||
*/
|
||||
int frontend_decode_proxy_request(struct session *s, struct channel *req, int an_bit)
|
||||
{
|
||||
char *line = req->data;
|
||||
char *end = req->data + req->i;
|
||||
char *line = req->buf.data;
|
||||
char *end = req->buf.data + req->buf.i;
|
||||
int len;
|
||||
|
||||
DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
|
||||
@ -269,7 +269,7 @@ int frontend_decode_proxy_request(struct session *s, struct channel *req, int an
|
||||
if (req->flags & (BF_READ_ERROR|BF_READ_TIMEOUT))
|
||||
goto fail;
|
||||
|
||||
len = MIN(req->i, 6);
|
||||
len = MIN(req->buf.i, 6);
|
||||
if (!len)
|
||||
goto missing;
|
||||
|
||||
@ -278,7 +278,7 @@ int frontend_decode_proxy_request(struct session *s, struct channel *req, int an
|
||||
goto fail;
|
||||
|
||||
line += 6;
|
||||
if (req->i < 18) /* shortest possible line */
|
||||
if (req->buf.i < 18) /* shortest possible line */
|
||||
goto missing;
|
||||
|
||||
if (!memcmp(line, "TCP4 ", 5) != 0) {
|
||||
@ -388,8 +388,8 @@ int frontend_decode_proxy_request(struct session *s, struct channel *req, int an
|
||||
}
|
||||
|
||||
/* remove the PROXY line from the request */
|
||||
len = line - req->data;
|
||||
buffer_replace2(req, req->data, line, NULL, 0);
|
||||
len = line - req->buf.data;
|
||||
buffer_replace2(req, req->buf.data, line, NULL, 0);
|
||||
req->total -= len; /* don't count the header line */
|
||||
|
||||
req->analysers &= ~an_bit;
|
||||
|
@ -1228,7 +1228,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
|
||||
if ((s->req = pool_alloc2(pool2_buffer)) == NULL)
|
||||
goto out_fail_req; /* no memory */
|
||||
|
||||
s->req->size = global.tune.bufsize;
|
||||
s->req->buf.size = global.tune.bufsize;
|
||||
buffer_init(s->req);
|
||||
s->req->prod = &s->si[0];
|
||||
s->req->cons = &s->si[1];
|
||||
@ -1251,7 +1251,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
|
||||
if ((s->rep = pool_alloc2(pool2_buffer)) == NULL)
|
||||
goto out_fail_rep; /* no memory */
|
||||
|
||||
s->rep->size = global.tune.bufsize;
|
||||
s->rep->buf.size = global.tune.bufsize;
|
||||
buffer_init(s->rep);
|
||||
s->rep->prod = &s->si[1];
|
||||
s->rep->cons = &s->si[0];
|
||||
|
386
src/proto_http.c
386
src/proto_http.c
File diff suppressed because it is too large
Load Diff
@ -411,7 +411,7 @@ int tcp_connect_server(struct stream_interface *si)
|
||||
* machine with the first ACK. We only do this if there are pending
|
||||
* data in the buffer.
|
||||
*/
|
||||
if ((be->options2 & PR_O2_SMARTCON) && si->ob->o)
|
||||
if ((be->options2 & PR_O2_SMARTCON) && si->ob->buf.o)
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, &zero, sizeof(zero));
|
||||
#endif
|
||||
|
||||
@ -1403,11 +1403,11 @@ smp_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, unsigned in
|
||||
smp->flags = 0;
|
||||
smp->type = SMP_T_CSTR;
|
||||
|
||||
bleft = l4->req->i;
|
||||
bleft = l4->req->buf.i;
|
||||
if (bleft <= 11)
|
||||
goto too_short;
|
||||
|
||||
data = (const unsigned char *)l4->req->p + 11;
|
||||
data = (const unsigned char *)l4->req->buf.p + 11;
|
||||
bleft -= 11;
|
||||
|
||||
if (bleft <= 7)
|
||||
@ -1598,11 +1598,11 @@ smp_fetch_payload_lv(struct proxy *px, struct session *l4, void *l7, unsigned in
|
||||
if (!b)
|
||||
return 0;
|
||||
|
||||
if (len_offset + len_size > b->i)
|
||||
if (len_offset + len_size > b->buf.i)
|
||||
goto too_short;
|
||||
|
||||
for (i = 0; i < len_size; i++) {
|
||||
buf_size = (buf_size << 8) + ((unsigned char *)b->p)[i + len_offset];
|
||||
buf_size = (buf_size << 8) + ((unsigned char *)b->buf.p)[i + len_offset];
|
||||
}
|
||||
|
||||
/* buf offset may be implicit, absolute or relative */
|
||||
@ -1612,18 +1612,18 @@ smp_fetch_payload_lv(struct proxy *px, struct session *l4, void *l7, unsigned in
|
||||
else if (arg_p[2].type == ARGT_SINT)
|
||||
buf_offset += arg_p[2].data.sint;
|
||||
|
||||
if (!buf_size || buf_size > b->size || buf_offset + buf_size > b->size) {
|
||||
if (!buf_size || buf_size > b->buf.size || buf_offset + buf_size > b->buf.size) {
|
||||
/* will never match */
|
||||
smp->flags = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf_offset + buf_size > b->i)
|
||||
if (buf_offset + buf_size > b->buf.i)
|
||||
goto too_short;
|
||||
|
||||
/* init chunk as read only */
|
||||
smp->type = SMP_T_CBIN;
|
||||
chunk_initlen(&smp->data.str, b->p + buf_offset, 0, buf_size);
|
||||
chunk_initlen(&smp->data.str, b->buf.p + buf_offset, 0, buf_size);
|
||||
smp->flags = SMP_F_VOLATILE;
|
||||
return 1;
|
||||
|
||||
@ -1648,18 +1648,18 @@ smp_fetch_payload(struct proxy *px, struct session *l4, void *l7, unsigned int o
|
||||
if (!b)
|
||||
return 0;
|
||||
|
||||
if (!buf_size || buf_size > b->size || buf_offset + buf_size > b->size) {
|
||||
if (!buf_size || buf_size > b->buf.size || buf_offset + buf_size > b->buf.size) {
|
||||
/* will never match */
|
||||
smp->flags = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf_offset + buf_size > b->i)
|
||||
if (buf_offset + buf_size > b->buf.i)
|
||||
goto too_short;
|
||||
|
||||
/* init chunk as read only */
|
||||
smp->type = SMP_T_CBIN;
|
||||
chunk_initlen(&smp->data.str, b->p + buf_offset, 0, buf_size);
|
||||
chunk_initlen(&smp->data.str, b->buf.p + buf_offset, 0, buf_size);
|
||||
smp->flags = SMP_F_VOLATILE;
|
||||
return 1;
|
||||
|
||||
|
@ -225,7 +225,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
||||
goto out_free_req; /* no memory */
|
||||
|
||||
/* initialize the request buffer */
|
||||
s->req->size = global.tune.bufsize;
|
||||
s->req->buf.size = global.tune.bufsize;
|
||||
buffer_init(s->req);
|
||||
s->req->prod = &s->si[0];
|
||||
s->req->cons = &s->si[1];
|
||||
@ -242,7 +242,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
||||
s->req->analyse_exp = TICK_ETERNITY;
|
||||
|
||||
/* initialize response buffer */
|
||||
s->rep->size = global.tune.bufsize;
|
||||
s->rep->buf.size = global.tune.bufsize;
|
||||
buffer_init(s->rep);
|
||||
s->rep->prod = &s->si[1];
|
||||
s->rep->cons = &s->si[0];
|
||||
|
@ -88,7 +88,7 @@ static int sock_raw_splice_in(struct channel *b, struct stream_interface *si)
|
||||
if (!(b->flags & BF_KERN_SPLICING))
|
||||
return -1;
|
||||
|
||||
if (buffer_not_empty(b)) {
|
||||
if (buffer_not_empty(&b->buf)) {
|
||||
/* We're embarrassed, there are already data pending in
|
||||
* the buffer and we don't want to have them at two
|
||||
* locations at a time. Let's indicate we need some
|
||||
@ -273,25 +273,25 @@ static void sock_raw_read(struct connection *conn)
|
||||
/*
|
||||
* 1. compute the maximum block size we can read at once.
|
||||
*/
|
||||
if (buffer_empty(b)) {
|
||||
if (buffer_empty(&b->buf)) {
|
||||
/* let's realign the buffer to optimize I/O */
|
||||
b->p = b->data;
|
||||
b->buf.p = b->buf.data;
|
||||
}
|
||||
else if (b->data + b->o < b->p &&
|
||||
b->p + b->i < b->data + b->size) {
|
||||
else if (b->buf.data + b->buf.o < b->buf.p &&
|
||||
b->buf.p + b->buf.i < b->buf.data + b->buf.size) {
|
||||
/* remaining space wraps at the end, with a moving limit */
|
||||
if (max > b->data + b->size - (b->p + b->i))
|
||||
max = b->data + b->size - (b->p + b->i);
|
||||
if (max > b->buf.data + b->buf.size - (b->buf.p + b->buf.i))
|
||||
max = b->buf.data + b->buf.size - (b->buf.p + b->buf.i);
|
||||
}
|
||||
/* else max is already OK */
|
||||
|
||||
/*
|
||||
* 2. read the largest possible block
|
||||
*/
|
||||
ret = recv(fd, bi_end(b), max, 0);
|
||||
ret = recv(fd, bi_end(&b->buf), max, 0);
|
||||
|
||||
if (ret > 0) {
|
||||
b->i += ret;
|
||||
b->buf.i += ret;
|
||||
cur_read += ret;
|
||||
|
||||
/* if we're allowed to directly forward data, we must update ->o */
|
||||
@ -317,7 +317,7 @@ static void sock_raw_read(struct connection *conn)
|
||||
/* The buffer is now full, there's no point in going through
|
||||
* the loop again.
|
||||
*/
|
||||
if (!(b->flags & BF_STREAMER_FAST) && (cur_read == buffer_len(b))) {
|
||||
if (!(b->flags & BF_STREAMER_FAST) && (cur_read == buffer_len(&b->buf))) {
|
||||
b->xfer_small = 0;
|
||||
b->xfer_large++;
|
||||
if (b->xfer_large >= 3) {
|
||||
@ -329,7 +329,7 @@ static void sock_raw_read(struct connection *conn)
|
||||
}
|
||||
}
|
||||
else if ((b->flags & (BF_STREAMER | BF_STREAMER_FAST)) &&
|
||||
(cur_read <= b->size / 2)) {
|
||||
(cur_read <= b->buf.size / 2)) {
|
||||
b->xfer_large = 0;
|
||||
b->xfer_small++;
|
||||
if (b->xfer_small >= 2) {
|
||||
@ -359,7 +359,7 @@ static void sock_raw_read(struct connection *conn)
|
||||
*/
|
||||
if (ret < max) {
|
||||
if ((b->flags & (BF_STREAMER | BF_STREAMER_FAST)) &&
|
||||
(cur_read <= b->size / 2)) {
|
||||
(cur_read <= b->buf.size / 2)) {
|
||||
b->xfer_large = 0;
|
||||
b->xfer_small++;
|
||||
if (b->xfer_small >= 3) {
|
||||
@ -492,7 +492,7 @@ static int sock_raw_write_loop(struct connection *conn)
|
||||
* in the normal buffer.
|
||||
*/
|
||||
#endif
|
||||
if (!b->o) {
|
||||
if (!b->buf.o) {
|
||||
b->flags |= BF_OUT_EMPTY;
|
||||
return 0;
|
||||
}
|
||||
@ -501,11 +501,11 @@ static int sock_raw_write_loop(struct connection *conn)
|
||||
* data left, and that there are sendable buffered data.
|
||||
*/
|
||||
while (1) {
|
||||
max = b->o;
|
||||
max = b->buf.o;
|
||||
|
||||
/* outgoing data may wrap at the end */
|
||||
if (b->data + max > b->p)
|
||||
max = b->data + max - b->p;
|
||||
if (b->buf.data + max > b->buf.p)
|
||||
max = b->buf.data + max - b->buf.p;
|
||||
|
||||
/* check if we want to inform the kernel that we're interested in
|
||||
* sending more data after this call. We want this if :
|
||||
@ -524,8 +524,8 @@ static int sock_raw_write_loop(struct connection *conn)
|
||||
if ((!(b->flags & BF_NEVER_WAIT) &&
|
||||
((b->to_forward && b->to_forward != BUF_INFINITE_FORWARD) ||
|
||||
(b->flags & BF_EXPECT_MORE))) ||
|
||||
((b->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_HIJACK)) == BF_SHUTW_NOW && (max == b->o)) ||
|
||||
(max != b->o)) {
|
||||
((b->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_HIJACK)) == BF_SHUTW_NOW && (max == b->buf.o)) ||
|
||||
(max != b->buf.o)) {
|
||||
send_flag |= MSG_MORE;
|
||||
}
|
||||
|
||||
@ -533,7 +533,7 @@ static int sock_raw_write_loop(struct connection *conn)
|
||||
if (b->flags & BF_SEND_DONTWAIT)
|
||||
send_flag &= ~MSG_MORE;
|
||||
|
||||
ret = send(si_fd(si), bo_ptr(b), max, send_flag);
|
||||
ret = send(si_fd(si), bo_ptr(&b->buf), max, send_flag);
|
||||
} else {
|
||||
int skerr;
|
||||
socklen_t lskerr = sizeof(skerr);
|
||||
@ -542,7 +542,7 @@ static int sock_raw_write_loop(struct connection *conn)
|
||||
if (ret == -1 || skerr)
|
||||
ret = -1;
|
||||
else
|
||||
ret = send(si_fd(si), bo_ptr(b), max, MSG_DONTWAIT);
|
||||
ret = send(si_fd(si), bo_ptr(&b->buf), max, MSG_DONTWAIT);
|
||||
}
|
||||
|
||||
if (ret > 0) {
|
||||
@ -553,15 +553,15 @@ static int sock_raw_write_loop(struct connection *conn)
|
||||
|
||||
b->flags |= BF_WRITE_PARTIAL;
|
||||
|
||||
b->o -= ret;
|
||||
if (likely(!buffer_len(b)))
|
||||
b->buf.o -= ret;
|
||||
if (likely(!buffer_len(&b->buf)))
|
||||
/* optimize data alignment in the buffer */
|
||||
b->p = b->data;
|
||||
b->buf.p = b->buf.data;
|
||||
|
||||
if (likely(!bi_full(b)))
|
||||
b->flags &= ~BF_FULL;
|
||||
|
||||
if (!b->o) {
|
||||
if (!b->buf.o) {
|
||||
/* Always clear both flags once everything has been sent, they're one-shot */
|
||||
b->flags &= ~(BF_EXPECT_MORE | BF_SEND_DONTWAIT);
|
||||
if (likely(!b->pipe))
|
||||
|
@ -614,7 +614,7 @@ void conn_notify_si(struct connection *conn)
|
||||
*/
|
||||
if (((si->ib->flags & (BF_READ_PARTIAL|BF_OUT_EMPTY)) == BF_READ_PARTIAL) &&
|
||||
(si->ib->pipe /* always try to send spliced data */ ||
|
||||
(si->ib->i == 0 && (si->ib->cons->flags & SI_FL_WAIT_DATA)))) {
|
||||
(si->ib->buf.i == 0 && (si->ib->cons->flags & SI_FL_WAIT_DATA)))) {
|
||||
int last_len = si->ib->pipe ? si->ib->pipe->data : 0;
|
||||
|
||||
si_chk_snd(si->ib->cons);
|
||||
|
Loading…
x
Reference in New Issue
Block a user