From: Willy Tarreau Date: Thu, 19 Oct 2017 12:57:54 +0000 (+0200) Subject: MINOR: channel: make use of bo_getblk{,_nc} for their channel equivalents X-Git-Tag: v1.8-dev3~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6b3f353bcfdc136eda68a03b5b63a3798911129b;p=thirdparty%2Fhaproxy.git MINOR: channel: make use of bo_getblk{,_nc} for their channel equivalents Let's reuse the buffer-level functions to perform the operations. --- diff --git a/src/channel.c b/src/channel.c index 853b85c28f..62b3ffb6c8 100644 --- a/src/channel.c +++ b/src/channel.c @@ -292,8 +292,6 @@ int co_getline(struct channel *chn, char *str, int len) */ int co_getblk(struct channel *chn, char *blk, int len, int offset) { - int firstblock; - if (chn->flags & CF_SHUTW) return -1; @@ -303,20 +301,7 @@ int co_getblk(struct channel *chn, char *blk, int len, int offset) return 0; } - firstblock = chn->buf->data + chn->buf->size - bo_ptr(chn->buf); - if (firstblock > offset) { - if (firstblock >= len + offset) { - memcpy(blk, bo_ptr(chn->buf) + offset, len); - return len; - } - - memcpy(blk, bo_ptr(chn->buf) + offset, firstblock - offset); - memcpy(blk + firstblock - offset, chn->buf->data, len - firstblock + offset); - return len; - } - - memcpy(blk, chn->buf->data + offset - firstblock, len); - return len; + return bo_getblk(chn->buf, blk, len, offset); } /* Gets one or two blocks of data at once from a channel's output buffer. @@ -335,17 +320,7 @@ int co_getblk_nc(struct channel *chn, char **blk1, int *len1, char **blk2, int * return 0; } - if (unlikely(chn->buf->p - chn->buf->o < chn->buf->data)) { - *blk1 = chn->buf->p - chn->buf->o + chn->buf->size; - *len1 = chn->buf->data + chn->buf->size - *blk1; - *blk2 = chn->buf->data; - *len2 = chn->buf->p - chn->buf->data; - return 2; - } - - *blk1 = chn->buf->p - chn->buf->o; - *len1 = chn->buf->o; - return 1; + return bo_getblk_nc(chn->buf, blk1, len1, blk2, len2); } /* Gets one text line out of a channel's output buffer from a stream interface.