MINOR: buffer: add buffer_space_wraps()

This function returns true if the available buffer space wraps. This
will be used to detect if it's worth realigning a buffer when it lacks
contigous space.
This commit is contained in:
Willy Tarreau 2017-10-16 14:01:18 +02:00
parent e5676e7103
commit 5b9834f12a

View File

@ -247,6 +247,37 @@ static inline int buffer_empty(const struct buffer *buf)
return !buffer_not_empty(buf);
}
/* Return non-zero only if the buffer's free space wraps :
* [ |oooo| ] => yes
* [ |iiii| ] => yes
* [ |oooo|iiii| ] => yes
* [oooo| ] => no
* [ |oooo] => no
* [iiii| ] => no
* [ |iiii] => no
* [oooo|iiii| ] => no
* [ |oooo|iiii] => no
* [iiii| |oooo] => no
* [oo|iiii| |oo] => no
* [iiii| |oo|ii] => no
* [oooooooooo|iiiiiiiiiii] => no
* [iiiiiiiiiiiii|oooooooo] => no
*
* So the only case where the buffer does not wrap is when there's data either
* at the beginning or at the end of the buffer. Thus we have this :
* - if (p+i >= size) ==> doesn't wrap
* - if (p-data <= o) ==> doesn't wrap
* - otherwise wraps
*/
static inline int buffer_space_wraps(const struct buffer *buf)
{
if (buf->p + buf->i >= buf->data + buf->size)
return 0;
if (buf->p <= buf->data + buf->o)
return 0;
return 1;
}
/* Returns non-zero if the buffer's INPUT is considered full, which means that
* it holds at least as much INPUT data as (size - reserve). This also means
* that data that are scheduled for output are considered as potential free