mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-20 00:10:41 -05:00
MINOR: buffers: provide simple pointer normalization functions
Add buffer_wrap_sub() and buffer_wrap_add() to normalize buffer pointers after an addition or subtract.
This commit is contained in:
parent
02d6cfc1d7
commit
7fd758bbcf
1 changed files with 16 additions and 0 deletions
|
|
@ -87,6 +87,22 @@ static inline int buffer_empty(const struct buffer *buf)
|
|||
return !buffer_not_empty(buf);
|
||||
}
|
||||
|
||||
/* Normalizes a pointer after a subtract */
|
||||
static inline char *buffer_wrap_sub(const struct buffer *buf, char *ptr)
|
||||
{
|
||||
if (ptr < buf->data)
|
||||
ptr += buf->size;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* Normalizes a pointer after an addition */
|
||||
static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr)
|
||||
{
|
||||
if (ptr - buf->size >= buf->data)
|
||||
ptr -= buf->size;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* Return the number of reserved bytes in the buffer, which ensures that once
|
||||
* all pending data are forwarded, the buffer still has global.tune.maxrewrite
|
||||
* bytes free. The result is between 0 and global.maxrewrite, which is itself
|
||||
|
|
|
|||
Loading…
Reference in a new issue