mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: buffer: replace bo_getblk_nc() with b_getblk_nc() which takes an offset
This will be important so that we can parse a buffer without touching it. Now we indicate where from the buffer's head we plan to start to copy, and for how many bytes. This will be used by send functions to loop at the end of the buffer without having to update the buffer's output byte count.
This commit is contained in:
parent
90ed3836db
commit
a1f78fb652
@ -343,6 +343,34 @@ static inline size_t b_getblk(const struct buffer *buf, char *blk, size_t len, s
|
||||
return len;
|
||||
}
|
||||
|
||||
/* b_getblk_nc() : gets one or two blocks of data at once from a buffer,
|
||||
* starting from offset <ofs> after the beginning of its output, and limited to
|
||||
* no more than <max> bytes. The caller is responsible for ensuring that
|
||||
* neither <ofs> nor <ofs>+<max> exceed the total number of bytes available in
|
||||
* the buffer. Return values :
|
||||
* >0 : number of blocks filled (1 or 2). blk1 is always filled before blk2.
|
||||
* =0 : not enough data available. <blk*> are left undefined.
|
||||
* The buffer is left unaffected. Unused buffers are left in an undefined state.
|
||||
*/
|
||||
static inline size_t b_getblk_nc(struct buffer *buf, char **blk1, int *len1, char **blk2, int *len2, size_t ofs, size_t max)
|
||||
{
|
||||
size_t l1;
|
||||
|
||||
if (!max)
|
||||
return 0;
|
||||
|
||||
*blk1 = b_peek(buf, ofs);
|
||||
l1 = b_wrap(buf) - *blk1;
|
||||
if (l1 < max) {
|
||||
*len1 = l1;
|
||||
*len2 = max - l1;
|
||||
*blk2 = buf->data;
|
||||
return 2;
|
||||
}
|
||||
*len1 = max;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************/
|
||||
/* Functions used to modify the buffer state */
|
||||
|
@ -326,30 +326,6 @@ static inline int bo_putchk(struct buffer *b, const struct chunk *chk)
|
||||
return bo_putblk(b, chk->str, chk->len);
|
||||
}
|
||||
|
||||
/* Gets one or two blocks of data at once from a buffer's output.
|
||||
* Return values :
|
||||
* >0 : number of blocks filled (1 or 2). blk1 is always filled before blk2.
|
||||
* =0 : not enough data available. <blk*> are left undefined.
|
||||
* The buffer is left unaffected. Unused buffers are left in an undefined state.
|
||||
*/
|
||||
static inline int bo_getblk_nc(struct buffer *buf, char **blk1, int *len1, char **blk2, int *len2)
|
||||
{
|
||||
if (unlikely(buf->o == 0))
|
||||
return 0;
|
||||
|
||||
if (unlikely(buf->p != buf->data && buf->p - buf->o < buf->data)) {
|
||||
*blk1 = buf->p - buf->o + buf->size;
|
||||
*len1 = buf->data + buf->size - *blk1;
|
||||
*blk2 = buf->data;
|
||||
*len2 = buf->p - buf->data;
|
||||
return 2;
|
||||
}
|
||||
|
||||
*blk1 = b_head(buf);
|
||||
*len1 = buf->o;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Tries to write char <c> into input data at buffer <b>. Supports wrapping.
|
||||
* Data are truncated if buffer is full.
|
||||
*/
|
||||
|
@ -320,7 +320,7 @@ int co_getblk_nc(const struct channel *chn, char **blk1, int *len1, char **blk2,
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bo_getblk_nc(chn->buf, blk1, len1, blk2, len2);
|
||||
return b_getblk_nc(chn->buf, blk1, len1, blk2, len2, 0, chn->buf->o);
|
||||
}
|
||||
|
||||
/* Gets one text line out of a channel's output buffer from a stream interface.
|
||||
|
@ -3271,7 +3271,7 @@ static int h2s_frt_make_resp_data(struct h2s *h2s, struct buffer *buf)
|
||||
|
||||
/* copy whatever we can */
|
||||
blk1 = blk2 = NULL; // silence a maybe-uninitialized warning
|
||||
ret = bo_getblk_nc(buf, &blk1, &len1, &blk2, &len2);
|
||||
ret = b_getblk_nc(buf, &blk1, &len1, &blk2, &len2, 0, buf->o);
|
||||
if (ret == 1)
|
||||
len2 = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user