mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
MEDIUM: channel: adapt to the new buffer API
Also, ci_swpbuf() was removed (unused).
This commit is contained in:
parent
d4251a7e98
commit
cd9e60db00
@ -46,7 +46,6 @@ unsigned long long __channel_forward(struct channel *chn, unsigned long long byt
|
|||||||
|
|
||||||
/* SI-to-channel functions working with buffers */
|
/* SI-to-channel functions working with buffers */
|
||||||
int ci_putblk(struct channel *chn, const char *str, int len);
|
int ci_putblk(struct channel *chn, const char *str, int len);
|
||||||
struct buffer *ci_swpbuf(struct channel *chn, struct buffer *buf);
|
|
||||||
int ci_putchr(struct channel *chn, char c);
|
int ci_putchr(struct channel *chn, char c);
|
||||||
int ci_getline_nc(const struct channel *chn, char **blk1, size_t *len1, char **blk2, size_t *len2);
|
int ci_getline_nc(const struct channel *chn, char **blk1, size_t *len1, char **blk2, size_t *len2);
|
||||||
int ci_getblk_nc(const struct channel *chn, char **blk1, size_t *len1, char **blk2, size_t *len2);
|
int ci_getblk_nc(const struct channel *chn, char **blk1, size_t *len1, char **blk2, size_t *len2);
|
||||||
|
@ -38,7 +38,7 @@ unsigned long long __channel_forward(struct channel *chn, unsigned long long byt
|
|||||||
* regular code paths.
|
* regular code paths.
|
||||||
*/
|
*/
|
||||||
if (unlikely(chn->to_forward == CHN_INFINITE_FORWARD)) {
|
if (unlikely(chn->to_forward == CHN_INFINITE_FORWARD)) {
|
||||||
c_adv(chn, chn->buf->i);
|
c_adv(chn, ci_data(chn));
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ unsigned long long __channel_forward(struct channel *chn, unsigned long long byt
|
|||||||
budget = MIN(bytes, CHN_INFINITE_FORWARD - 1);
|
budget = MIN(bytes, CHN_INFINITE_FORWARD - 1);
|
||||||
|
|
||||||
/* transfer as much as we can of buf->i */
|
/* transfer as much as we can of buf->i */
|
||||||
forwarded = MIN(chn->buf->i, budget);
|
forwarded = MIN(ci_data(chn), budget);
|
||||||
c_adv(chn, forwarded);
|
c_adv(chn, forwarded);
|
||||||
budget -= forwarded;
|
budget -= forwarded;
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ int co_inject(struct channel *chn, const char *msg, int len)
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (len < 0 || len > chn->buf->size) {
|
if (len < 0 || len > c_size(chn)) {
|
||||||
/* we can't write this chunk and will never be able to, because
|
/* we can't write this chunk and will never be able to, because
|
||||||
* it is larger than the buffer. This must be reported as an
|
* it is larger than the buffer. This must be reported as an
|
||||||
* error. Then we return -2 so that writers that don't care can
|
* error. Then we return -2 so that writers that don't care can
|
||||||
@ -96,7 +96,7 @@ int co_inject(struct channel *chn, const char *msg, int len)
|
|||||||
if (len > max)
|
if (len > max)
|
||||||
return max;
|
return max;
|
||||||
|
|
||||||
memcpy(b_tail(chn->buf), msg, len);
|
memcpy(ci_tail(chn), msg, len);
|
||||||
b_add(chn->buf, len);
|
b_add(chn->buf, len);
|
||||||
c_adv(chn, len);
|
c_adv(chn, len);
|
||||||
chn->total += len;
|
chn->total += len;
|
||||||
@ -119,7 +119,7 @@ int ci_putchr(struct channel *chn, char c)
|
|||||||
|
|
||||||
*ci_tail(chn) = c;
|
*ci_tail(chn) = c;
|
||||||
|
|
||||||
chn->buf->i++;
|
b_add(chn->buf, 1);
|
||||||
chn->flags |= CF_READ_PARTIAL;
|
chn->flags |= CF_READ_PARTIAL;
|
||||||
|
|
||||||
if (chn->to_forward >= 1) {
|
if (chn->to_forward >= 1) {
|
||||||
@ -151,7 +151,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
|
|||||||
return -3;
|
return -3;
|
||||||
|
|
||||||
max = channel_recv_limit(chn);
|
max = channel_recv_limit(chn);
|
||||||
if (unlikely(len > max - b_data(chn->buf))) {
|
if (unlikely(len > max - c_data(chn))) {
|
||||||
/* we can't write this chunk right now because the buffer is
|
/* we can't write this chunk right now because the buffer is
|
||||||
* almost full or because the block is too large. Return the
|
* almost full or because the block is too large. Return the
|
||||||
* available space or -2 if impossible.
|
* available space or -2 if impossible.
|
||||||
@ -169,7 +169,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
|
|||||||
max = b_contig_space(chn->buf);
|
max = b_contig_space(chn->buf);
|
||||||
memcpy(ci_tail(chn), blk, MIN(len, max));
|
memcpy(ci_tail(chn), blk, MIN(len, max));
|
||||||
if (len > max)
|
if (len > max)
|
||||||
memcpy(b_orig(chn->buf), blk + max, len - max);
|
memcpy(c_orig(chn), blk + max, len - max);
|
||||||
|
|
||||||
b_add(chn->buf, len);
|
b_add(chn->buf, len);
|
||||||
chn->total += len;
|
chn->total += len;
|
||||||
@ -188,49 +188,6 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tries to copy the whole buffer <buf> into the channel's buffer after length
|
|
||||||
* controls. It will only succeed if the target buffer is empty, in which case
|
|
||||||
* it will simply swap the buffers. The buffer not attached to the channel is
|
|
||||||
* returned so that the caller can store it locally. The chn->buf->o and
|
|
||||||
* to_forward pointers are updated. If the output buffer is a dummy buffer or
|
|
||||||
* if it still contains data <buf> is returned, indicating that nothing could
|
|
||||||
* be done. Channel flag READ_PARTIAL is updated if some data can be transferred.
|
|
||||||
* The chunk's length is updated with the number of bytes sent. On errors, NULL
|
|
||||||
* is returned. Note that only buf->i is considered.
|
|
||||||
*/
|
|
||||||
struct buffer *ci_swpbuf(struct channel *chn, struct buffer *buf)
|
|
||||||
{
|
|
||||||
struct buffer *old;
|
|
||||||
|
|
||||||
if (unlikely(channel_input_closed(chn)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!c_size(chn) || !c_empty(chn))
|
|
||||||
return buf;
|
|
||||||
|
|
||||||
old = chn->buf;
|
|
||||||
chn->buf = buf;
|
|
||||||
|
|
||||||
if (!buf->i)
|
|
||||||
return old;
|
|
||||||
|
|
||||||
chn->total += buf->i;
|
|
||||||
|
|
||||||
if (chn->to_forward) {
|
|
||||||
unsigned long fwd = buf->i;
|
|
||||||
if (chn->to_forward != CHN_INFINITE_FORWARD) {
|
|
||||||
if (fwd > chn->to_forward)
|
|
||||||
fwd = chn->to_forward;
|
|
||||||
chn->to_forward -= fwd;
|
|
||||||
}
|
|
||||||
c_adv(chn, fwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* notify that some data was read from the SI into the buffer */
|
|
||||||
chn->flags |= CF_READ_PARTIAL;
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Gets one text line out of a channel's buffer from a stream interface.
|
/* Gets one text line out of a channel's buffer from a stream interface.
|
||||||
* Return values :
|
* Return values :
|
||||||
* >0 : number of bytes read. Includes the \n if present before len or end.
|
* >0 : number of bytes read. Includes the \n if present before len or end.
|
||||||
@ -256,10 +213,10 @@ int co_getline(const struct channel *chn, char *str, int len)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = b_head(chn->buf);
|
p = co_head(chn);
|
||||||
|
|
||||||
if (max > chn->buf->o) {
|
if (max > co_data(chn)) {
|
||||||
max = chn->buf->o;
|
max = co_data(chn);
|
||||||
str[max-1] = 0;
|
str[max-1] = 0;
|
||||||
}
|
}
|
||||||
while (max) {
|
while (max) {
|
||||||
@ -269,10 +226,10 @@ int co_getline(const struct channel *chn, char *str, int len)
|
|||||||
|
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
break;
|
break;
|
||||||
p = buffer_wrap_add(chn->buf, p + 1);
|
p = b_next(chn->buf, p);
|
||||||
}
|
}
|
||||||
if (ret > 0 && ret < len &&
|
if (ret > 0 && ret < len &&
|
||||||
(ret < chn->buf->o || channel_may_recv(chn)) &&
|
(ret < co_data(chn) || channel_may_recv(chn)) &&
|
||||||
*(str-1) != '\n' &&
|
*(str-1) != '\n' &&
|
||||||
!(chn->flags & (CF_SHUTW|CF_SHUTW_NOW)))
|
!(chn->flags & (CF_SHUTW|CF_SHUTW_NOW)))
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -314,13 +271,13 @@ int co_getblk(const struct channel *chn, char *blk, int len, int offset)
|
|||||||
*/
|
*/
|
||||||
int co_getblk_nc(const struct channel *chn, const char **blk1, size_t *len1, const char **blk2, size_t *len2)
|
int co_getblk_nc(const struct channel *chn, const char **blk1, size_t *len1, const char **blk2, size_t *len2)
|
||||||
{
|
{
|
||||||
if (unlikely(chn->buf->o == 0)) {
|
if (unlikely(co_data(chn) == 0)) {
|
||||||
if (chn->flags & CF_SHUTW)
|
if (chn->flags & CF_SHUTW)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return b_getblk_nc(chn->buf, blk1, len1, blk2, len2, 0, chn->buf->o);
|
return b_getblk_nc(chn->buf, blk1, len1, blk2, len2, 0, co_data(chn));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gets one text line out of a channel's output buffer from a stream interface.
|
/* Gets one text line out of a channel's output buffer from a stream interface.
|
||||||
@ -380,22 +337,22 @@ int ci_getblk_nc(const struct channel *chn,
|
|||||||
char **blk1, size_t *len1,
|
char **blk1, size_t *len1,
|
||||||
char **blk2, size_t *len2)
|
char **blk2, size_t *len2)
|
||||||
{
|
{
|
||||||
if (unlikely(chn->buf->i == 0)) {
|
if (unlikely(ci_data(chn) == 0)) {
|
||||||
if (chn->flags & CF_SHUTR)
|
if (chn->flags & CF_SHUTR)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(chn->buf->p + chn->buf->i > b_wrap(chn->buf))) {
|
if (unlikely(ci_head(chn) + ci_data(chn) > c_wrap(chn))) {
|
||||||
*blk1 = chn->buf->p;
|
*blk1 = ci_head(chn);
|
||||||
*len1 = b_wrap(chn->buf) - chn->buf->p;
|
*len1 = c_wrap(chn) - ci_head(chn);
|
||||||
*blk2 = b_orig(chn->buf);
|
*blk2 = c_orig(chn);
|
||||||
*len2 = chn->buf->i - *len1;
|
*len2 = ci_data(chn) - *len1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
*blk1 = chn->buf->p;
|
*blk1 = ci_head(chn);
|
||||||
*len1 = chn->buf->i;
|
*len1 = ci_data(chn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user