From f7605782390713cf290c3218fe836ddb93249d7a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 24 Nov 2014 10:54:47 +0100 Subject: MINOR: buffers: 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. --- include/common/buffer.h | 8 ++++++++ include/proto/channel.h | 7 +------ src/compression.c | 4 +--- src/peers.c | 2 ++ src/session.c | 2 ++ 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/common/buffer.h b/include/common/buffer.h index 2d657d1..fd29575 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 e323d34..cf7b413 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 09bc4a6..189d202 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 b196d88..9ff1773 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 7723074..d57a2d5 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]; -- 1.7.12.1