From: Willy Tarreau Date: Mon, 24 Nov 2014 09:54:47 +0000 (+0100) Subject: MINOR: buffer: reset a buffer in b_reset() and not channel_init() X-Git-Tag: v1.6-dev1~227 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=474cf54a97ca19fa0f5a1de9489330f348836531;p=thirdparty%2Fhaproxy.git MINOR: buffer: reset a buffer in b_reset() and not channel_init() We'll soon need to be able to switch buffers without touching the channel, so let's move buffer initialization out of channel_init(). We had the same in compressoin.c. --- diff --git a/include/common/buffer.h b/include/common/buffer.h index 2d657d1f97..fd2957579c 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -387,6 +387,14 @@ static inline void bo_putchk(struct buffer *b, const struct chunk *chk) return bo_putblk(b, chk->str, chk->len); } +/* Resets a buffer. The size is not touched. */ +static inline void b_reset(struct buffer *buf) +{ + buf->o = 0; + buf->i = 0; + buf->p = buf->data; +} + #endif /* _COMMON_BUFFER_H */ /* diff --git a/include/proto/channel.h b/include/proto/channel.h index e323d340d0..cf7b413831 100644 --- a/include/proto/channel.h +++ b/include/proto/channel.h @@ -51,9 +51,6 @@ int bo_getblk(struct channel *chn, char *blk, int len, int offset); /* Initialize all fields in the channel. */ static inline void channel_init(struct channel *chn) { - chn->buf->o = 0; - chn->buf->i = 0; - chn->buf->p = chn->buf->data; chn->to_forward = 0; chn->last_read = now_ms; chn->xfer_small = chn->xfer_large = 0; @@ -185,10 +182,8 @@ static inline void channel_check_timeouts(struct channel *chn) */ static inline void channel_erase(struct channel *chn) { - chn->buf->o = 0; - chn->buf->i = 0; chn->to_forward = 0; - chn->buf->p = chn->buf->data; + b_reset(chn->buf); } /* marks the channel as "shutdown" ASAP for reads */ diff --git a/src/compression.c b/src/compression.c index 3d6085e84a..b6c4ae201d 100644 --- a/src/compression.c +++ b/src/compression.c @@ -139,9 +139,7 @@ int http_compression_buffer_init(struct session *s, struct buffer *in, struct bu */ out->size = global.tune.bufsize; - out->i = 0; - out->o = 0; - out->p = out->data; + b_reset(out); if (in->o > 0) { left = in->o - bo_contig_data(in); diff --git a/src/peers.c b/src/peers.c index b196d881ed..9ff177354a 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1241,6 +1241,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio goto out_fail_req_buf; /* no memory */ s->req->buf->size = global.tune.bufsize; + b_reset(s->req->buf); channel_init(s->req); s->req->prod = &s->si[0]; s->req->cons = &s->si[1]; @@ -1267,6 +1268,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio goto out_fail_rep_buf; /* no memory */ s->rep->buf->size = global.tune.bufsize; + b_reset(s->rep->buf); channel_init(s->rep); s->rep->prod = &s->si[1]; s->rep->cons = &s->si[0]; diff --git a/src/session.c b/src/session.c index 772307495a..d57a2d5da2 100644 --- a/src/session.c +++ b/src/session.c @@ -488,6 +488,7 @@ int session_complete(struct session *s) /* initialize the request buffer */ s->req->buf->size = global.tune.bufsize; + b_reset(s->req->buf); channel_init(s->req); s->req->prod = &s->si[0]; s->req->cons = &s->si[1]; @@ -505,6 +506,7 @@ int session_complete(struct session *s) /* initialize response buffer */ s->rep->buf->size = global.tune.bufsize; + b_reset(s->rep->buf); channel_init(s->rep); s->rep->prod = &s->si[1]; s->rep->cons = &s->si[0];