]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: reset a buffer in b_reset() and not channel_init()
authorWilly Tarreau <w@1wt.eu>
Mon, 24 Nov 2014 09:54:47 +0000 (10:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Dec 2014 22:47:31 +0000 (23:47 +0100)
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
include/proto/channel.h
src/compression.c
src/peers.c
src/session.c

index 2d657d1f972169085dd28866e5b7ad9e147ef12b..fd2957579c164d883c06b932b334e8faf1de05db 100644 (file)
@@ -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 */
 
 /*
index e323d340d0929e122fef6eedff9c7bea4a8b58dd..cf7b4138313ccf345f568e650e4473a23acb8766 100644 (file)
@@ -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 */
index 3d6085e84ab446fd4ec4510dd3c18294fe443a02..b6c4ae201d714db37e3443faa9d551e5f13b019b 100644 (file)
@@ -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);
index b196d881eddd66d7db2a3bb0cb45fd8eb38e3eec..9ff177354a628d2c7a3c7b4e166946c4969be604 100644 (file)
@@ -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];
index 772307495aa3b152dedaad5b449f91d1138fd14b..d57a2d5da246428b45787db450ae4b01e51bcc6d 100644 (file)
@@ -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];