mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-02-26 19:52:06 +01:00
MINOR: buffer: add two functions to inject data into buffers
bi_istput() injects the ist string into the input region of the buffer, it will be used to feed small data chunks into the conn_stream. bo_istput() does the same into the output region of the buffer, it will be used to send data via the transport layer and assumes there's no input data.
This commit is contained in:
parent
6634b63c78
commit
e5676e7103
@ -618,6 +618,64 @@ static inline int bi_eat(struct buffer *b, const struct ist ist)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* injects string <ist> into the input region of buffer <b> provided that it
|
||||
* fits. Wrapping is supported. It's designed for small strings as it only
|
||||
* writes a single byte per iteration. Returns the number of characters copied
|
||||
* (ist.len), 0 if it temporarily does not fit or -1 if it will never fit. It
|
||||
* will only modify the buffer upon success. In all cases, the contents are
|
||||
* copied prior to reporting an error, so that the destination at least
|
||||
* contains a valid but truncated string.
|
||||
*/
|
||||
static inline int bi_istput(struct buffer *b, const struct ist ist)
|
||||
{
|
||||
const char *end = b->data + b->size;
|
||||
struct ist r = ist;
|
||||
char *p;
|
||||
|
||||
if (r.len > (size_t)(b->size - b->i - b->o))
|
||||
return r.len < b->size ? 0 : -1;
|
||||
|
||||
p = b_ptr(b, b->i);
|
||||
b->i += r.len;
|
||||
while (r.len--) {
|
||||
*p++ = *r.ptr++;
|
||||
if (unlikely(p == end))
|
||||
p = b->data;
|
||||
}
|
||||
return ist.len;
|
||||
}
|
||||
|
||||
|
||||
/* injects string <ist> into the output region of buffer <b> provided that it
|
||||
* fits. Input data is assumed not to exist and will silently be overwritten.
|
||||
* Wrapping is supported. It's designed for small strings as it only writes a
|
||||
* single byte per iteration. Returns the number of characters copied (ist.len),
|
||||
* 0 if it temporarily does not fit or -1 if it will never fit. It will only
|
||||
* modify the buffer upon success. In all cases, the contents are copied prior
|
||||
* to reporting an error, so that the destination at least contains a valid
|
||||
* but truncated string.
|
||||
*/
|
||||
static inline int bo_istput(struct buffer *b, const struct ist ist)
|
||||
{
|
||||
const char *end = b->data + b->size;
|
||||
struct ist r = ist;
|
||||
char *p;
|
||||
|
||||
if (r.len > (size_t)(b->size - b->o))
|
||||
return r.len < b->size ? 0 : -1;
|
||||
|
||||
p = b->p;
|
||||
b->o += r.len;
|
||||
b->p = b_ptr(b, r.len);
|
||||
while (r.len--) {
|
||||
*p++ = *r.ptr++;
|
||||
if (unlikely(p == end))
|
||||
p = b->data;
|
||||
}
|
||||
return ist.len;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _COMMON_BUFFER_H */
|
||||
|
||||
/*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user